[R] Help specifying a non-linear model in nlsLM()
Prof J C Nash (U30A)
nashjc at uottawa.ca
Wed Dec 17 12:46:24 CET 2014
nlsLM and nls share a numerical gradient approximation and pop up the
"singular gradient" quite often at the start. Package nlmrt and a very
alpha nls14 (not on CRAN) try to use analytic derivatives for the
Jacobian (most optimization folk will say singular Jacobian rather than
singular gradient), so you might be better off with nlxb from nlmrt.
BUT ... it works on expressions, not functions.
Or you could provide your own Jacobian and make sure it is not singular
at the start.
Both nlsLM and nlxb/nlfb will generally be OK once they get started due
to the Marquardt adjustment to the Jacobian to avoid singularity.
JN
On 14-12-17 06:00 AM, r-help-request at r-project.org wrote:
> Message: 9 Date: Tue, 16 Dec 2014 08:24:45 -0800 From: Bert Gunter
> <gunter.berton at gene.com> To: Chandrasekhar Rudrappa
> <chandratr at gmail.com> Cc: "r-help at r-project.org" <r-help at r-project.org>
> Subject: Re: [R] Help specifying a non-linear model in nlsLM()
> Message-ID:
> <CACk-te30269-jbC4rOh24WhyCV2MrsoRQceKUrn+VzhVuRm9fA at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8 Suitable help may not be
> possible. I suspect that either your function/code is funky (is the
> function smooth, non-infinite near your starting value?) or you are
> overparameterized. If the latter, the remedy may depend on the nature of
> your data, which you have not shared. While you may receive some help
> here (there are some pretty smart optimizers who monitor the list), I
> suggest you try a statistical site like stats.stackexchange.com for
> help, as this appears to be primarily a statistics issue, not an R
> programming one. Cheers, Bert Bert Gunter Genentech Nonclinical
> Biostatistics (650) 467-7374 "Data is not information. Information is
> not knowledge. And knowledge is certainly not wisdom." Clifford Stoll On
> Tue, Dec 16, 2014 at 6:26 AM, Chandrasekhar Rudrappa
> <chandratr at gmail.com> wrote:
>> >Dear All,
>> >
>> >I am trying to fit the following model in nlsLM():
>> >
>> >fn5 <- function(x, T, t1, w_inf, Lt0){
>> >S<-function(x, T, t1){
>> >x+(1-T)/(2*pi)*sin(2*pi*(x-t1)/(1-T))
>> >}
>> >F <- function(x, T, t1){
>> >t2 <- t1 + (1-T)/2
>> >t3 <- t1 + (1+T)/2
>> >t.factorial <- x%%1
>> >floor(x)*(1-T) + S(t.factorial, T, t1)*(0<=t.factorial & t.factorial<t2) +
>> >S(t2, T, t1)*(t2<=t.factorial & t.factorial<t3) +
>> >S(t.factorial-T, T, t1)*(t3<=t.factorial & t.factorial<1)
>> >}
>> >return(w_inf - (w_inf - Lt0)*exp(-(2/30)*(F(x,T,t1)-F(7,T,t1))))
>> >}
>> >fn6<- y~fn5(x, T, t1, w_inf, Lt0)
>> >startval<-c(x=x, T=0.035, t1=0.359, w_inf=135, Lt0=47)
>> >(nlsktm1 <- nlsLM(fn6, start=startval, lower=c(x=x, T=0.0135, t1=0.259,
>> >w_inf=131, Lt0=41), jac=NULL, trace=T, data=ktm,
>> >control=nls.control(maxiter=10)))
>> >
>> >When I run the above script, the following error is displayed:
>> >
>> >Error in nlsModel(formula, mf, start, wts) :
>> > singular gradient matrix at initial parameter estimates
>> >In addition: Warning message:
>> >In nls.lm(par = start, fn = FCT, jac = jac, control = control, lower =
>> >lower, :
>> > lmdif: info = 0. Improper input parameters.
>> >
>> >Suitable help is requested.
>> >--
>> >Dr. TR Chandrasekhar, M.Sc., M. Tech., Ph. D.,
>> >Sr. Scientist
>> >Rubber Research Institute of India
>> >Hevea Breeding Sub Station
>> >Kadaba - 574 221
>> >DK Dt., Karnataka
>> >Phone-Land: 08251-214336
>> >Mobile: 9448780118
>> >
>> > [[alternative HTML version deleted]]
>> >
>> >______________________________________________
>> >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> >https://stat.ethz.ch/mailman/listinfo/r-help
>> >PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
>> >and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list