View source: R/plot_model_check.R
plot_model_check | R Documentation |
Function provides multi-plots to check model assumptions of heteroscedasticity, normally distributed residuals and leverage of each datum.
Function plots fitted values versus residuals, fitted values versus response values, a QQ plot of the standardized residuals, and histogram of residual values.
For the QQ plot only standardized residuals are computed without taking the square root of the absolute value.
plot_model_check(
fitted_v,
response_v,
residual_v,
id_v = NULL,
residual_label_threshold = NULL,
label_color = "red",
label_sd = NULL,
title = NULL,
axis_text_size = 11,
pts_color = "black",
pts_fill = "white",
pts_alpha = 1,
pts_size = 1,
histo_fill = "white",
histo_alpha = 1,
ref_line_color = "red",
trend_line = TRUE,
trend_line_color = "red"
)
fitted_v |
A required numeric vector of fitted values. |
response_v |
A required numeric vector of observed response/dependent values. |
residual_v |
A required numeric vector of corresponding residual values. |
id_v |
An optional numeric/string vector that labels the fit/residual pairs. If this argument is |
residual_label_threshold |
A numeric that sets the residual threshold beyond which observations will be labeled with their id. |
label_color |
A string that sets the label/point color for observations whose absolute residual is greater than the 'label_threshold'. |
label_sd |
A numeric that sets the number times +/- residual standard deviations to plot as a pair of horizontal dotted lines. Typical values could be 1 or 2 standard deviations. |
title |
A string that sets the plot title. |
axis_text_size |
A numeric that sets the font size along the axis'. Default is 11. |
pts_color |
A string that sets the color of the points. |
pts_fill |
A string that sets the fill color of the points. |
pts_alpha |
A numeric value that sets the alpha level of 'pts_color'. |
pts_size |
A numeric value that sets the size of the points. |
histo_fill |
A string that sets the histogram fill color. |
histo_alpha |
A numeric that sets the histogram fill alpha. |
ref_line_color |
A string that sets the reference lines color. |
trend_line |
A logical which if |
trend_line_color |
A string that sets the color of the trend line. |
A multi-paneled ggplot2 object with various plots for checking linear model assumptions.
library(data.table)
library(ggplot2)
library(gtable)
library(ggplotify)
library(RplotterPkg)
library(RregressPkg)
sample_size = 500
x <- runif(n = sample_size) * 5
y <- 3 + 5 * x^2 + rnorm(n = sample_size, mean = 0, sd = 5)
sim_df <- data.frame(x,y)
fit_lm <- lm(y ~ x, data = sim_df)
sim_ols <- RregressPkg::ols_calc(
df = sim_df,
formula_obj = fit_lm
)
a_plot <- RregressPkg::plot_model_check(
fitted_v = sim_ols$fitted_vals,
response_v = sim_df$y,
residual_v = sim_ols$residual_vals,
histo_fill = "blue",
histo_alpha = 0.5,
ref_line_color = "darkorange"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.