[R] indexing a parameter in nls

From: John Hendrickx <john_hendrickx_at_yahoo.com>
Date: Thu 15 Jul 2004 - 22:02:31 EST

I'm trying to estimate a "diagonal reference model" in nls. In its basic form, the model consists of two factors with equal categories and a dependent variable. The model fits the main effects of the two factors such that they are proportional to each other. So the model I want to fit is:


The m-parameters indicate the "average" main effect of factors f1 and f2 (with no intercept). The p-parameter indicates the relative impact of the two factors on Y. If p=.5, f1 and f2 have equal impact, for p>.5, f1 has greater impact, for p<.5 f2 has greater impact.

I can estimate the model as follows for f1="row", f2="col", Y="nkids":



nls(nkids~p*(rd[,1]*m1+rd[,2]*m2+rd[,3]*m3+rd[,4]*m4+rd[,5]*m5) +


What I want however, is a more compact specification, where "row" and

"col" are used to index which m-parameter should be used, something
like: nls(nkids~p*strt[row]+(1-p)*strt[col],start=strt) This specification produces an error: "Error in nlsModel(formula, mf, start) : singular gradient matrix at initial parameter estimates". I suspect the problem is that "strt[row]" evaluates to a list of starting values rather than the object names m1, m2, etc. I've tried nls(nkids~p*get(names(strt[row]))+(1-p)*get(names(strt[col])),start=strt) But this produces an error as well: "Error in qr.qty(QR, resid) : qr and y must have the same number of rows" Can anyone point me in the right direction? How can I use "row" and
"col" to index the appropriate "m" parameter in this model?
______________________________________________ R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Thu Jul 15 22:10:29 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:54:59 EST