Skip to contents

Returns raw / standardised / externally studentised residuals along with normality, heteroskedasticity (Breusch-Pagan), and autocorrelation (Durbin-Watson) tests. Optionally also returns deviance and Pearson residuals for logistic / Poisson GLMs.

Usage

compute_residuals(y, y_hat, X, model_type = "linear")

Arguments

y

Observed response.

y_hat

Fitted values.

X

Design matrix.

model_type

"linear", "logistic", or "poisson".

Value

A morie_residual_diagnostics list.

Examples

set.seed(1)
X <- cbind(1, matrix(rnorm(100 * 2), 100, 2))
y <- drop(X %*% c(0.5, 1, -0.5) + rnorm(100, sd = 0.5))
y_hat <- drop(X %*% solve(crossprod(X), crossprod(X, y)))
r <- compute_residuals(y, y_hat, X)
head(r$standardized_residuals)
#> [1]  0.3525897  1.6008833  1.4886868 -0.3727842 -2.2715227  2.5498705