I'm a novice with R. I want to do a nonlinear regression fitting on the following 1st order decaying time-series formula:
y = a*exp^(-kt)
Can anyone show me the scripts and process to do this nonlinear fitting? Thanks!
The nls() function performs non-linear least squares, which I think is what you're asking about. Here's an example:
> data = data.frame(Year=0:7, Count=c(3, 5, 9, 30, 62, 154, 245, 321)) > out = nls(Count~a*exp(b*Year), data=data, start=list(a=1, b=1)) # Look at output > summary(out) Formula: Count ~ a * exp(b * Year) Parameters: Estimate Std. Error t value Pr(>|t|) a 11.52774 4.30644 2.677 0.036689 * b 0.48412 0.05778 8.379 0.000157 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 24.54 on 6 degrees of freedom Number of iterations to convergence: 11 Achieved convergence tolerance: 4.533e-06
Another option might be to do straight linear regression on the log-transformed data -- I'm not sure if that violates your modeling assumptions.
Source for this: https://stat.ethz.ch/pipermail/r-help/2007-July/137063.html
The nls() function performs non-linear least squares, which I think is what you're asking about. Here's an example:
Another option might be to do straight linear regression on the log-transformed data -- I'm not sure if that violates your modeling assumptions.
Source for this: https://stat.ethz.ch/pipermail/r-help/2007-July/137063.html