Learn R Programming

riskdiff (version 0.3.0)

calc_risk_diff_iptw: Calculate Standardized Risk Differences Using IPTW

Description

Calculates standardized risk differences using inverse probability of treatment weighting. This approach estimates causal effects under the assumption of no unmeasured confounding by creating a pseudo-population where treatment assignment is independent of measured confounders.

Usage

calc_risk_diff_iptw(
  data,
  outcome,
  treatment,
  covariates,
  nnt = FALSE,
  iptw_weights = NULL,
  weight_type = "ATE",
  ps_method = "logistic",
  stabilize = TRUE,
  trim_weights = TRUE,
  alpha = 0.05,
  bootstrap_ci = FALSE,
  boot_n = 1000,
  verbose = FALSE
)

Value

A tibble of class "riskdiff_iptw_result" containing:

treatment_var

Character. Name of treatment variable

rd_iptw

Numeric. IPTW-standardized risk difference OR Number Needed to Treat if nnt=TRUE

ci_lower

Numeric. Lower confidence interval bound (RD scale or NNT scale)

ci_upper

Numeric. Upper confidence interval bound (RD scale or NNT scale)

p_value

Numeric. P-value for test of null hypothesis

weight_type

Character. Type of weights used

effective_n

Numeric. Effective sample size

risk_treated

Numeric. Risk in treated group

risk_control

Numeric. Risk in control group

Arguments

data

A data frame containing outcome, treatment, and covariate data

outcome

Character string naming the binary outcome variable

treatment

Character string naming the binary treatment variable

covariates

Character vector of covariate names for propensity score model

nnt

Logical indicating whether to return Number Needed to Treat instead of risk difference (default: FALSE)

iptw_weights

Optional vector of pre-calculated IPTW weights

weight_type

Type of weights if calculating: "ATE", "ATT", or "ATC" (default: "ATE")

ps_method

Method for propensity score estimation (default: "logistic")

stabilize

Whether to use stabilized weights (default: TRUE)

trim_weights

Whether to trim extreme weights (default: TRUE)

alpha

Significance level for confidence intervals (default: 0.05)

bootstrap_ci

Whether to use bootstrap confidence intervals (default: FALSE)

boot_n

Number of bootstrap replicates if bootstrap_ci=TRUE (default: 1000)

verbose

Whether to print diagnostic information (default: FALSE)

Details

Causal Interpretation

IPTW estimates causal effects by weighting observations to create balance on measured confounders. The estimand depends on the weight type:

  • ATE: Average treatment effect in the population

  • ATT: Average treatment effect among those who received treatment

  • ATC: Average treatment effect among those who did not receive treatment

Standard Errors

By default, uses robust (sandwich) standard errors that account for propensity score estimation uncertainty. Bootstrap confidence intervals are available as an alternative that may perform better with small samples.

Assumptions

  1. No unmeasured confounding: All confounders are measured and included

  2. Positivity: All subjects have non-zero probability of receiving either treatment

  3. Correct model specification: Propensity score model is correctly specified

Number Needed to Treat (NNT)

When nnt = TRUE, results are transformed to causal Number Needed to Treat. This represents the number of individuals who need to receive treatment to prevent one additional adverse outcome in the target population (defined by weight_type). NNT calculations preserve the causal interpretation of IPTW estimates under the assumptions of exchangeability, positivity, and consistency.

Examples

Run this code
data(cachar_sample)

# Standard ATE estimation
rd_iptw <- calc_risk_diff_iptw(
  data = cachar_sample,
  outcome = "abnormal_screen",
  treatment = "areca_nut",
  covariates = c("age", "sex", "residence", "smoking")
)
print(rd_iptw)

# ATT estimation with bootstrap CI
rd_att <- calc_risk_diff_iptw(
  data = cachar_sample,
  outcome = "head_neck_abnormal",
  treatment = "tobacco_chewing",
  covariates = c("age", "sex", "residence", "areca_nut"),
  weight_type = "ATT",
  bootstrap_ci = TRUE,
  boot_n = 500
)
print(rd_att)

# Calculate causal NNT using IPTW
nnt_iptw <- calc_risk_diff_iptw(
  data = cachar_sample,
  outcome = "abnormal_screen",
  treatment = "areca_nut",
  covariates = c("age", "sex", "residence", "smoking"),
  nnt = TRUE
)
print(nnt_iptw)

# ATT-specific NNT with bootstrap CI
nnt_att <- calc_risk_diff_iptw(
  data = cachar_sample,
  outcome = "abnormal_screen",
  treatment = "areca_nut",
  covariates = c("age", "sex", "residence"),
  weight_type = "ATT",
  bootstrap_ci = TRUE,
  boot_n = 500,
  nnt = TRUE
)
summary(nnt_att)

Run the code above in your browser using DataLab