final_svyglm: Final Survey-Weighted GLM

View source: R/final_svyglm.R

final_svyglmR Documentation

Final Survey-Weighted GLM

Description

Fits a survey-weighted logistic regression model (quasibinomial) using raw survey variables. Returns ORs, confidence intervals, p-values, and model discrimination statistics.

Usage

final_svyglm(
  data,
  dep_var,
  covariates,
  id_var,
  strata_var,
  weight_var,
  family = "binomial",
  level = 0.95,
  interaction_terms = NULL
)

Arguments

data

A data frame containing the survey data.

dep_var

Character. Name of the binary outcome variable (0/1).

covariates

Character vector of covariate names to adjust for.

id_var

Character. Name of the primary sampling unit variable.

strata_var

Character. Name of the stratification variable.

weight_var

Character. Name of the survey weight variable.

family

Character. Currently supports only "binomial".

level

Numeric. Confidence level for intervals (default = 0.95).

interaction_terms

Optional character vector of interaction terms.

Value

A list containing:

  • model: Survey-weighted logistic regression model.

  • results_table: Odds ratios with confidence intervals and p-values.

  • AUC: Survey-weighted AUC (Somers' C).

  • data: Input data with predicted probabilities.

  • design: Survey design object.

Examples

set.seed(123)
n <- 100
dat <- data.frame(
  psu = sample(1:10, n, replace = TRUE),
  strata = sample(1:5, n, replace = TRUE),
  weight = runif(n, 0.5, 2),
  age = rnorm(n, 50, 10),
  sex = factor(sample(c("Male", "Female"), n, replace = TRUE)),
  exposure = rbinom(n, 1, 0.5)
)
dat$outcome <- rbinom(n, 1, plogis(-2 + 0.03*dat$age + 0.5*dat$exposure))
fit_simple<-final_svyglm(dat, dep_var="outcome", covariates=c("age","sex"),
             id_var="psu", strata_var="strata", weight_var="weight")
fit_simple$OR_table

svyCausalGLM documentation built on March 3, 2026, 5:08 p.m.