[R] NLS Singular Gradient Error
Hello, I am trying to model a type II functional response of number of prey eaten (Ne) against number supplied (No) with a non-linear least squares regression (nls). I am using a modification of Holling's (1959) disc equation to account for non-replacement of prey; Ne=No{1-exp[a(bNe-T)]} where a is the attack rate, b is the handling time, and T is the experimental period. My script is as follows; model-nls(Ne~No*(1-exp(a*(b*Ne-T))),start=list(a=1.2,b=0.015,T=24)) This returns the following error; Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at initial parameter estimates. Can anyone please advise as to what I may be doing wrong? I have tried modifying the parameter start points with no success. Many thanks, -- View this message in context: http://r.789695.n4.nabble.com/NLS-Singular-Gradient-Error-tp2069029p2069029.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] NLS Singular Gradient Error
Your model is not identifiable. The model contains the exponential of a linear function of Ne but such a function can be described in two parameters and you have three. Perhaps you know T? If that is the case remove it from the start list and set it to the known value T - ... before running nls. On Wed, Apr 28, 2010 at 7:43 AM, bsnrh bs...@leeds.ac.uk wrote: Hello, I am trying to model a type II functional response of number of prey eaten (Ne) against number supplied (No) with a non-linear least squares regression (nls). I am using a modification of Holling's (1959) disc equation to account for non-replacement of prey; Ne=No{1-exp[a(bNe-T)]} where a is the attack rate, b is the handling time, and T is the experimental period. My script is as follows; model-nls(Ne~No*(1-exp(a*(b*Ne-T))),start=list(a=1.2,b=0.015,T=24)) This returns the following error; Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at initial parameter estimates. Can anyone please advise as to what I may be doing wrong? I have tried modifying the parameter start points with no success. Many thanks, -- View this message in context: http://r.789695.n4.nabble.com/NLS-Singular-Gradient-Error-tp2069029p2069029.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] NLS Singular Gradient Error
Thank you for your reply. The equation is derived from Juliano's chapter in Scheiner and Gurevitch (2001) on Functional Responses. I have tried calling T-24 and rerunning with no success sadly. -- View this message in context: http://r.789695.n4.nabble.com/NLS-Singular-Gradient-Error-tp2069029p2069149.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] NLS Singular Gradient Error
What does no success mean? Some things to try are: - since log(1-Ne/No) is linear in Ne and run an lm(log(1-Ne/No) ~ Ne) and then use the implied values from that or use them as starting values, - reparameterize a*(b*Ne-T) to aa*Ne + bb and try nls on that On Wed, Apr 28, 2010 at 9:13 AM, bsnrh bs...@leeds.ac.uk wrote: Thank you for your reply. The equation is derived from Juliano's chapter in Scheiner and Gurevitch (2001) on Functional Responses. I have tried calling T-24 and rerunning with no success sadly. -- View this message in context: http://r.789695.n4.nabble.com/NLS-Singular-Gradient-Error-tp2069029p2069149.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] NLS Singular Gradient Error
Thank you for your message. This isn't the Rogers equation, although I am not familiar with that particular one. It is from Juliano's (2001) Nonlinear Curve Fitting chapter in Scheiner and Gurevitch. -- View this message in context: http://r.789695.n4.nabble.com/NLS-Singular-Gradient-Error-tp2069029p2069271.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] NLS Singular Gradient Error
No success means that I was not successful in changing the outputed error. It had no effect on the model. Thank you for your suggestions; The first returns this error; Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/Inf in foreign function call (arg 4) I don't understand your reasoning behind the second suggestion, but assuming you mean a*a*Ne + b*b and not aa*Ne + bb the following error occurs; Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity produced when evaluating the model Many thanks, -- View this message in context: http://r.789695.n4.nabble.com/NLS-Singular-Gradient-Error-tp2069029p2069263.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] NLS Singular Gradient Error
Maybe you are applying a completely inappropriate model such as would be the case if Ne/No is not strictly between 0 and 1. All we can do is guess unless you provide a reproducible example which means that if we paste it in from your post it will give the same errors you see. aa means aa, not a*a. On Wed, Apr 28, 2010 at 10:08 AM, bsnrh bs...@leeds.ac.uk wrote: No success means that I was not successful in changing the outputed error. It had no effect on the model. Thank you for your suggestions; The first returns this error; Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/Inf in foreign function call (arg 4) I don't understand your reasoning behind the second suggestion, but assuming you mean a*a*Ne + b*b and not aa*Ne + bb the following error occurs; Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity produced when evaluating the model Many thanks, -- View this message in context: http://r.789695.n4.nabble.com/NLS-Singular-Gradient-Error-tp2069029p2069263.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] NLS Singular Gradient Error
I don't know any about you research but I agree with Gabor: the model is identifiable. No*(1-exp(a*(b*Ne-T))) can be reparametrized to No*(1-exp(C*NeD)), where C=a*b and D=a*T. This reduces the model to 3 parameters and can see shown that is a reperametrization of the SSasympOff() defined in R (with default start values). No is a parameter too, so you need provide start values in start list. Look: # indentifiability No - 100; a - 1; b - -1; T - 2 Ne - seq(1, 10, l=8) curve(No*(1-exp(a*(b*x-T))), 0, 10) abline(h=No*(1-exp(a*(b*0-T # intercept C - a*b; D - a*T curve(No*(1-exp(C*x-D)), add=TRUE, lty=2, col=2, lwd=2) help(SSasympOff, help_type=html) # model speficication nls(Ne~No*(1-exp(a*(b*Ne-T))), start=list(a=1.2, b=0.015, T=24)) ^ ^ ^ ^ y y? y - No*(1-exp(a*(b*Ne-T)))+rnorm(Ne,0,0.1) plot(y~Ne) nls(y~No*(1-exp(a*(b*Ne-T))), start=list(No=No, a=a, b=b, T=T)) Erro em numericDeriv(form[[3L]], names(ind), env) : Obtido valor faltante ou infinito quando avaliando o modelo nls(y~No*(1-exp(C*Ne-D)), start=list(No=No, C=C, D=D)) Nonlinear regression model model: y ~ No * (1 - exp(C * Ne - D)) data: parent.frame() No C D 99.9763 -0.9972 2.0197 residual sum-of-squares: 0.02746 Number of iterations to convergence: 2 Achieved convergence tolerance: 6.673e-07 Bests. - ..ooo0 ... ..()... 0ooo... Walmes Zeviani ...\..(.(.)... Master in Statistics and Agricultural Experimentation \_). )../ walmeszevi...@hotmail.com, Lavras - MG, Brasil (_/ -- View this message in context: http://r.789695.n4.nabble.com/NLS-Singular-Gradient-Error-tp2069029p2073452.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.