Skip to content
Prev 268048 / 398502 Next

Odp: nls, how to determine function?

Hi
Thanks for providing data and your code
**************************************************************************
711155378,NA,6.320284698,0.581632653,0.144578313,3.666666667,0,0,0,0,0,NA,
81818182,NA,NA,0,NA,0,0,0,NA,0.212454212,3.120181406,NA,0.011811024,NA,0,
0.120430108,5.928571429,1.75,0.679292929,0.97,NA,0,NA,NA,1,0.38547486,NA,
unnecessary
some correction
dat.df.2 <- data.frame(x=seq_along(dat), dat=dat)
ylim=c(0,100))
**************************************************************************
**************************************************************************
Yes. I think that the best source of information about nonlinear 
regression is book by Bates, Pinheiro - Mixed effect models with S and S+. 
There you can find how to determine starting parameters, how to construct 
and use your own function together with selfstart feature.
Maybe I do not understand well but looking at the picture it seems to me 
that logistic model is fitting your data quite well. You can use also four 
parameter logistic model.
=list(A=85.65, B=0, xmid = 72, scal = -6))
Formula: dat ~ SSfpl(x, A, B, xmid, scal)

Parameters:
     Estimate Std. Error t value Pr(>|t|) 
A      1.6729     1.5927   1.050    0.296 
B     85.5555     1.7065  50.134  < 2e-16 ***
xmid  71.7628     1.0762  66.679  < 2e-16 ***
scal  -5.8051     0.9162  -6.336 6.13e-09 ***
---
Signif. codes:  0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 

Residual standard error: 10.32 on 104 degrees of freedom

Number of iterations to convergence: 9 
Achieved convergence tolerance: 7.629e-06 
  (45 observations deleted due to missingness)

As you can see parameter A is insignificant so simple logistic can be used 
too. In that case upper asymptote is 85.6, lower asymptote is zero, 
inflection point is 72 (x where y is in the middle between both 
asymptotes) and scal is rate at which the curve is falling (growing).

There is however some wave in the beginning of your data

fit <-loess(dat ~ x, data = dat.df.2, span=0.3)
lines(dat.df.2$x[complete.cases(dat.df.2)], predict(fit), col=3)

So it is up to you to decide if you are satisfied with getting asymptotic 
values from logistic model or you want to set something more elaborated.

Regards
Petr
http://www.R-project.org/posting-guide.html