model_diagnostics {DImodelsVis} | R Documentation |
Regression diagnostics plots with pie-glyphs
Description
This function returns regression diagnostics plots for a model with points replaced by pie-glyphs making it easier to track various data points in the plots. This could be useful in models with compositional predictors to quickly identify any observations with unusual residuals, hat values, etc.
Usage
model_diagnostics(
model,
which = c(1, 2, 3, 5),
prop = NULL,
FG = NULL,
npoints = 3,
cook_levels = c(0.5, 1),
pie_radius = 0.2,
pie_colours = NULL,
only_extremes = FALSE,
label_size = 4,
points_size = 3,
plot = TRUE,
nrow = 0,
ncol = 0
)
Arguments
model |
A statistical regression model object fit using |
which |
A subset of the numbers 1 to 6, by default 1, 2, 3, and 5,
referring to |
prop |
A character vector giving names of columns containing
proportions to show in the pie-glyphs. If not specified,
black points (geom_point) will be shown for each observation in
the model. Note: |
FG |
A character vector of same length as |
npoints |
Number of points to be labelled in each plot, starting with the most extreme (those points with the highest absolute residuals or hat values). |
cook_levels |
A numeric vector specifying levels of Cook's distance at which to draw contours. |
pie_radius |
A numeric value specifying the radius (in cm) for the pie-glyphs. |
pie_colours |
A character vector specifying the colours for the slices within the pie-glyphs. |
only_extremes |
A logical value indicating whether to show pie-glyphs only for extreme observations (points with the highest absolute residuals or hat values). |
label_size |
A numeric value specifying the size of the labels identifying extreme observations. |
points_size |
A numeric value specifying the size of points (when pie-glyphs not shown) shown in the plots. |
plot |
A boolean variable indicating whether to create the plot or return
the prepared data instead. The default |
nrow |
Number of rows in which to arrange the final plot. |
ncol |
Number of columns in which to arrange the final plot. |
Value
A ggmultiplot (ggplot if single plot is returned) class object or data-frame (if plot = FALSE
).
Examples
library(DImodels)
## Load data
data(sim1)
## Fit model
mod1 <- lm(response ~ 0 + (p1 + p2 + p3 + p4)^2, data = sim1)
## Get diagnostics plot
## Recommend to store plot in a variable, to access individual plots later
diagnostics <- model_diagnostics(mod1, prop = c("p1", "p2", "p3", "p4"))
print(diagnostics)
## Access individual plots
print(diagnostics[[1]])
print(diagnostics[[4]])
## Change plot arrangement
model_diagnostics(mod1, prop = c("p1", "p2", "p3", "p4"),
which = c(1, 3), nrow = 2, ncol = 1)
## Show only extreme points as pie-glyphs to avoid overplotting
model_diagnostics(mod1, prop = c("p1", "p2", "p3", "p4"),
which = 2, npoints = 5, only_extremes = TRUE)
## If model is a DImodels object, the don't need to specify prop
DI_mod <- DI(y = "response", prop = c("p1", "p2", "p3", "p4"),
DImodel = "FULL", data = sim1)
model_diagnostics(DI_mod, which = 1)
## Specify `plot = FALSE` to not create the plot but return the prepared data
head(model_diagnostics(DI_mod, which = 1, plot = FALSE))