as.lm: Converts nls class objects to lm class

Description Usage Arguments Details Value Author(s) Examples

View source: R/as.lm.R

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

1
2
3
4
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# 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)

walmes/wzRfun documentation built on Aug. 10, 2021, 2:19 p.m.