Learn R Programming

broom (version 0.3.4)

nls_tidiers: Tidying methods for a nonlinear model

Description

These methods tidy the coefficients of a nonlinear model into a summary, augment the original data with information on the fitted values and residuals, and construct a one-row glance of the model's statistics.

Usage

## S3 method for class 'nls':
tidy(x, conf.int = FALSE, conf.level = 0.95, ...)

## S3 method for class 'nls': augment(x, data = NULL, newdata = NULL, ...)

## S3 method for class 'nls': glance(x, ...)

Arguments

x
An object of class "nls"
conf.int
whether to include a confidence interval
conf.level
confidence level of the interval, used only if conf.int=TRUE
...
extra arguments (not used)
data
original data this was fitted on; if not given this will attempt to be reconstructed from nls (may not be successful)
newdata
new data frame to use for predictions

Value

  • All tidying methods return a data.frame without rownames. The structure depends on the method chosen.

    tidy returns one row for each coefficient in the model, with five columns:

  • termThe term in the nonlinear model being estimated and tested
  • estimateThe estimated coefficient
  • std.errorThe standard error from the linear model
  • statistict-statistic
  • p.valuetwo-sided p-value
  • augment returns one row for each original observation, with two columns added:
  • .fittedFitted values of model
  • .residResiduals
  • If newdata is provided, these are computed on based on predictions of the new data.

    glance returns one row with the columns

  • sigmathe square root of the estimated residual variance
  • isConvwhether the fit successfully converged
  • finTolthe achieved convergence tolerance
  • logLikthe data's log-likelihood under the model
  • AICthe Akaike Information Criterion
  • BICthe Bayesian Information Criterion
  • deviancedeviance
  • df.residualresidual degrees of freedom

Details

When the modeling was performed with na.action = "na.omit" (as is the typical default), rows with NA in the initial data are omitted entirely from the augmented data frame. When the modeling was performed with na.action = "na.exclude", one should provide the original data as a second argument, at which point the augmented data will contain those rows (typically with NAs in place of the new columns). If the original data is not provided to augment and na.action = "na.exclude", a warning is raised and the incomplete rows are dropped.

See Also

na.action

nls and summary.nls

Examples

Run this code
n <- nls(mpg ~ k * e ^ wt, data = mtcars, start = list(k = 1, e = 2))

tidy(n)
augment(n)
glance(n)

library(ggplot2)
ggplot(augment(n), aes(wt, mpg)) + geom_point() + geom_line(aes(y = .fitted))

# augment on new data
newdata <- head(mtcars)
newdata$wt <- newdata$wt + 1
augment(n, newdata = newdata)

Run the code above in your browser using DataLab