Movatterモバイル変換


[0]ホーム

URL:


asympDiag

badge

TheasympDiag package provides tools for diagnosingstatistical regression models using Monte Carlo simulations. It helpsassess the adequacy of asymptotic approximations for Wald tests andverify residuals with envelopes. Most of the functions uses genericmethods from thestats package and are compatible withmodels fitted with the functionslm,glm,glm.nb,lmer andglmer. If yourmodel class is not compatible, you can still generate the diagnosticplots with theresponses andrefit_fnarguments.

Installation

You can install the development version of asympDiag fromGitHub with:

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

Example

Below is an example usingenvelope() to create aresidual diagnostic plot based on Monte Carlo simulations.

library(asympDiag)# Example datacounts<-c(18,17,15,20,10,20,25,13,12)outcome<-gl(3,1,9)treatment<-gl(3,3)# Fitting a Poisson regression modelglm.D93<-glm(counts~ outcome+ treatment,family =poisson())# Creating an envelope plot for residual diagnosticsenvelope(glm.D93)
envelope

Theenvelope() function generates an envelope plot thatcompares observed residuals to those expected under the model, helpingto identify potential model misspecifications.

Next, after fitting a valid model, you can usesimulate_wald_pvalues() to generate p-values throughsimulation and check if the sample size is sufficient for the Waldtest’s asymptotic approximation:

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

The functionsimulate_wald_pvalues() provides adistribution of p-values from the Monte Carlo simulation, enabling adeeper assessment of whether the sample size supports reliable inferencebased on the Wald test.


[8]ページ先頭

©2009-2025 Movatter.jp