The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

Type: Package
Title: Survey-Weighted Modeling Utilities
Version: 0.1.0
Description: Utility functions for survey-weighted regression, diagnostics, and visualization.
License: MIT + file LICENSE
Encoding: UTF-8
Imports: stats, survey, nnet, ggplot2
RoxygenNote: 7.3.3
Config/build/vignettes: false
VignetteBuilder: knitr
Suggests: knitr, rmarkdown, testthat (≥ 3.0.0)
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-02-25 19:43:27 UTC; shakahme
Author: Shakeel Ahmed [aut, cre]
Maintainer: Shakeel Ahmed <shakeelatish05@gmail.com>
Repository: CRAN
Date/Publication: 2026-03-03 11:10:02 UTC

Prognostic-weighted survey GLM Prognostic-weighted survey GLM

Description

Fits a survey-weighted logistic regression model using stabilized prognostic score weights derived from a model predicting the outcome conditional on baseline covariates and excluding the exposure effect. The function supports design-based inference under complex survey sampling while adjusting for confounding through prognostic weighting

Usage

final_prog_svyglm(
  data,
  dep_var,
  exposure,
  covariates,
  id_var,
  strata_var,
  weight_var,
  outcome_covariates = NULL,
  level = 0.95,
  ...
)

Arguments

data

Data frame

dep_var

Character; binary outcome

exposure

Character; exposure variable

covariates

Character vector; adjustment variables

id_var

Character; PSU

strata_var

Character; strata

weight_var

Character; survey weight

outcome_covariates

Character vector; optional covariates for final model

level

Numeric; CI level

...

Additional args to svyglm

Value

A list with:

Examples

set.seed(123)
n <- 1000
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<-final_prog_svyglm(data = dat,
 dep_var = "outcome",
 exposure="exposure",
 covariates = c("age", "sex"),
 id_var = "psu",
 strata_var = "strata",
 weight_var = "weight",
 level = 0.95
)
names(fit)
fit$OR_table

Propensity-weighted survey GLM

Description

Calculates IPTW weights and fits survey-weighted GLM. Supports binary, multinomial, or continuous exposures.

Usage

final_prop_svyglm(
  data,
  dep_var,
  covariates,
  exposure,
  id_var,
  strata_var,
  weight_var,
  exposure_type = "binary",
  outcome_covariates = NULL,
  level = 0.95,
  ...
)

Arguments

data

Data frame

dep_var

Character; binary outcome

covariates

Character vector; adjustment variables

exposure

Character; treatment/exposure variable

id_var

Character; PSU

strata_var

Character; strata

weight_var

Character; base weight

exposure_type

Character; "binary", "multinomial", "continuous"

outcome_covariates

Character vector of additional covariates to include in the final outcome model after applying propensity weights (default = NULL)

level

Numeric; confidence interval level

...

Additional args to svyglm

Value

A list with:

Examples

set.seed(123)
n <- 1500
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_bin = rbinom(n, 1, 0.5)
)
dat$outcome <- rbinom(n, 1, plogis(-2 + 0.03*dat$age + 0.5*dat$exposure_bin))
## ---- Example 1: Binary exposure ----
fit_bin_exp<-final_prop_svyglm(dat, dep_var="outcome",
                  covariates=c("age","sex"),
                  exposure="exposure_bin",
                  id_var="psu", strata_var="strata",
                  weight_var="weight", outcome_covariates = NULL)
fit_bin_exp$OR_table
## ---- Example 2: Continuous exposure ----
fit_cont_exp <- final_prop_svyglm(
  dat,
  dep_var     = "outcome",
  covariates  = c("sex"),
  exposure    = "age",
  id_var      = "psu",
  strata_var  = "strata",
  weight_var  = "weight",
 exposure_type = "continuous",
 outcome_covariates = NULL)
fit_cont_exp$OR_table
#### ---- Example 1: Multinomial exposure ----
dat$exposure_3cat <- cut(dat$age,
breaks = quantile(dat$age, probs = c(0, 1/3, 2/3, 1)),  # tertiles
 labels = c("Low", "Medium", "High"),
include.lowest = TRUE)
# Numeric coding for exposure effect
exp_eff <- ifelse(dat$exposure_3cat == "Low", 0,
                ifelse(dat$exposure_3cat == "Medium", 0.6, 1.2))
dat$outcome <- rbinom(n,1,plogis(-3 +0.02 * dat$age +0.4  * (dat$sex == "Male") +exp_eff))
fit_multi_cat <- final_prop_svyglm(dat, dep_var     = "outcome",
covariates  = c("age", "sex"), exposure    = "exposure_3cat",
id_var      = "psu", strata_var  = "strata", weight_var  = "weight",
exposure_type = "multinomial",
outcome_covariates = NULL)
fit_multi_cat$OR_table

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:

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

Print method for svyCausal objects

Description

Print method for svyCausal objects

Usage

## S3 method for class 'svyCausal'
print(x, ...)

Arguments

x

An object of class svyCausal.

...

Additional arguments passed to print.

Value

The object x, invisibly.


Weighted ROC Curve for Survey-Weighted Models

Description

Produces a weighted ROC curve and reports weighted AUC for survey-based models.

Usage

viz_auc_svyglm(
  fit_object,
  title = "Weighted ROC Curve",
  line_color = "#0072B2"
)

Arguments

fit_object

object obtain from logistic regression

title

Character. Plot title.

line_color

Character. ROC curve color.

Details

AUC is computed using, consistent with complex survey weighting.

Value

A ggplot 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_example<-final_svyglm(dat, dep_var="outcome", covariates=c("age","sex"),
             id_var="psu", strata_var="strata", weight_var="weight")
viz_auc_svyglm(fit_object=fit_example)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.