sdfrost@ucsd.edu
2003-Apr-19 19:26 UTC
[R] nls, gnls, starting values, and covariance matrix
Dear R-Help, I'm trying to fit a model of the following form using gnls. I've fitted it using nlsList with the following syntax: nlsList(Y~log(exp(a0-a1*X)+exp(b0-b1*X))|K,start=list (a0=6,a1=0.2,b0=4.5,b1=0.001),data=data.frame(Y=y,X=X,K=k))) which works just fine: <snip> Coefficients: a0 a1 b0 b1 1 5.459381 0.5006811 5.137458 -0.0040548687 2 5.761496 0.1716723 6.359151 -0.0022802595 3 5.683510 0.5436838 5.906742 -0.0007788076 4 6.225745 0.2807003 5.875803 -0.0008351051 5 6.558350 0.1388707 5.071080 0.0014594212 6 5.483639 0.2757080 2.406683 -0.0003282243 7 5.746064 0.4354105 5.883882 -0.0002577279 8 5.448679 0.3385350 2.851571 0.0011627360 9 5.259762 0.5654369 5.498967 0.0015381718 10 6.546022 0.8008781 4.913085 0.0051150166 12 5.602982 1.1538595 5.008253 -0.0006087786 13 6.452605 0.1752357 6.229393 0.0007899073 15 5.937199 0.2214811 4.980386 0.0081102533 16 5.998689 0.2925840 6.077816 0.0062388250 However, I'd like to be able to fit the model using gnls. The format is a little different, but I get an error when I use the following syntax: gnls(Y~log(exp(a0-a1*X)+exp(b0-b1*X)),params=a0+a1+b0+b1~K,start=list(rep(c (6.02,0.2,4.5,0.001),16)),data=data.frame(Y=y,X=x,K=k),control=list (msVerbose=TRUE,apVar=FALSE,returnObject=TRUE)) Error in gnls(Y ~ log(exp(a0 - a1 * X) + exp(b0 - b1 * X)), params = a0 + : Approx. covariance matrix for parameter estimates not of full rank I assume that I'm getting the format of my starting values wrong. Any suggestions would be greatly appreciated. Best wishes Simon
Thomas W Blackwell
2003-Apr-19 19:54 UTC
[R] nls, gnls, starting values, and covariance matrix
Simon - There's a symmetry in the model you are fitting, and the error message returned sounds to me as though it is referring to that. Could you try a model formula of the form Y ~ a0 + log(exp(-c0-a1*X) + exp(+c0-b1*X)) Maybe you will need to make the two slopes identifiable in much the same fashion that I've done for the two intercepts, in order to get it to work. Or maybe not. I'll leave that up to you. HTH - tom blackwell - u michigan medical school - ann arbor - On Sat, 19 Apr 2003 sdfrost at ucsd.edu wrote:> Dear R-Help, > > I'm trying to fit a model of the following form using gnls. I've fitted it > using nlsList with the following syntax: > > nlsList(Y~log(exp(a0-a1*X)+exp(b0-b1*X))|K,start=list > (a0=6,a1=0.2,b0=4.5,b1=0.001),data=data.frame(Y=y,X=X,K=k))) > > which works just fine: > > <snip> > > Coefficients: > a0 a1 b0 b1 > 1 5.459381 0.5006811 5.137458 -0.0040548687 > 2 5.761496 0.1716723 6.359151 -0.0022802595 > 3 5.683510 0.5436838 5.906742 -0.0007788076 > 4 6.225745 0.2807003 5.875803 -0.0008351051 > 5 6.558350 0.1388707 5.071080 0.0014594212 > 6 5.483639 0.2757080 2.406683 -0.0003282243 > 7 5.746064 0.4354105 5.883882 -0.0002577279 > 8 5.448679 0.3385350 2.851571 0.0011627360 > 9 5.259762 0.5654369 5.498967 0.0015381718 > 10 6.546022 0.8008781 4.913085 0.0051150166 > 12 5.602982 1.1538595 5.008253 -0.0006087786 > 13 6.452605 0.1752357 6.229393 0.0007899073 > 15 5.937199 0.2214811 4.980386 0.0081102533 > 16 5.998689 0.2925840 6.077816 0.0062388250 > > However, I'd like to be able to fit the model using gnls. The format is a > little different, but I get an error when I use the following syntax: > > gnls(Y~log(exp(a0-a1*X)+exp(b0-b1*X)),params=a0+a1+b0+b1~K,start=list(rep(c > (6.02,0.2,4.5,0.001),16)),data=data.frame(Y=y,X=x,K=k),control=list > (msVerbose=TRUE,apVar=FALSE,returnObject=TRUE)) > > Error in gnls(Y ~ log(exp(a0 - a1 * X) + exp(b0 - b1 * X)), params = a0 + : > Approx. covariance matrix for parameter estimates not of full rank > > I assume that I'm getting the format of my starting values wrong. Any > suggestions would be greatly appreciated. > > Best wishes > Simon