Learn R Programming

asympDiag

The asympDiag package provides tools for diagnosing statistical regression models using Monte Carlo simulations. It helps assess the adequacy of asymptotic approximations for Wald tests and verify residuals with envelopes. Most of the functions uses generic methods from the stats package and are compatible with models fitted with the functions lm, glm, glm.nb, lmer and glmer. If your model class is not compatible, you can still generate the diagnostic plots with the responses and refit_fn arguments.

Installation

You can install the development version of asympDiag from GitHub with:

# install.packages("devtools")
devtools::install_github("Alvaro-Kothe/asympDiag")

Example

Below is an example using envelope() to create a residual diagnostic plot based on Monte Carlo simulations.

library(asympDiag)

# Example data
counts <- c(18, 17, 15, 20, 10, 20, 25, 13, 12)
outcome <- gl(3, 1, 9)
treatment <- gl(3, 3)

# Fitting a Poisson regression model
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())

# Creating an envelope plot for residual diagnostics
envelope(glm.D93)

The envelope() function generates an envelope plot that compares observed residuals to those expected under the model, helping to identify potential model misspecifications.

Next, after fitting a valid model, you can use simulate_wald_pvalues() to generate p-values through simulation and check if the sample size is sufficient for the Wald test's asymptotic approximation:

# Simulating p-values to assess asymptotic approximation validity
simulate_wald_pvalues(glm.D93, nsim = 10000)

The function simulate_wald_pvalues() provides a distribution of p-values from the Monte Carlo simulation, enabling a deeper assessment of whether the sample size supports reliable inference based on the Wald test.

Copy Link

Version

Install

install.packages('asympDiag')

Monthly Downloads

187

Version

0.3.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Álvaro Kothe

Last Published

March 27th, 2025

Functions in asympDiag (0.3.1)

get_model_response

Extract the Response Variable from a Model Object
get_fixef

Get fixed effects
envelope

Generate Simulated Envelope
envelope_residual

Recommended Residuals for Envelope Plots
get_refit

Refit the Model
plot.AD_envelope

Envelope Plot
concat_pvalues

Concatenate AD_pvalues object
get_converged

Did the model converged
parametric_bootstrap

Perform Parametric Bootstrap Simulations
get_vcov

Get covariance matrix
plot_cook

Plot Cook's distances
plot.AD_pvalues

Plot Empirical Cumulative Distribution Function (ECDF) of p-values
refit_model

Refit Model
plot_ecdf_pvalue

Plot Empirical Cumulative Distribution Function (ECDF) of p-values
simulate_wald_pvalues

Generate Wald test P-Values with Monte Carlo Simulations
select_covariates

Select covariates
plot_res_vs_linear_predictor

Plot Residuals against Linear Predictor