Skip to contents

Fits \(y = f(x, \theta) + \epsilon\) by least squares, the model being written as a formula such as y ~ a * (1 - exp(-b * x)) whose parameters are the names in start. Gauss-Newton follows the nls algorithm of Bates and Chambers (1992): increments from the QR decomposition of the gradient, step halving with a step factor that doubles back after each success, and the relative-offset convergence criterion of Bates and Watts (1988). Levenberg-Marquardt is available for poor starting values. The Jacobian is analytic (via stats::deriv) when possible, otherwise by central differences.

Usage

morie_nls(
  formula,
  data,
  start,
  algorithm = c("gauss-newton", "levenberg-marquardt"),
  control = list()
)

# S3 method for class 'morie_nls'
print(x, ...)

# S3 method for class 'morie_nls'
summary(object, ...)

# S3 method for class 'summary.morie_nls'
print(x, ...)

# S3 method for class 'morie_nls'
coef(object, ...)

# S3 method for class 'morie_nls'
vcov(object, ...)

# S3 method for class 'morie_nls'
fitted(object, ...)

# S3 method for class 'morie_nls'
residuals(object, ...)

# S3 method for class 'morie_nls'
deviance(object, ...)

# S3 method for class 'morie_nls'
df.residual(object, ...)

# S3 method for class 'morie_nls'
logLik(object, ...)

# S3 method for class 'morie_nls'
predict(object, newdata = NULL, ...)

Arguments

formula

Model formula, response ~ expression; a one-sided ~ expression minimises the sum of squares of the expression. Functions from base R and pnorm, dnorm, qnorm, plogis, dlogis, qlogis may be used.

data

Data frame (or named list) holding the variables.

start

Named list or vector of starting values; vector-valued entries give indexed parameters (b[1], b[2], named b1, b2 in the output).

algorithm

"gauss-newton" (default) or "levenberg-marquardt".

control

List of settings: maxiter (50), tol (1e-5, on the relative offset), minFactor (1/1024), scaleOffset (0), warnOnly (FALSE: non-convergence is an error), jacobian ("auto", "analytic" or "central"), and for Levenberg-Marquardt lambda (initial damping, 1e-3) and maxlambda (1e16).

x, object

A "morie_nls" fit.

...

Unused.

newdata

Optional data frame (or list) of predictor values.

Value

An object of class "morie_nls": coefficients, coef_table (Estimate, Std. Error, t value, Pr(>|t|)), sigma (residual standard error), df (p, n - p), cov.unscaled, vcov, fitted.values, residuals, deviance, convInfo (isConv, finIter, finTol, stopCode, stopMessage), algorithm, jacobian, formula, call.

References

Bates, D. M. and Watts, D. G. (1988). Nonlinear Regression Analysis and Its Applications. Wiley.

Bates, D. M. and Chambers, J. M. (1992). Nonlinear models. In Chambers, J. M. and Hastie, T. J. (eds), Statistical Models in S. Wadsworth & Brooks/Cole.

Marquardt, D. W. (1963). An algorithm for least-squares estimation of nonlinear parameters. SIAM Journal on Applied Mathematics 11, 431-441.

More, J. J. (1978). The Levenberg-Marquardt algorithm: implementation and theory. Lecture Notes in Mathematics 630, 105-116.

Examples

set.seed(1)
d <- data.frame(x = seq(0, 5, length.out = 40))
d$y <- 3 * (1 - exp(-0.8 * d$x)) + rnorm(40, sd = 0.05)
fit <- morie_nls(y ~ a * (1 - exp(-b * x)), d, start = list(a = 1, b = 1))
summary(fit)
#> 
#> Formula: y ~ a * (1 - exp(-b * x))
#> 
#> Parameters:
#>   Estimate Std. Error t value  Pr(>|t|)    
#> a 2.994317   0.015653 191.296 < 2.2e-16 ***
#> b 0.811495   0.013871  58.501 < 2.2e-16 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> Residual standard error: 0.04456 on 38 degrees of freedom
#> 
#> Number of iterations to convergence: 5 
#> Achieved convergence tolerance: 3.706773e-07 
#> (gauss-newton, analytic Jacobian)
predict(fit, data.frame(x = c(1, 2)))
#> [1] 1.664261 2.403515