Learn R Programming

broom (version 0.4.3)

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 nls
tidy(x, conf.int = FALSE, conf.level = 0.95, quick = FALSE,
  ...)

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

# S3 method for 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

quick

whether to compute a smaller and faster version, containing only the term and estimate columns.

...

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:

term

The term in the nonlinear model being estimated and tested

estimate

The estimated coefficient

std.error

The standard error from the linear model

statistic

t-statistic

p.value

two-sided p-value

augment returns one row for each original observation, with two columns added:

.fitted

Fitted values of model

.resid

Residuals

If newdata is provided, these are computed on based on predictions of the new data.

glance returns one row with the columns

sigma

the square root of the estimated residual variance

isConv

whether the fit successfully converged

finTol

the achieved convergence tolerance

logLik

the data's log-likelihood under the model

AIC

the Akaike Information Criterion

BIC

the Bayesian Information Criterion

deviance

deviance

df.residual

residual 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
# NOT RUN {
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