Skip to contents

Rao-Scott design-based ANOVA for survey_glm() fits. Accepts three input shapes on object:

Usage

get_anova(
  object,
  formula = NULL,
  response = NULL,
  predictors = NULL,
  ...,
  method = c("LRT", "Wald"),
  test = c("F", "Chisq"),
  null = NULL,
  tolerance = sqrt(.Machine$double.eps),
  decimals = NULL,
  label_vars = TRUE,
  name_style = "surveycore"
)

Arguments

object

A survey_glm_fit, a list of survey_glm_fit objects, or a survey design (survey_base subclass).

formula

A model formula (e.g. y ~ x1 + x2). Only used when object is a survey design. Passed through to survey_glm(); supplying formula alongside response / predictors is rejected by survey_glm()'s validator.

response

Character string naming the outcome variable. Only used when object is a survey design. Forwarded to survey_glm().

predictors

Character vector of predictor variable names. Only used when object is a survey design. Forwarded to survey_glm().

...

Additional arguments forwarded to survey_glm() when object is a survey design (e.g. family, na.action, quiet). For fit or list inputs, ... must be empty — any extras error via rlang::check_dots_empty() with fuzzy typo detection.

method

Character(1). "LRT" (default) or "Wald".

test

Character(1). "F" (default) or "Chisq" reference distribution.

null

Numeric or NULL. Hypothesized value for the tested coefficients (Wald only). Only used when object is a single survey_glm_fit or a survey design (reducing to single-model mode); ignored with warning surveycore_warning_anova_null_ignored when object is a list of fits.

tolerance

Numeric(1). Reciprocal-condition-number threshold for the naive-covariance near-singular gate in the Rao-Scott LRT. Default sqrt(.Machine$double.eps).

decimals

Integer(1) or NULL. Round double output columns.

label_vars

Logical(1). When TRUE, compose term-row labels from @metadata@variable_labels for the term column. Default TRUE.

name_style

Character(1). "surveycore" (default) or "broom".

Value

A survey_anova tibble with columns term, statistic, df, ddf, deff, p_value, stars and a .meta attribute.

Details

  • A single survey_glm_fit — sequential mode, one row per term.

  • A list of survey_glm_fit objects — chained pairwise comparison, producing length(object) - 1 rows.

  • A survey design (any survey_base subclass) — fits the model internally via survey_glm() using formula (or response + predictors), then runs sequential anova on the fit.

Supports the four method x test combinations shared with survey::anova.svyglm(): Rao-Scott working-LRT with F or Chisq reference, and design-based Wald with F or Chisq reference.

Examples

gss_cc <- gss_2024[
  stats::complete.cases(gss_2024[, c("age", "sex", "educ")]),
]
gss_design <- as_survey(
  gss_cc, ids = vpsu, weights = wtssps,
  strata = vstrat, nest = TRUE
)

# Single fit
fit <- survey_glm(gss_design, age ~ sex + educ)
get_anova(fit)
#> # A tibble: 2 × 7
#>   term  statistic    df   ddf  deff p_value stars
#>   <chr>     <dbl> <dbl> <dbl> <dbl>   <dbl> <chr>
#> 1 sex        52.2     1    66  734.  0.784  ""   
#> 2 educ     4521.      1    65  700.  0.0141 "*"  

# Design + formula (fits internally)
get_anova(gss_design, age ~ sex + educ)
#> # A tibble: 2 × 7
#>   term  statistic    df   ddf  deff p_value stars
#>   <chr>     <dbl> <dbl> <dbl> <dbl>   <dbl> <chr>
#> 1 sex        52.2     1    66  734.  0.784  ""   
#> 2 educ     4521.      1    65  700.  0.0141 "*"  

# List of fits (chained pairwise comparison)
fit_s <- survey_glm(gss_design, age ~ sex)
fit_b <- survey_glm(gss_design, age ~ sex + educ)
get_anova(list(fit_s, fit_b))
#> # A tibble: 1 × 7
#>   term       statistic    df   ddf  deff p_value stars
#>   <chr>          <dbl> <dbl> <dbl> <dbl>   <dbl> <chr>
#> 1 educ | sex     4521.     1    65  700.  0.0141 *