as.lm: Converts nls class objects to lm class

View source: R/as.lm.nls.R

as.lmR Documentation

Converts nls class objects to lm class

Description

This functions is a modified version of the code available at the nls2 package on github https://github.com/ggrothendieck/nls2. This function is no longer available in the current version of nls2 package.

Usage

as.lm(object, ...)

## S3 method for class 'nls'
as.lm(object, ...)

Arguments

object

An object of class nls.

...

Currently not used.

Details

This function is useful to get the residuals plot for the fitted nls model. The dependence on the as.proto.list function in the proto package was removed (also this function no longer exists). Thanks for the original author of this function G. Grothendieck.

Value

This function returns an object of class lm created from the nls object. The linear model design matrix used is the the partial derivatives of the nls model function with relation to the model parameters, i.e. the gradient matrix.

Author(s)

Walmes Zeviani, walmes@ufr.br

Examples


# An simple nls fit.
n0 <- nls(dist ~ A + B * speed^C,
          data = cars,
          start = c(A = 0, B = 1, C = 1))
summary(n0)

# The results.
plot(dist ~ speed, data = cars)
with(as.list(coef(n0)), {
    curve(A + B * speed^C, xname = "speed", add = TRUE)
})

# Residual analysis.
par(mfrow = c(2, 2))
plot(as.lm(n0))
layout(1)


earlycapistran/consLettersUtils documentation built on Nov. 22, 2022, 1:22 a.m.