plot_linear_assumption_check: Visual plot to check the assumption that the predicted values...

View source: R/plot_linear_assumption_check.R

plot_linear_assumption_checkR Documentation

Visual plot to check the assumption that the predicted values are linearly related to the predictors.

Description

Visual plot to check the assumption that the predicted values are linearly related to the predictors.

Usage

plot_linear_assumption_check(
  glm_out,
  n_groups,
  vars = get_numeric_vars(glm_out),
  na.rm = TRUE,
  x_lab = "Predicted Probabilities",
  y_lab = all.vars(glm_out$formula)[1],
  x_limits = c(0, 1),
  coord_equal = TRUE,
  coord_flip = FALSE,
  widths = NULL,
  legend.position = "bottom",
  varplot_nrow = NULL,
  varplot_ncol = NULL
)

Arguments

glm_out

the results of the logistic regression (i.e. the result from glm).

n_groups

the number of groups to use. By default groups will have a minimum of six observations up to a maximum of 10 groups.

vars

character vector with the name of the independent variables to include. If omitted, all numeric variables will be used.

na.rm

whether missing values should be removed.

x_lab

label for the x-axis.

y_lab

label for the y-axis.

x_limits

limits for the x-axis.

coord_equal

whether the x- and y-axes should be equal.

coord_flip

whether the x- and y-axes should be flipped.

widths

the relative widths of the two plots. If you only want the first plot, use widths = c(0, 1); if only the second plot, use widths = c(1, 0).

legend.position

location of the legend.

varplot_nrow

parameter passed to ggplot2::facet_wrap().

varplot_ncol

parameter passed to ggplot2::facet_wrap().

Value

a ggplot2 expression.

Examples

study <- data.frame(
    Hours=c(0.50,0.75,1.00,1.25,1.50,1.75,1.75,2.00,2.25,2.50,2.75,3.00,
		       3.25,3.50,4.00,4.25,4.50,4.75,5.00,5.50),
    Pass=c(0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1)
)
lr.out <- glm(Pass ~ Hours, data = study,
			  family = binomial(link='logit'))
plot_linear_assumption_check(glm_out = lr.out, n_groups = 5)

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