augment_longer {regressinator}R Documentation

Augment a model fit with residuals, in "long" format

Description

Use broom::augment() to augment a model fit with residual and fit information, then reformat the resulting data frame into a "long" format with one row per predictor per observation, to facilitate plotting of the result.

Usage

augment_longer(x, ...)

Arguments

x

A model fit object, such as those returned by lm() or glm(). See the broom documentation for the full list of model types supported.

...

Additional arguments passed to broom::augment().

Details

The name comes by analogy to tidyr::pivot_longer(), and the concept of long versus wide data formats.

Value

A data frame (tibble) in similar form to those produced by broom::augment(), but expanded to have one row per predictor per observation. Columns .predictor_name and .predictor_value identify the predictor and its value. An additional column .obs records the original observation numbers so results can be matched to observations in the original model data.

Limitations

Factor predictors (as factors, logical, or character vectors) can't coexist with numeric variables in the .predictor_value column. If there are some numeric and some factor predictors, the factor predictors will automatically be omitted. If all predictors are factors, they will be combined into one factor with all levels. However, if a numeric variable is converted to factor in the model formula, such as with y ~ factor(x), the function cannot determine the appropriate types and will raise an error. Create factors as needed in the source data frame before fitting the model to avoid this issue.

See Also

partial_residuals(), binned_residuals()

Examples

fit <- lm(mpg ~ cyl + disp + hp, data = mtcars)

# each observation appears 3 times, once per predictor:
augment_longer(fit)

[Package regressinator version 0.1.3 Index]