NonLinear Regression examples

These examples are run on the NIST Kirby2 dataset from http://cran.r-project.org/web/packages/NISTnls/NISTnls.pdf

library(NISTnls)
library(nls2)
## Loading required package: proto
data()

plot(y ~ x, data = Kirby2)

plot of chunk unnamed-chunk-1


fm1 <- nls(y ~ (b1 + b2 * x + b3 * x^2)/(1 + b4 * x + b5 * x^2), data = Kirby2, 
    trace = TRUE, start = c(b1 = 2, b2 = -0.1, b3 = 0.003, b4 = -0.001, b5 = 1e-05))
## 373285 :   2e+00 -1e-01  3e-03 -1e-03  1e-05
## 31571 :   2.008e+00 -1.653e-01  3.060e-03 -1.235e-04  1.447e-05
## 640 :   1.960e+00 -1.613e-01  2.915e-03 -6.856e-04  2.028e-05
## 7.214 :   1.643e+00 -1.376e-01  2.579e-03 -1.760e-03  2.171e-05
## 3.905 :   1.676e+00 -1.393e-01  2.597e-03 -1.723e-03  2.167e-05
## 3.905 :   1.674e+00 -1.393e-01  2.596e-03 -1.724e-03  2.166e-05
## 3.905 :   1.675e+00 -1.393e-01  2.596e-03 -1.724e-03  2.166e-05
## 3.905 :   1.675e+00 -1.393e-01  2.596e-03 -1.724e-03  2.166e-05
summary(fm1)
## 
## Formula: y ~ (b1 + b2 * x + b3 * x^2)/(1 + b4 * x + b5 * x^2)
## 
## Parameters:
##     Estimate Std. Error t value Pr(>|t|)    
## b1  1.67e+00   8.80e-02    19.0   <2e-16 ***
## b2 -1.39e-01   4.12e-03   -33.8   <2e-16 ***
## b3  2.60e-03   4.19e-05    62.0   <2e-16 ***
## b4 -1.72e-03   5.89e-05   -29.3   <2e-16 ***
## b5  2.17e-05   2.01e-07   107.6   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.164 on 146 degrees of freedom
## 
## Number of iterations to convergence: 7 
## Achieved convergence tolerance: 8.37e-07

fm1a <- nls(y ~ (b1 + b2 * x + b3 * x^2)/(1 + b4 * x + b5 * x^2), data = Kirby2, 
    trace = TRUE, alg = "port", start = c(b1 = 2, b2 = -0.1, b3 = 0.003, b4 = -0.001, 
        b5 = 1e-05))
##   0:     186642.68:  2.00000 -0.100000 0.00300000 -0.00100000 1.00000e-05
##   1:     20672.700: -1.81456 -0.185395 0.00275961 -0.000511581 1.11946e-05
##   2:     1171.0301:  1.32347 -0.135420 0.00270564 -0.000216322 1.63160e-05
##   3:     10.602085:  1.46049 -0.137694 0.00269684 -0.00116508 2.09991e-05
##   4:     1.9694042:  1.65291 -0.137906 0.00257834 -0.00176150 2.16235e-05
##   5:     1.9525567:  1.67712 -0.139421 0.00259761 -0.00172243 2.16721e-05
##   6:     1.9525371:  1.67431 -0.139262 0.00259599 -0.00172435 2.16642e-05
##   7:     1.9525370:  1.67452 -0.139275 0.00259613 -0.00172417 2.16649e-05
##   8:     1.9525370:  1.67450 -0.139274 0.00259612 -0.00172418 2.16648e-05
##   9:     1.9525370:  1.67451 -0.139274 0.00259612 -0.00172418 2.16648e-05
summary(fm1a)
## 
## Formula: y ~ (b1 + b2 * x + b3 * x^2)/(1 + b4 * x + b5 * x^2)
## 
## Parameters:
##     Estimate Std. Error t value Pr(>|t|)    
## b1  1.67e+00   8.80e-02    19.0   <2e-16 ***
## b2 -1.39e-01   4.12e-03   -33.8   <2e-16 ***
## b3  2.60e-03   4.19e-05    62.0   <2e-16 ***
## b4 -1.72e-03   5.89e-05   -29.3   <2e-16 ***
## b5  2.17e-05   2.01e-07   107.6   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.164 on 146 degrees of freedom
## 
## Algorithm "port", convergence message: relative convergence (4)

fm2 <- nls(y ~ (b1 + b2 * x + b3 * x^2)/(1 + b4 * x + b5 * x^2), data = Kirby2, 
    trace = TRUE, start = c(b1 = 1.5, b2 = -0.15, b3 = 0.0025, b4 = -0.0015, 
        b5 = 2e-05))
## 987.7 :   1.50000 -0.15000  0.00250 -0.00150  0.00002
## 4.659 :   1.694e+00 -1.407e-01  2.617e-03 -1.665e-03  2.171e-05
## 3.905 :   1.670e+00 -1.390e-01  2.594e-03 -1.728e-03  2.165e-05
## 3.905 :   1.675e+00 -1.393e-01  2.596e-03 -1.724e-03  2.167e-05
## 3.905 :   1.674e+00 -1.393e-01  2.596e-03 -1.724e-03  2.166e-05
## 3.905 :   1.675e+00 -1.393e-01  2.596e-03 -1.724e-03  2.166e-05
summary(fm2)
## 
## Formula: y ~ (b1 + b2 * x + b3 * x^2)/(1 + b4 * x + b5 * x^2)
## 
## Parameters:
##     Estimate Std. Error t value Pr(>|t|)    
## b1  1.67e+00   8.80e-02    19.0   <2e-16 ***
## b2 -1.39e-01   4.12e-03   -33.8   <2e-16 ***
## b3  2.60e-03   4.19e-05    62.0   <2e-16 ***
## b4 -1.72e-03   5.89e-05   -29.3   <2e-16 ***
## b5  2.17e-05   2.01e-07   107.6   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.164 on 146 degrees of freedom
## 
## Number of iterations to convergence: 5 
## Achieved convergence tolerance: 3.68e-06

fm2a <- nls(y ~ (b1 + b2 * x + b3 * x^2)/(1 + b4 * x + b5 * x^2), data = Kirby2, 
    trace = TRUE, alg = "port", start = c(b1 = 1.5, b2 = -0.15, b3 = 0.0025, 
        b4 = -0.0015, b5 = 2e-05))
##   0:     493.86048:  1.50000 -0.150000 0.00250000 -0.00150000 2.00000e-05
##   1:     144.67390:  1.91353 -0.145586 0.00250850 -0.00153288 1.99475e-05
##   2:     17.045810:  2.11949 -0.133663 0.00251086 -0.00153238 2.01985e-05
##   3:     2.5018675:  1.25831 -0.118532 0.00241458 -0.00184472 2.05844e-05
##   4:     1.9961205:  1.54694 -0.132259 0.00252529 -0.00180660 2.13202e-05
##   5:     1.9527499:  1.68278 -0.139752 0.00260118 -0.00171754 2.16878e-05
##   6:     1.9525386:  1.67381 -0.139233 0.00259568 -0.00172476 2.16628e-05
##   7:     1.9525370:  1.67451 -0.139274 0.00259612 -0.00172419 2.16648e-05
##   8:     1.9525370:  1.67450 -0.139274 0.00259612 -0.00172418 2.16648e-05
##   9:     1.9525370:  1.67451 -0.139274 0.00259612 -0.00172418 2.16648e-05
summary(fm2a)
## 
## Formula: y ~ (b1 + b2 * x + b3 * x^2)/(1 + b4 * x + b5 * x^2)
## 
## Parameters:
##     Estimate Std. Error t value Pr(>|t|)    
## b1  1.67e+00   8.80e-02    19.0   <2e-16 ***
## b2 -1.39e-01   4.12e-03   -33.8   <2e-16 ***
## b3  2.60e-03   4.19e-05    62.0   <2e-16 ***
## b4 -1.72e-03   5.89e-05   -29.3   <2e-16 ***
## b5  2.17e-05   2.01e-07   107.6   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.164 on 146 degrees of freedom
## 
## Algorithm "port", convergence message: relative convergence (4)

fm3 <- nls(y ~ cbind(1, x, x^2)/(1 + x * (b4 + b5 * x)), data = Kirby2, trace = TRUE, 
    algorithm = "plinear", start = c(b4 = -0.001, b5 = 1e-05))
## 379.4 :  -0.001000  0.000010 -4.166485  0.084557  0.001175
## 18.13 :  -0.0011449  0.0000203  0.9623247 -0.1190046  0.0025802
## 3.912 :  -1.744e-03  2.166e-05  1.679e+00 -1.391e-01  2.590e-03
## 3.905 :  -1.723e-03  2.167e-05  1.676e+00 -1.393e-01  2.597e-03
## 3.905 :  -1.724e-03  2.166e-05  1.674e+00 -1.393e-01  2.596e-03
## 3.905 :  -1.724e-03  2.166e-05  1.675e+00 -1.393e-01  2.596e-03
## 3.905 :  -1.724e-03  2.166e-05  1.675e+00 -1.393e-01  2.596e-03
summary(fm3)
## 
## Formula: y ~ cbind(1, x, x^2)/(1 + x * (b4 + b5 * x))
## 
## Parameters:
##         Estimate Std. Error t value Pr(>|t|)    
## b4     -1.72e-03   5.89e-05   -29.3   <2e-16 ***
## b5      2.17e-05   2.01e-07   107.6   <2e-16 ***
## .lin1   1.67e+00   8.80e-02    19.0   <2e-16 ***
## .lin.x -1.39e-01   4.12e-03   -33.8   <2e-16 ***
## .lin3   2.60e-03   4.19e-05    62.0   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.164 on 146 degrees of freedom
## 
## Number of iterations to convergence: 6 
## Achieved convergence tolerance: 4.78e-06

fm4 <- nls(y ~ cbind(1, x, x^2)/(1 + x * (b4 + b5 * x)), data = Kirby2, trace = TRUE, 
    algorithm = "plinear", start = c(b4 = -0.0015, b5 = 2e-05))
## 12.13 :  -0.001500  0.000020  0.901843 -0.110309  0.002435
## 3.914 :  -1.694e-03  2.171e-05  1.688e+00 -1.404e-01  2.612e-03
## 3.905 :  -1.726e-03  2.166e-05  1.672e+00 -1.391e-01  2.595e-03
## 3.905 :  -1.724e-03  2.167e-05  1.675e+00 -1.393e-01  2.596e-03
## 3.905 :  -1.724e-03  2.166e-05  1.674e+00 -1.393e-01  2.596e-03
## 3.905 :  -1.724e-03  2.166e-05  1.675e+00 -1.393e-01  2.596e-03
## 3.905 :  -1.724e-03  2.166e-05  1.675e+00 -1.393e-01  2.596e-03
summary(fm4)
## 
## Formula: y ~ cbind(1, x, x^2)/(1 + x * (b4 + b5 * x))
## 
## Parameters:
##         Estimate Std. Error t value Pr(>|t|)    
## b4     -1.72e-03   5.89e-05   -29.3   <2e-16 ***
## b5      2.17e-05   2.01e-07   107.6   <2e-16 ***
## .lin1   1.67e+00   8.80e-02    19.0   <2e-16 ***
## .lin.x -1.39e-01   4.12e-03   -33.8   <2e-16 ***
## .lin3   2.60e-03   4.19e-05    62.0   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.164 on 146 degrees of freedom
## 
## Number of iterations to convergence: 6 
## Achieved convergence tolerance: 3.68e-07