aline.frank at wsl.ch
2013-Oct-03 18:49 UTC
[R] SSweibull() : problems with step factor and singular gradient
SSweibull() : problems with step factor and singular gradient Hello I am working with growth data of ~4000 tree seedlings and trying to fit non-linear Weibull growth curves through the data of each plant. Since they differ a lot in their shape, initial parameters cannot be set for all plants. That’s why I use the self-starting function SSweibull(). However, I often got two error messages: 1) # Example days <- c(163,168,170,175,177,182,185,189,196,203,211,217,224) height <- c(153,161,171,173,176,173,185,192,195,187,195,203,201) dat <- as.data.frame(cbind(days,height)) fit <- nls(y ~ SSweibull(x, Asym, Drop, lrc, pwr), data = dat, trace=T, control=nls.control(minFactor=1/100000)) Error in nls(y ~cbind(1, -exp(-exp(lrc)* x^pwr)), data = xy, algorithm = “plinear”, : step factor 0.000488281 reduced below `minFactor` of 0.000976562 I tried to avoid this error by reducing the step factor below the standard minFactor of 1/1024 using the nls.control function (shown in the example above). However, this didn’t work, as shown in the example (minFactor still the standard). Thus, does nls.control() not work for self-starting functions like SSweibull()? Or is there another explanation? 2) In other cases, a second error message showed up: Error in nls(y ~cbind(1, -exp(-exp(lrc)* x^pwr)), data = xy, algorithm = “plinear”, : singular gradient Is there a way to avoid the problem of a singular gradient? I’d be very glad about helpful comments. Thanks a lot. Aline [[alternative HTML version deleted]]
Prof J C Nash (U30A)
2013-Oct-04 13:28 UTC
[R] SSweibull() : problems with step factor and singular gradient
I think you have chosen a model that is ill-suited to the data. My initial thoughts were simply that the issue was the usual nls() "singular gradient" (actually jacobian if you want to be understood in the optimization community) woes, but in this case the jacobian really is bad. My quick and dirty tries give some insight, but do not provide a satisfactory answer. Note that the last two columns of the nlxb summary are the gradient and the Jacobian singular values, so one can see how bad things are. days <- c(163,168,170,175,177,182,185,189,196,203,211,217,224) height <- c(153,161,171,173,176,173,185,192,195,187,195,203,201) dat <- as.data.frame(cbind(days,height)) fit <- try(nls(y ~ SSweibull(x, Asym, Drop, lrc, pwr), data = dat, trace=T, control=nls.control(minFactor=1/100000))) ## failed fdata<-data.frame(x=days, y=height) require(nlmrt) strt2<-c(Asym=250, Drop=1, lrc=1, pwr=1) fit2<-nlxb(y ~ Asym - (Drop * ( exp(-(exp(lrc)*(x^pwr))))), data=fdata, start=strt2, trace=TRUE) strt3<-c(Asym=250, Drop=.5, lrc=.1, pwr=2) fit3<-nlxb(y ~ Asym - (Drop * ( exp(-(exp(lrc)*(x^pwr))))), data=fdata, start=strt3, trace=TRUE) strt4<-c(Asym=200, Drop=.5, lrc=.1, pwr=2) fit4<-nlxb(y ~ Asym - (Drop * ( exp(-(exp(lrc)*(x^pwr))))), data=fdata, start=strt4, trace=TRUE, masked=c("Asym")) d50<-days-160 fd2<-data.frame(x=d50, y=height) fit5<-nlxb(y ~ Asym - (Drop * ( exp(-(exp(lrc)*(x^pwr))))), data=fd2, start=strt3, trace=TRUE) fit5 John Nash On 13-10-04 02:19 AM, r-help-request at r-project.org wrote:> Message: 40 > Date: Thu, 3 Oct 2013 20:49:36 +0200 > From:aline.frank at wsl.ch > To:r-help at r-project.org > Subject: [R] SSweibull() : problems with step factor and singular > gradient > Message-ID: > <OF669FA420.9EF643ED-ONC1257BF9.00676B04-C1257BF9.00676B07 at wsl.ch> > Content-Type: text/plain > > SSweibull() : ? problems with step factor and singular gradient > > Hello > > I am working with growth data of ~4000 tree seedlings and trying to fit non-linear Weibull growth curves through the data of each plant. Since they differ a lot in their shape, initial parameters cannot be set for all plants. That???s why I use the self-starting function SSweibull(). > However, I often got two error messages: > > 1) > # Example > days <- c(163,168,170,175,177,182,185,189,196,203,211,217,224) > height <- c(153,161,171,173,176,173,185,192,195,187,195,203,201) > dat <- as.data.frame(cbind(days,height)) > fit <- nls(y ~ SSweibull(x, Asym, Drop, lrc, pwr), data = dat, trace=T, control=nls.control(minFactor=1/100000)) > > Error in nls(y ~cbind(1, -exp(-exp(lrc)* x^pwr)), data = xy, algorithm = ???plinear???, : ? ? ? ? ? ? ? ? ? ? ? ? ? > step factor 0.000488281 reduced below `minFactor` of 0.000976562 > > I tried to avoid this error by reducing the step factor below the standard minFactor of 1/1024 using the nls.control function (shown in the example above). However, this didn???t work, as shown in the example (minFactor still the standard). > Thus, does nls.control() not work for self-starting functions like SSweibull()? Or is there another explanation? > > 2) > In other cases, a second error message showed up: > > Error in nls(y ~cbind(1, -exp(-exp(lrc)* x^pwr)), data = xy, algorithm = ???plinear???, : ? ? ? ? ? ? ? ? ? ? ? ? ? > singular gradient > > Is there a way to avoid the problem of a singular gradient? > > I???d be very glad about helpful comments. Thanks a lot. > Aline > [[alternative HTML version deleted]]
aline.frank at wsl.ch
2013-Oct-04 20:23 UTC
[R] SSweibull() : problems with step factor and singular gradient
Dear John Nash Thank you very much for your inputs on how to fit a non-linear growth curve without running into "singular gradient". I wasn't aware of the package "nlmrt" which seems to provide very helpful functions, indeed. I'll try to figure out how nlxb() can be applied to my data (I am not sure yet wheter I can actually apply the same initial parameters for all of my plants) and also how plotting of the fitted curve works with nlxb(). The easy way of using predict(fit) did not work in this case. In addition, I am still wondering if there is in fact no way of controlling the step factor in SSweibull. Best regards, Aline Frank [[alternative HTML version deleted]]