| Title: | Comprehensive Diagnostics for Statistical Models |
|---|---|
| Description: | Provides a unified framework for diagnosing common issues in statistical models including linear models, generalized linear models (logistic and Poisson regression), and survival models. Implements tests for multicollinearity, heteroscedasticity, autocorrelation, normality, influential observations, overdispersion, zero-inflation, and proportional hazards assumptions. Includes visualization methods for graphical diagnostics. Methods are based on established approaches including Fox and Monette (1992) <doi:10.1080/01621459.1992.10475190>, Breusch and Pagan (1979) <doi:10.2307/1911963>, and Dean and Lawless (1989) <doi:10.1080/01621459.1989.10478792>. |
| Authors: | Emmanuel Adewuyi [aut, cre], Adewale Lukman [aut], Abiola Owolabi [ctb] |
| Maintainer: | Emmanuel Adewuyi <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-28 18:20:48 UTC |
| Source: | https://github.com/cran/modeldiag |
Performs Breusch-Pagan test for heteroskedasticity.
check_heteroskedasticity(model)check_heteroskedasticity(model)
model |
A fitted lm object. |
An htest object or NA if computation fails.
Computes variance inflation factors to detect multicollinearity.
check_vif(model)check_vif(model)
model |
A fitted model object. |
A numeric vector of VIF values or NA if computation fails.
This is a generic function for performing diagnostic checks on statistical models. It dispatches to specific methods based on the model type.
## S3 method for class 'glm' diagnose_model(model, ...) ## S3 method for class 'lm' diagnose_model(model, ...) ## S3 method for class 'coxph' diagnose_model(model, ...) diagnose_model(model, ...)## S3 method for class 'glm' diagnose_model(model, ...) ## S3 method for class 'lm' diagnose_model(model, ...) ## S3 method for class 'coxph' diagnose_model(model, ...) diagnose_model(model, ...)
model |
A fitted model object. |
... |
Additional arguments passed to specific methods. |
An object of class "model_diagnostics" containing the results of various diagnostic tests.
# Linear model diagnostics model_lm <- lm(mpg ~ wt + hp, data = mtcars) diag_lm <- diagnose_model(model_lm) summary(diag_lm) plot(diag_lm) # Logistic regression diagnostics model_glm <- glm(am ~ wt + hp, data = mtcars, family = binomial) diag_glm <- diagnose_model(model_glm) summary(diag_glm) # Poisson regression diagnostics model_pois <- glm(carb ~ wt + hp, data = mtcars, family = poisson) diag_pois <- diagnose_model(model_pois) summary(diag_pois) # Cox proportional hazards diagnostics library(survival) data(lung) model_cox <- coxph(Surv(time, status) ~ age + sex + ph.ecog, data = lung) diag_cox <- diagnose_model(model_cox) summary(diag_cox)# Linear model diagnostics model_lm <- lm(mpg ~ wt + hp, data = mtcars) diag_lm <- diagnose_model(model_lm) summary(diag_lm) plot(diag_lm) # Logistic regression diagnostics model_glm <- glm(am ~ wt + hp, data = mtcars, family = binomial) diag_glm <- diagnose_model(model_glm) summary(diag_glm) # Poisson regression diagnostics model_pois <- glm(carb ~ wt + hp, data = mtcars, family = poisson) diag_pois <- diagnose_model(model_pois) summary(diag_pois) # Cox proportional hazards diagnostics library(survival) data(lung) model_cox <- coxph(Surv(time, status) ~ age + sex + ph.ecog, data = lung) diag_cox <- diagnose_model(model_cox) summary(diag_cox)
Generates diagnostic plots for the fitted model.
## S3 method for class 'model_diagnostics' plot(x, ...)## S3 method for class 'model_diagnostics' plot(x, ...)
x |
An object of class "model_diagnostics". |
... |
Additional arguments passed to plotting functions. |
None (plots are displayed).
Prints a summary of the model diagnostics object.
## S3 method for class 'model_diagnostics' print(x, ...)## S3 method for class 'model_diagnostics' print(x, ...)
x |
An object of class "model_diagnostics". |
... |
Additional arguments passed to print. |
The object x, invisibly.
Provides a detailed summary of diagnostic test results.
## S3 method for class 'model_diagnostics' summary(object, ...)## S3 method for class 'model_diagnostics' summary(object, ...)
object |
An object of class "model_diagnostics". |
... |
Additional arguments (currently ignored). |
The object, invisibly.