singular gradient error with nls in r; how do I know if its the code or the data? -


i'm trying run non linear regression on data:

flux<-c(192.09536, 199.47616, 137.63245, 133.60358, -89.28360, -23.17639, -27.14659, 107.25287,  52.72565, na, 167.43277, 113.59047) par<-c(4.166667e-01, 4.347826e-02, 4.583333e-01, 1.845833e+02, 1.122688e+03, 1.059048e+03, 6.384000e+02, 3.326087e+02, 7.094762e+02, 4.180000e+02, 3.953333e+02, 3.998636e+02) obs<-c(1,2,3,4,5,6,7,8,9,10,11,12) curve1<-data.frame(flux, par, obs) curve1<-do.call("cbind", curve1) 

this first model tried, has worked on other similar datasets:

model1 <- nls(flux~b*par/(c+par)-a, data = curve1, start=list(a=180,                                                           b=-200, c=800)) 

however data model1 gives:

error in nls(flux ~ b * par/(c + par) - a, data = curve1, start =     list(a = 180, : singular gradient 

i thought might because starting parameters wrong tried turn self starting model (i've tried lots of different starting parameters):

model2<-with(curve1, nls(flux~ssasymp(par, a, b, c))) 

this gives same error. think have used ssasymp wrong in case because fits incorrect curves data able fit model1 to. think because i've confused r a, b , c (?). i've read when using ssasymp: b 'the horizontal asymptote (a) -the response when x 0' while c rate constant.

in original equation in model1 b horizontal asymptote, c rate constant , response when x 0.

if try write self starting model reflect this:

model3<-with(curve1, nls(flux~ssasymp(par, b, (b-a), c))) 

i error: in addition: warning message: in nls(flux ~ ssasymp(par, b, (b - a), c)) : no starting values specified parameters. initializing ‘a’ '1.'. consider specifying 'start' or using selfstart model

i looking advice on 1) model1 not working because of error in code/incorrect starting parameters or because model doesn't fit data?

if latter case, there way force r best fit non-linear model anyway? ecologically, should saturating curve.

2) can i/how fit equation self-starting model? have fundamentally misunderstood how use ssasymp?

any appreciated. apologies if haven't explained or formatted well, first post , i'm not experienced r user or statistician!

something this?

enter image description here

model1<-nls(flux~b*par/(c+par)-a, data = curve1, start=list(a=180, b=-200, c=-2000)) plot(flux~par,curve1) curve(predict(model1,newdata=data.frame(par=x)),add=true) summary(model1) # formula: flux ~ b * par/(c + par) - # # parameters: #   estimate std. error t value pr(>|t|)     #  -179.17      22.86  -7.837 5.06e-05 *** # b  1009.36    2556.44   0.395    0.703     # c -5651.20   11542.41  -0.490    0.638     # --- # signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # residual standard error: 42.43 on 8 degrees of freedom # ... 

your data pathological. functions of form

y = b * x / (c+x)

are concave when b < 0 , c > 0; concave down when b > 0 , c < 0, providing |c| > max(x) (otherwise there's vertical asymptote, demonstrated in 1 of comments). because data "nearly" linear, , there substantial scatter, best fit (e.g., set of parameters a, b, , c minimize residual sum-of-squares), concave down (c < 0). if start estimate of c < -max(x), convergence.

now, gather question c has physical meaning requires > 0. problem here model over-specified (too many parameters). in saturating curve, rate constant determined curvature. in case, there no curvature (or, if any, negative), cannot determine rate constant. mathematically, x << c

b * x / (c + x) ~ (b/c) * x

in case slope -0.25, b/c ~ -0.25. there infinitely many values of b , c yield ratio. so, while know lot ratio b/c, know nothing @ b or c individually. why standard error in parameters large in fit above (and p-values high).

the bottom line that, in specific case, have insufficient data determine a, b, , c separately, accuracy.

[two minor points]

  1. the presence of nas in data has nothing - nls(...) removes rows containing nas default.
  2. you don't need line: curve1<-do.call("cbind", curve1)

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -