# Complicated nls formula giving singular gradient message Classic List Threaded 7 messages Open this post in threaded view
|

## Complicated nls formula giving singular gradient message

 I'm attempting to calculate a regression in R that I normally use Prism for, because the formula isn't pretty by any means. Prism presents the formula (which is in the Prism equation library as Heterologous competition with depletion, if anyone is curious) in these segments: KdCPM = KdnM*SpAct*Vol*1000 R=NS+1 S=(1+10^(X-LogKi))*KdCPM+Hot a=-1*R b=R*S+NS*Hot+BMax c = -1*Hot*(S*MS+BMax) Y = (-1*b+sqrt(b*b-4*a*c))/(2*a) I'm only trying to solve for NS, LogKi, and BMax. I have everything else (KdnM, SpAct, Vol, Hot). I would use the simple formula at the bottom and then backsolve for the terms I'm looking for, but the simple formula at the bottom takes out the X term, which is contained within S, which it itself contained in both b and c. So I tried to substitute all the terms back into Y and got the following formula<-as.formula("Y ~ (-1*(((NS+1)*((1+10^(X-LogKi))*(KdnM*SpAct*Vol*1000)+Hot))+NS*Hot+BMax)+sqrt((((NS+1)*((1+10^(X-LogKi))*(KdnM*SpAct*Vol*1000)+Hot))+NS*Hot+BMax)*(((NS+1)*((1+10^(X-LogKi))*(KdnM*SpAct*Vol*1000)+Hot))+NS*Hot+BMax)-4*(-1*(NS+1))*(-1*Hot*(((1+10^(X-LogKi))*(KdnM*SpAct*Vol*1000)+Hot)*NS+BMax))))/(2*-1*(NS+1))") But trying to use that formula gives me the single gradient message, which I wasn't entirely surprised by. fit<-nls(formula=formula,data=data,start=list(NS=.01,LogKi=-7,BMax=33000)) Error in nls(formula = formula, data = all_no_outliers, start = list(NS = 0.01,  :   singular gradient I've never worked with a formula this complicated in R. Is it even possible to do something like this? Any ideas or points in the right direction would be greatly appreciated. Thanks, Jared         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Complicated nls formula giving singular gradient message

Open this post in threaded view
|

## Re: Complicated nls formula giving singular gradient message

Open this post in threaded view
|

## Re: Complicated nls formula giving singular gradient message

 I always enjoy these direct comparisons between different software packages. I coded this up in AD Model Builder which is freely available at http://admb-project.org   ADMB calculates exact derivatives via automatic differentiation so it tends to be more stable for these difficult problems. The parameter estimates are # Number of parameters = 3 Objective function value = 307873.  Maximum gradient component = 1.45914e-06 # NS: 0.00865232633386 # LogKi: -8.98700621813 # BMax: 237135.365156 The objective function is just least squares. So it looks like SAS did pretty well before dying. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|