Learn R Programming

sjPlot (version 2.1.0)

sjp.resid: Plot predicted values and their residuals

Description

This function plots observed and predicted values of the response of linear (mixed) models for each coefficient and highlights the observed values according to their distance (residuals) to the predicted values. This allows to investigate how well actual and predicted values of the outcome fit across the predictor variables.

Usage

sjp.resid(fit, geom.size = 2, remove.estimates = NULL, show.lines = TRUE, show.resid = TRUE, show.pred = TRUE, show.ci = F, prnt.plot = TRUE)

Arguments

fit
fitted linear (mixed) regression model (including objects of class gls or plm).
geom.size
size resp. width of the geoms (bar width, line thickness or point size, depending on plot type and function). Note that bar and bin widths mostly need smaller values than dot sizes.
remove.estimates
character vector with coefficient names that indicate which estimates should be removed from the plot. remove.estimates = "est_name" would remove the estimate est_name. Default is NULL, i.e. all estimates are printed.
show.lines
logical, if TRUE, a line connecting predicted and residual values is plotted. Set this argument to FALSE, if plot-building is too time consuming.
show.resid
logical, if TRUE, residual values are plotted.
show.pred
logical, if TRUE, predicted values are plotted.
show.ci
logical, if TRUE, depending on type, a confidence interval or region is added to the plot.
prnt.plot
logical, if TRUE (default), plots the results as graph. Use FALSE if you don't want to plot any graphs. In either case, the ggplot-object will be returned as value.

Value

(Insisibily) returns the ggplot-object with the complete plot (plot) as well as the data frame that was used for setting up the ggplot-object (mydf).

Examples

Run this code
library(sjmisc)
data(efc)
# fit model
fit <- lm(neg_c_7 ~ c12hour + e17age + e42dep, data = efc)

# plot residuals for all independent variables
sjp.resid(fit)

# remove some independent variables from output
sjp.resid(fit, remove.estimates = c("e17age", "e42dep"))

Run the code above in your browser using DataLab