df_from_model: Creates a data.frame from a model

View source: R/df_from_model.R

df_from_modelR Documentation

Creates a data.frame from a model

Description

df_from_model creates and returns a data.frame from a model object such as a(n): aov, lm, or glm object. The return data.frame will contain two columns, one for residuals ('res'), and a second for fitted values ('fit').

Usage

df_from_model(model, type = "rstandard")

Arguments

model

A model object such as a(n): aov, lm, or glm object, that is compatible with fitted and residuals methods.

type

The type of residuals to be returned in the data.frame. The residual type supplied must match a function name, for example: residuals, rstandard, and rstudent. Values can be supplied as quoted or unquoted elements, for example: "rstandard" or rstandard.

Value

The output will be a two-column data.frame with columns 'res' and 'fit' containing the residuals and fitted values.

See Also

plot.lm, residual_plots, gg_residual_plots

Examples

data(npk)
npk.aov <- aov(yield ~ block + N*P*K, npk)
summary(npk.aov)
npk.aov1 <- aov(yield ~ block + N + K, data = npk)
summary(npk.aov1)
summary.lm(npk.aov1)
model.tables(npk.aov1, type = "means", se = TRUE)
plot(npk.aov1)

npk.table <- df_from_model(npk.aov1, type = "rstandard")
df_from_model(npk.aov1, type = rstandard)
df_from_model(npk.aov1)

df_from_model(npk.aov1, type = "rstudent")
df_from_model(npk.aov1, type = "residuals")
df_from_model(npk.aov1, type = "resid")

rm(list = c("npk", "npk.aov", "npk.aov1", "npk.table"))

## Not run: 
df_from_model(npk.aov1, resid)

## End(Not run)


jjw3952/mcotear documentation built on Sept. 2, 2023, 10:30 a.m.