[R] nlsList problems: control option does not effect output and strange environment search

Theis, Winfried Winfried.Theis at unilever.com
Thu Jun 14 14:50:08 CEST 2007


Dear R-helpers,
 
I'm using R 2.5.0 under Windows and am trying to use nlsList from nlme
3.1-80 with the selfstart function for the four parametric logistic
function. My first test went well, but now I'm trying to do some more
sophisticated things and it does not work anymore. 
 
I simulate my data from a five parametric logistic function like this:

Y<-as.data.frame(apply(params,1,function(x){
Y<-x[1]+(x[2]/(1+x[3]*exp(-1*x[4]*(1:240-x[5])))^(1/x[3]))+rnorm(240,0,s
derror) 
return(Y)}))

params contains different parameters for 200 persons in 4 groups. Next I
sample for each person five observations one at the start, one at the
end and three randomly in between. Now I get the following error
messages:
testnlslist2<-nlsList(SSfpl,groupedData(Y~Time|group, datset))
Error in nls(y ~ cbind(1, 1/(1 + exp((xmid - x)/exp(lscal)))), data =
xy,  : 
        step factor 0.000488281 reduced below 'minFactor' of 0.000976562
Error in nls(formula = formula, data = data, control = control) : 
        singular gradient

For the first error it could be that this is due to the fact that this
group is simulated as a kind of placebo and therefore it may be hard to
fit. To solve this I tried to specify controls like this:
testnlslist2<-nlsList(SSfpl,groupedData(Y~Time|group,
datset),control=nls.control(minFactor=1/4096))

but it led to the same error as the first. So it looks like the control
parameter is not evaluated. Any other ideas how to get the function
running? 

The second strange thing I encountered is that nlsList does not seem to
analyse the environment from which it is called. I did try to use it
within a function in apply and I got the error that the dataset I gave
was not found, but the function grouped.data worked well within the
function. Any idea what I could have done wrong?

Regards,
Winfried Theis



More information about the R-help mailing list