| modelcheck | R Documentation |
Draw the teaching diagnostic plots used by older 's20x' workflows. 'modelcheck()' is retained as an exported compatibility helper for model checking, while newer teaching material may use focused diagnostic helpers such as [eovcheck()], [normcheck()], and [cooks20x()] directly.
modelcheck(x, ...)
## S3 method for class 'lm'
modelcheck(
x,
which = 1:3,
mar = c(3, 4, 1.5, 4),
engine = c("base", "ggplot2"),
...
)
x |
The fitted model. |
which |
The plot(s) to be drawn. Residuals versus fitted values
( |
mar |
Margins applied to each selected plot. Ignored by the ggplot2 engine. |
engine |
plotting engine to use. The default, |
... |
any other arguments to pass to |
The default base graphics engine preserves the original teaching plots and draws directly on the active graphics device. The optional ggplot2 engine is intended for users who want reusable plot objects for reports or further customisation; it requires ggplot2 to be installed and returns ggplot objects instead of drawing base graphics side effects.
Draws diagnostic plots for teaching model checking when using the
base engine. With engine = "ggplot2", returns a ggplot object for a
single selected plot, or a named list of ggplot objects for multiple selected
plots.
data(peru.df)
lmFit = lm(BP ~ weight, data = peru.df)
# Plot residuals versus fitted values only
modelcheck(lmFit, 1)
# Plot residuals versus fitted values, histogram, and Q-Q plot
modelcheck(lmFit, 1:2)
# Plot all diagnostics
modelcheck(lmFit)
# Optional ggplot2 engine for reusable plot objects
if (requireNamespace("ggplot2", quietly = TRUE)) {
diagnosticPlots = modelcheck(lmFit, engine = "ggplot2")
names(diagnosticPlots)
modelcheck(lmFit, which = 1, engine = "ggplot2")
modelcheck(lmFit, which = 2, engine = "ggplot2")
modelcheck(lmFit, which = 3, engine = "ggplot2")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.