pm_check: Checks of a Fitted Model

View source: R/pm_check.R

pm_checkR Documentation

Checks of a Fitted Model

Description

A table of checks of a model's assumptions and structure, grouped in sections, with a plain note on each: the fit itself (singular or not converged); the residuals (outliers, influence, normality, a transformation); the variance (equal across factor levels, constant with the fitted values); the distribution of generalized models (over- and underdispersion, excess zeros, separation); the design (balance and empty cells, aliasing, collinearity, few levels of a random effect); and the terms (interactions, straight lines). For any model that predictmeans handles.

Usage

pm_check(model, plot = FALSE)

Arguments

model

A fitted model, as for residplot.

plot

TRUE: also draw the diagnostic plots of residplot.

Details

The checks inform; they do not decide. Rows marked ! are worth a look at the plots of residplot; rows marked i are information. Keep the terms the design calls for (blocks, whole plots, the treatment structure): dropping a term because its test is not significant makes the later tests and intervals too optimistic. Tests of normality and of equal variances reject small departures in large data sets and miss large ones in small data sets; the plots say how large a departure is.

Fit

singular fits (a variance component estimated as zero) and convergence warnings.

Outliers

residuals beyond 3 (of the residuals residplot uses: standardized, normalized or randomized quantile), against the number expected for normal residuals; worth a look when that many, or one as large as the largest (Bonferroni over the observations), has probability below 0.01.

Influence

(lm, aov, glm) the largest Cook's distance; above 0.5 is worth a look (CookD for mixed models).

Normality

Shapiro-Wilk tests of the residuals and of each term's random effects (intercepts).

Transformation of the response

(lm and aov with a positive response that is not transformed in the formula) the Box-Cox power the residuals favour: the profile likelihood estimate of \lambda and its 95% interval (Box and Cox, 1964; as MASS::boxcox()). Worth a look when the interval leaves out 1 (no transformation); the note names the usual transformation within the interval.

Equal variances

for each factor: the ratio of the largest to the smallest standard deviation of the residuals within its levels, and the Brown-Forsythe test (ANOVA of the absolute deviations from the medians).

Spread vs fitted values

(gaussian models) Spearman correlation of the absolute residuals with the fitted values; worth a look when |\rho| \ge 0.2 and p < 0.01 (the variance grows with the mean).

Dispersion

(Poisson, binomial with more than one trial, negative binomial; glm, glmer, glmmTMB) Pearson chi-square / residual df, about 1 when the variance function is right; overdispersion (ratio > 1.5, p < 0.01) makes SEs too small, underdispersion (ratio < 0.7, p < 0.01) too large. For mixed models the residual df counts the variance parameters, an approximation. A 0/1 response carries no information on dispersion; for families with an estimated dispersion (Gamma, quasi) its estimate is shown.

Zero counts

(Poisson, negative binomial) the observed zeros against those simulated from the fitted model (200 simulations, fixed seed; the user's random numbers are not changed); worth a look when there are more (p < 0.01).

Separation

(binomial) fitted probabilities of 0 or 1, or coefficients beyond 10 on the logit scale or with standard errors above 50: the estimates and Wald tests of these terms are unreliable.

Balance of cells

of the crossed fixed factors: balanced, unbalanced or with empty cells; unbalanced data make Type I, II and III tests differ (see anova.lmerMod, section 'Which type of test').

Estimability

coefficients dropped as aliased (empty cells or confounded factors).

Collinearity

(models of main effects only) the generalized variance inflation factor of each term, GVIF^{1/(2 df)} (Fox and Monette, 1992); above \sqrt{10} is worth a look.

Random-effect levels

a grouping factor with fewer than 5 levels: its variance is poorly estimated.

Interaction

the Type III test of each interaction term (as permmodels(type = "III")).

Straight line

for a factor with numeric levels and at least three of them: the joint test of the polynomial contrasts above the linear one (with the actual spacing of the levels), from pm_joint.

Value

A data frame of class "pm_check": section, check, result, p.value, look, status ("!" worth a look, "i" information, "OK") and note; printed by section with the notes below. summary() keeps only the rows worth a look. The rows worth a look are also kept as advice (advice).

Author(s)

Dongwen Luo, Siva Ganesh and John Koolaard

References

Fox, J. and Monette, G. (1992). Generalized collinearity diagnostics. Journal of the American Statistical Association, 87, 178-183.

See Also

residplot, CookD, advice, pm_boxcox

Examples

library(predictmeans)
Oats$nitro <- factor(Oats$nitro)
fm <- lmer(yield ~ nitro*Variety + (1|Block/Variety), data = Oats)
pm_check(fm)

# counts: overdispersion
gm <- glm(breaks ~ wool * tension, family = poisson, data = warpbreaks)
pm_check(gm)
summary(pm_check(gm))

predictmeans documentation built on Nov. 24, 2026, 5:10 p.m.