Main page: https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/BOD
BOD
## Time demand
## 1 1 8.3
## 2 2 10.3
## 3 3 19.0
## 4 4 16.0
## 5 5 15.6
## 6 7 19.8
require(stats)
# simplest form of fitting a first-order model to these data
fm1 <- nls(demand ~ A*(1-exp(-exp(lrc)*Time)), data = BOD,
start = c(A = 20, lrc = log(.35)))
coef(fm1)
## A lrc
## 19.1425770 -0.6328215
fm1
## Nonlinear regression model
## model: demand ~ A * (1 - exp(-exp(lrc) * Time))
## data: BOD
## A lrc
## 19.1426 -0.6328
## residual sum-of-squares: 25.99
##
## Number of iterations to convergence: 4
## Achieved convergence tolerance: 3.588e-07
# using the plinear algorithm
fm2 <- nls(demand ~ (1-exp(-exp(lrc)*Time)), data = BOD,
start = c(lrc = log(.35)), algorithm = "plinear", trace = TRUE)
## 32.94622 : -1.049822 22.126001
## 25.99248 : -0.6257161 19.1031883
## 25.99027 : -0.6327039 19.1419223
## 25.99027 : -0.6328192 19.1425644
# using a self-starting model
fm3 <- nls(demand ~ SSasympOrig(Time, A, lrc), data = BOD)
summary(fm3)
##
## Formula: demand ~ SSasympOrig(Time, A, lrc)
##
## Parameters:
## Estimate Std. Error t value Pr(>|t|)
## A 19.1426 2.4959 7.670 0.00155 **
## lrc -0.6328 0.3824 -1.655 0.17328
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.549 on 4 degrees of freedom
##
## Number of iterations to convergence: 0
## Achieved convergence tolerance: 6.473e-07