R/wald-test.R
fastglm_wald_test.RdTests specified linear combinations of regression coefficients in a fitted model. A factor or interaction can be tested as a complete formula term, and a named contrast can compare coefficients without refitting.
fastglm_wald_test(
object,
terms = NULL,
contrast = NULL,
null = 0,
vcov. = NULL,
component = "all"
)a fastglm GLM (including negative-binomial and streaming GLMs), ordinal, truncated-count, hurdle, zero-inflated, or two-part fit.
formula terms, or coefficient names for a matrix fit, to test
jointly. The default selects all formula terms or all matrix coefficients
except a coefficient named (Intercept). For ordinal models it selects
location slopes. A nonparallel ordinal term includes its slopes at all
thresholds. Formula terms refer to their fitted design columns;
a main-effect test with interactions depends on their coding and reference
values and is not a test of every effect involving that variable.
For two-component models, names select complete terms in the selected
component(s), or unprefixed coefficient names for matrix fits. With
component="all", each term is tested wherever it occurs. A term must
occur in at least one selected component.
numeric vector or matrix specifying linear combinations.
Named columns may select a subset of coefficients in any order; omitted
columns have weight zero. Unnamed contrasts must follow coef(object).
Each matrix row specifies one hypothesis. Use either terms or contrast.
For two-component models, named contrasts use the count_ and zero_
prefixes returned by coef(object). A contrast spanning components requires
component="all"; its interpretation depends on their coefficient scales.
hypothesized value for each selected coefficient or contrast; a scalar is repeated across hypotheses. The default is zero.
optional coefficient covariance matrix, or a function of
object returning one. The default uses vcov(object). A named matrix
must contain all coefficient names; its order may differ. Robust or
cluster covariance can be supplied from fastglm_vcov().
"all" (default), "count", or "zero" for two-component
models. Two-part fits also accept "positive" for the positive-amount
component and "binary" for the positive-outcome probability. The zero
component describes the probability of a positive outcome for hurdle and
two-part fits, and structural-zero probability for zero-inflated fits.
Single-component and ordinal fits use "all".
A fastglm_wald_test inheriting from fastglm_test and htest,
with statistic, degrees of freedom, p-value, availability, contrast estimates,
standard errors, null values, and the contrast matrix and its covariance.
Print the object directly or use as.data.frame() for numeric extraction.
For contrast matrix L, coefficient estimate b, and covariance
V, the statistic is (L b - null)' solve(L V L', L b - null). Its
reference is chi-square with one degree of freedom per independent
contrast. This is a first-order approximation requiring asymptotically
normal, estimable coefficients and a consistent covariance for the sampling
design. It is not a finite-sample F test or a likelihood-ratio test.
Mean-bias-reduced estimates use the same first-order convention. Sparse
outcomes, extreme effects, and few independent clusters can make the
approximation inaccurate. Tests of regression coefficients do not assess
the common-slope restriction; use fastglm_po_test() for that hypothesis.
Nonconvergence, collapsed ordinal categories, nonestimable contrasts, and
missing or numerically singular contrast covariance return an unavailable
result with an explanation. Degrees of freedom are not reduced silently.
For aliased GLM coefficients, estimability is checked against the retained
dependence between design columns. No generalized inverse is used.
Tests concern regression coefficients, excluding dispersion or size
parameters. An estimated negative-binomial size at its numerical boundary
returns an unavailable result. Truncated, hurdle, and zero-inflated fits
use regression covariance accounting for estimated size in regular fits.
For fastglm_nb(), the default retains its conventional fixed-size GLM
covariance; to use joint observed information, supply the regression block
of vcov(object, full=TRUE). Supplied covariance must contain all regression coefficients,
including both components when applicable, even for a selected-component test.
Cross-component covariance is retained; it is not replaced with independent
component calculations. The covariance restrictions of fastglm_vcov()
continue to apply, including its restriction on adjusted two-part fits.
fit <- fastglm_ordinal(Sat ~ Infl + Type + Cont, MASS::housing,
weights=Freq, firth=TRUE)
fastglm_wald_test(fit, terms="Type")
#> Joint Wald test
#> Terms: Type
#> Estimation: mean bias reduction
#> Covariance: model-based
#>
#> Statistic df p-value
#> 54.2 3 < 1e-04
#>
#> Tested contrasts:
#> Estimate Std. Error Null
#> TypeApartment -0.5701 0.1187 0.0000
#> TypeAtrium -0.3650 0.1568 0.0000
#> TypeTerrace -1.0867 0.1515 0.0000
#>
#> Note: First-order chi-square approximation; validity depends on coefficient
#> estimability and the covariance assumptions.
fastglm_wald_test(fit, contrast=c(InflHigh=1, InflMedium=-1))
#> Joint Wald test
#> Estimation: mean bias reduction
#> Covariance: model-based
#>
#> Statistic df p-value
#> 33.82 1 < 1e-04
#>
#> Tested contrasts:
#> Estimate Std. Error Null
#> Contrast 1 0.7194 0.1237 0.0000
#>
#> Note: First-order chi-square approximation; validity depends on coefficient
#> estimability and the covariance assumptions.