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.

plot_residuals(
fit,
geom.size = 2,
remove.estimates = NULL,
show.lines = TRUE,
show.resid = TRUE,
show.pred = TRUE,
show.ci = FALSE
)

## Arguments

fit Fitted linear (mixed) regression model (including objects of class gls or plm). 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. Numeric vector with indices (order equals to row index of coef(fit)) or character vector with coefficient names that indicate which estimates should be removed from the table output. The first estimate is the intercept, followed by the model predictors. The intercept cannot be removed from the table output! remove.estimates = c(2:4) would remove the 2nd to the 4th estimate (1st to 3rd predictor after intercept) from the output. remove.estimates = "est_name" would remove the estimate est_name. Default is NULL, i.e. all estimates are printed. Logical, if TRUE, a line connecting predicted and residual values is plotted. Set this argument to FALSE, if plot-building is too time consuming. Logical, if TRUE, residual values are plotted. Logical, if TRUE, predicted values are plotted. Logical, if TRUE), adds notches to the box plot, which are used to compare groups; if the notches of two boxes do not overlap, medians are considered to be significantly different.

A ggplot-object.

## Note

The actual (observed) values have a coloured fill, while the predicted values have a solid outline without filling.

## Examples

data(efc)
# fit model
fit <- lm(neg_c_7 ~ c12hour + e17age + e42dep, data = efc)

# plot residuals for all independent variables
plot_residuals(fit)
#> geom_smooth() using formula 'y ~ x'

# remove some independent variables from output
plot_residuals(fit, remove.estimates = c("e17age", "e42dep"))
#> geom_smooth() using formula 'y ~ x'
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.6622797846794128, "perplexity": 4586.100175663686}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2021-43/segments/1634323583408.93/warc/CC-MAIN-20211016013436-20211016043436-00492.warc.gz"}