balancing.weights: Compute balancing weights using FLEXOR, IC, or IGO methods

View source: R/stage-1.R

balancing.weightsR Documentation

Compute balancing weights using FLEXOR, IC, or IGO methods

Description

This function calculates balancing weights based on the specified pseudo-population method.

Usage

balancing.weights(
  S,
  Z,
  X,
  method,
  naturalGroupProp,
  num.random = 40,
  gammaMin = 0.001,
  gammaMax = (1 - 0.001),
  seed = NULL,
  verbose = TRUE,
  suppress_diagnostics = FALSE,
  nodesize = NULL,
  fold_ids = NULL
)

Arguments

S

Vector of factor levels representing the study memberships. Takes values in {1, ..., J}.

Z

Vector of factor levels representing the group memberships. Takes values in {1, ..., K}.

X

Covariate matrix of N rows and p columns.

method

Pseudo-population method, i.e., weighting method. Take values in FLEXOR, IC, or IGO.

naturalGroupProp

Relevant only for FLEXOR method: a fixed user-specified probability vector \theta.

num.random

Relevant only for FLEXOR method: number of random starting points of \gamma in the two-step iterative procedure. Default is 40.

gammaMin

Relevant only for FLEXOR method: Lower bound for each \gamma_s in the two-step iterative procedure. Default is 0.001.

gammaMax

Relevant only for FLEXOR method: Upper bound for each \gamma_s in the two-step iterative procedure. Default is 0.999.

seed

Seed for random number generation. Default is NULL.

verbose

Logical; Relevant only for FLEXOR method: if TRUE (default), displays progress messages during computation to the console. Set to FALSE to suppress these messages.

suppress_diagnostics

Logical; if TRUE, suppress diagnostic warnings (default: FALSE). Used internally during bootstrapping to avoid console clutter.

nodesize

Integer nodesize for the propensity score random forests; if NULL, selected automatically. Used internally during bootstrapping to reuse the nodesize from the original data.

fold_ids

Integer vector of cross-fitting fold assignments (length N); if NULL, generated internally. Used internally during bootstrapping so that each replicate is cross-fitted like the point estimate, with all copies of a resampled observation held in the same fold.

Details

Propensity scores are estimated with a joint (S, Z) random forest, fit to a truncated SVD reconstruction of the unscaled covariates that retains 60% of the cumulative singular values.

Value

An S3 object of class balancing_weights with the following components:

wt.v

N empirically normalized sample weights.

percentESS

Percentage sample effective sample size (ESS) for the pseudo-population.

method

Weighting method used (FLEXOR, IC, or IGO).

selected_nodesize

Selected min.node.size for the propensity forest.

diagnostics

A list of propensity model diagnostics:

  • frac_truncated: Fraction of subjects with own-cell propensity below the truncation floor prior to stabilization.

  • crossfit_accuracy: Out-of-fold classification accuracy of the propensity model (NA during bootstrap).

  • max_weight: Maximum weight prior to normalization.

  • prob_quantiles: Quantiles of the subject-level propensity distribution.

Examples


data(demo)

# IC Method
weights_ic <- balancing.weights(S, Z, X, method = "IC", naturalGroupProp)
summary(weights_ic)

# IGO Method
weights_igo <- balancing.weights(S, Z, X, method = "IGO", naturalGroupProp)
summary(weights_igo)

# FLEXOR Method
weights_flexor <- balancing.weights(S, Z, X, method = "FLEXOR", naturalGroupProp, num.random = 40)
summary(weights_flexor)



WMAP documentation built on Oct. 6, 2026, 1:07 a.m.