Learn R Programming

asympDiag (version 0.3.1)

plot_res_vs_linear_predictor: Plot Residuals against Linear Predictor

Description

Plot Residuals against Linear Predictor

Usage

plot_res_vs_linear_predictor(
  model,
  residual_fn = stats::rstandard,
  xlab = "Linear Predictor",
  ylab = "Standardized deviance residuals",
  ...
)

Value

An invisible list containing the linear predictor (x) and standardized deviance residuals (y).

Arguments

model

Model with methods predict() or fitted()

residual_fn

A function to calculate model residuals. The default is stats::rstandard.

xlab

The label for the x-axis. Defaults to "Linear Predictor".

ylab

The label for the y-axis. Defaults to "Standardized deviance residuals".

...

Extra arguments to residual_fn and plot().

Details

If the model was fitted using the glm() function, it will use the predict() method with type = link, otherwise, it will use the fitted() method.

Examples

Run this code
fit <- lm(mpg ~ cyl, data = mtcars)

plot_res_vs_linear_predictor(fit)
plot_res_vs_linear_predictor(fit, residual_fn = rstudent)
plot_res_vs_linear_predictor(fit, residual_fn = residuals)


glm_fit <- glm(cyl ~ mpg, family = poisson(), data = mtcars)

plot_res_vs_linear_predictor(glm_fit)
plot_res_vs_linear_predictor(glm_fit, type = "pearson")

Run the code above in your browser using DataLab