anova.glm_weightit: Methods for 'glm_weightit()' objects

View source: R/anova.glm_weightit.R

anova.glm_weightitR Documentation

Methods for glm_weightit() objects

Description

anova() is used to compare nested models fit with glm_weightit(), mutinom_weightit(), ordinal_weightit(), or coxph_weightit() using a Wald test that incorporates uncertainty in estimating the weights (if any).

Usage

## S3 method for class 'glm_weightit'
anova(
  object,
  object2,
  test = "Chisq",
  method = "Wald",
  tolerance = 1e-07,
  vcov = NULL,
  ...
)

Arguments

object, object2

an output from one of the above modeling functions. object2 is required.

test

the type of test statistic used to compare models. Currently only "Chisq" (the chi-square statistic) is allowed.

method

the kind of test used to compare models. Currently only "Wald" is allowed.

tolerance

for the Wald test, the tolerance used to determine if models are symbolically nested.

vcov

either a string indicating the method used to compute the variance of the estimated parameters for object, a function used to extract the variance, or the variance matrix itself. Default is to use the variance matrix already present in object. If a string or function, arguments passed to ... are supplied to the method or function. (Note: for vcov(), can also be supplied as type.)

...

other arguments passed to the function used for computing the parameter variance matrix, if supplied as a string or function, e.g., cluster, R, or fwb.args.

Details

anova() performs a Wald test to compare two fitted models. The models must be nested, but they don't have to be nested symbolically (i.e., the names of the coefficients of the smaller model do not have to be a subset of the names of the coefficients of the larger model). The larger model must be supplied to object and the smaller to object2. Both models must contain the same units, weights (if any), and outcomes. The variance-covariance matrix of the coefficients of the smaller model is not used.

Value

An object of class "anova" inheriting from class "data.frame".

See Also

glm_weightit() for the page documenting glm_weightit(), lm_weightit(), ordinal_weightit(), multinom_weightit(), and coxph_weightit(). anova.glm() for model comparison of glm objects.

Examples

data("lalonde", package = "cobalt")

# Model comparison for any relationship between `treat`
# and `re78` (not the same as testing for the ATE)
fit1 <- glm_weightit(
  re78 ~ treat * (age + educ + race + married + nodegree +
                    re74 + re75), data = lalonde
)

fit2 <- glm_weightit(
  re78 ~ age + educ + race + married + nodegree +
    re74 + re75, data = lalonde
)

anova(fit1, fit2)

# Using the usual maximum likelihood variance matrix
anova(fit1, fit2, vcov = "const")

# Using a bootstrapped variance matrix
anova(fit1, fit2, vcov = "BS", R = 100)


# Model comparison between spline model and linear
# model; note they are nested but not symbolically
# nested
fit_s <- glm_weightit(
  re78 ~ splines::ns(age, df = 4), data = lalonde
)

fit_l <- glm_weightit(
  re78 ~ age, data = lalonde
)

anova(fit_s, fit_l)


WeightIt documentation built on Oct. 4, 2024, 9:07 a.m.