r_squared_vis: Regression Sum of Squared Visualization

View source: R/r_squared_vis.R

r_squared_visR Documentation

Regression Sum of Squared Visualization

Description

Regression Sum of Squared Visualization

Usage

r_squared_vis(
  df,
  formu,
  x_lab = "Observed Value",
  y_lab = "Predicted Value",
  plot_total_variance = TRUE,
  plot_all_variances = TRUE,
  plot_error_variance = FALSE,
  plot_regression_variance = FALSE,
  plot_unit_line = TRUE,
  plot_points = TRUE,
  plot_means = TRUE,
  plot_residuals = FALSE,
  plot_residuals_squared = FALSE,
  variance_alpha = 0.2,
  total_variance_color = "#999999",
  error_variance_color = "#ff7f00",
  regression_variance_color = "#377eb8",
  point_color = "grey50",
  point_alpha = 0.5
)

Arguments

df

data.frame with the data to plot.

formu

formula for the regression.

x_lab

label for the x-axis.

y_lab

label for the y-axis.

plot_total_variance

plot a square representing the total variance in the dependent variable.

plot_all_variances

plot a squares representing all the variances (i.e. each predictor and error).

plot_error_variance

plot a square representing the error/residual variance.

plot_regression_variance

plot a square representing the total regression variance.

plot_unit_line

plot the unit line (i.e. y = x).

plot_points

plot the data points.

plot_means

plot horizontal and vertical lines for the means.

plot_residuals

plot vertical lines representing the residuals.

plot_residuals_squared

plot squares representing the squared residuals.

variance_alpha

the alpha level (transparency) of the residual squares.

total_variance_color

color representing the total variance.

error_variance_color

color representing the error variance.

regression_variance_color

color representing variance explained (i.e. regression variance).

point_color

color of the data points.

point_alpha

the alpha level (transparency) of the data points.

Value

a ggplot2 expression.

Examples

df <- VisualStats::simulate(n = 100, r_squared = .5)
formu <- y ~ x1 + x2
lm(formu, df) |> summary()
VisualStats::r_squared_vis(df, formu,
						   plot_total_variance = TRUE,
						   plot_error_variance = FALSE,
						   plot_all_variances = TRUE,
						   plot_residuals_squared = FALSE,
						   plot_residuals = FALSE)

jbryer/VisualStats documentation built on Feb. 27, 2025, 6:19 p.m.