| Title: | Weighted Meta-Analysis with Pseudo-Populations |
| Version: | 1.3.0 |
| Description: | Implementation of integrative weighting approaches for multiple observational studies and causal inferences. The package features three weighting approaches, each representing a special case of the unified weighting framework, introduced by Guha and Li (2024) <doi:10.1093/biomtc/ujae070>, which includes an extension of inverse probability weights for data integration settings. |
| License: | GPL-3 |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| LazyData: | true |
| Imports: | pkgcond, ggplot2, zeallot, randomForest, ranger, forcats, utils, stats |
| Depends: | R (≥ 3.5.0) |
| Suggests: | future (≥ 1.33.0), future.apply (≥ 1.11.0), parallelly (≥ 1.37.0), knitr, rmarkdown |
| NeedsCompilation: | no |
| Packaged: | 2026-05-20 18:40:41 UTC; chayce |
| Author: | Subharup Guha [aut, cre], Mengqi Xu [aut], Chayce Reed [aut], Kashish Priyam [aut], Yi Li [aut] |
| Maintainer: | Subharup Guha <Subharup.Guha@dartmouth.edu> |
| Repository: | CRAN |
| Date/Publication: | 2026-06-05 11:50:02 UTC |
| VignetteBuilder: | knitr |
Calculate balancing weights with method routing
Description
Compute balancing weights using IC, IGO, or FLEXOR methods.
Usage
Stage1(
data,
parm,
method,
flexorFlag,
num.random,
naturalGroupProp,
gammaMin,
gammaMax,
verbose
)
Arguments
data |
Structured data list from fn.createListData() |
parm |
Parameter list with propensity scores from fn.Estimate_mgPS() |
method |
Chracter string: "IC", "IGO", or "FLEXOR" |
flexorFlag |
Logical indicating if FLEXOR is selected |
num.random |
Number of random gamma starting points for FLEXOR |
naturalGroupProp |
Probability vector theta for FLEXOR |
gammaMin |
Lower bound for gamma parameters (FLEXOR only) |
gammaMax |
Upper bound for gamma parameters (FLEXOR only) |
verbose |
Logical; if TRUE, display FLEXOR progress messages |
Value
List with two elements:
return.parm - Updated parameter list with weights and ESS
percentESS - Percentage effective sample size
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
)
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 |
method |
Pseudo-population method, i.e., weighting method. Take values in |
naturalGroupProp |
Relevant only for FLEXOR method: a fixed user-specified probability vector |
num.random |
Relevant only for FLEXOR method: number of random starting points of |
gammaMin |
Relevant only for FLEXOR method: Lower bound for each |
gammaMax |
Relevant only for FLEXOR method: Upper bound for each |
seed |
Seed for random number generation. Default is |
verbose |
Logical; Relevant only for FLEXOR method: if |
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 |
Value
An S3 list object with the following components:
- wt.v
Nempirically normalized sample weights.- percentESS
Percentage sample effective sample size (ESS) for the pseudo-population.
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)
Bootstrap procedure for variance estimation
Description
Bootstrap procedure for variance estimation
Usage
bootStrap(
data,
moments.ar,
moreFeatures.v,
B,
method,
method_wt.v,
naturalGroupProp,
num.random.b,
gammaMin,
gammaMax,
seed,
verbose,
parallel = FALSE,
n_cores = NULL,
outcome_model = FALSE,
crossfit_folds = NULL,
nodesize = NULL
)
Arguments
data |
Structured data list |
moments.ar |
Point estimate moments array |
moreFeatures.v |
Point estimate mean differences |
B |
Number of bootstrap samples |
method |
Weighting method ("IC", "IGO", or "FLEXOR") |
method_wt.v |
Original weights |
naturalGroupProp |
FLEXOR theta parameter |
num.random.b |
Number of random starts for FLEXOR in bootstrap |
gammaMin |
FLEXOR gamma lower bound |
gammaMax |
FLEXOR gamma uppper bound |
seed |
Random seed |
verbose |
Logical; if TRUE, display progress |
parallel |
Logical; if TRUE, use parallel processing (default: FALSE) |
n_cores |
Number of cores to use for parallel processing (default: availableCores() - 1) |
outcome_model |
Logical; if TRUE, uses RF-predicted Y in place of observed Y. Default FALSE. |
crossfit_folds |
Integer >= 2 enabling K-fold cross-fitting for the outcome model, or NULL to fit on the full bootstrap sample. Default is NULL. |
nodesize |
Integer nodesize for the propensity score random forests; reuses the value selected on the original data to skip re-tuning in each bootstrap iteration. |
Value
List with three elements:
collatedMoments.ar - Array of bootstrap moments
collatedMoreFeatures.mt - Matrix of bootstrap mean differences
collatedESS - Vector of bootstrap ESS values
Estimate causal effects using FLEXOR, IC, or IGO methods
Description
This function estimates causal effects based on the specified pseudo-population method. The FLEXOR method involves an iterative two-step procedure.
Usage
causal.estimate(
S,
Z,
X,
Y,
B = 0,
method,
naturalGroupProp = NULL,
num.random = 40,
gammaMin = 0.001,
gammaMax = (1 - 0.001),
seed = NULL,
verbose = TRUE,
parallel = FALSE,
n_cores = NULL,
outcome_model = FALSE,
crossfit_folds = 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 |
Y |
Matrix of |
B |
Number of bootstrap samples for variance estimation. Default is 0 (point estimates only). |
method |
Pseudo-population method, i.e., weighting method. Take values in |
naturalGroupProp |
Relevant only for FLEXOR method: a fixed user-specified probability vector |
num.random |
Relevant only for FLEXOR method: number of random starting points of |
gammaMin |
Relevant only for FLEXOR method: Lower bound for each |
gammaMax |
Relevant only for FLEXOR method: Upper bound for each |
seed |
Seed for random number generation. Default is |
verbose |
Logical; if |
parallel |
Logical; if TRUE, use parallel processing for bootstrap (default: FALSE) |
n_cores |
Number of cores to use for parallel bootstrap (default: availableCores() - 1). Only used if parallel = TRUE. |
outcome_model |
Logical; if TRUE, fits a random forest on X, S, Z and substitutes predicted outcomes for observed Y. Default FALSE. |
crossfit_folds |
Integer >= 2 for K-fold cross-fitting of the outcome model, or NULL (default) to fit on the full data. Only used when |
Value
An S3 list object with the following components:
- percentESS
Percentage sample effective sample size (ESS) of the pseudo-population.
- moments.ar
An array of dimension
3 \times K \times L, containing:Estimated means, standard deviations (SDs), and medians (dimension 1),
For
Kgroups (dimension 2),And
Loutcomes (dimension 3).
- otherFeatures.v
Estimated mean group differences for
Loutcomes.- collatedMoments.ar
An array of dimension
3 \times K \times L \times B, containing:-
moments.arof thebth bootstrap sample (dimensions 1–3), For
Bbootstrap samples (dimension 4).
-
- collatedOtherFeatures.mt
A matrix of dimension
L \times Bcontaining:-
otherFeatures.vof thebth bootstrap sample (dimension 1), For
Bbootstrap samples (dimension 2).
-
- collatedESS
A vector of length
B
containing percentage sample ESS for B bootstrap samples.
- method
Pseudo-population method, i.e., weighting method.
Examples
data(demo)
# Point estimates only (no CIs)
result <- causal.estimate(S, Z, X, Y, B = 0, method = "IC", naturalGroupProp)
summary(result)
# Bootstrap CIs
set.seed(1)
result <- causal.estimate(S, Z, X, Y, B = 100, method = "IC", naturalGroupProp)
summary(result)
plot(result)
# FLEXOR method
result <- causal.estimate(S, Z, X, Y, B = 100, method = "FLEXOR", naturalGroupProp,
num.random = 40, seed = 1)
# Outcome model: substitute RF predictions for observed Y
result <- causal.estimate(S, Z, X, Y, B = 0, method = "FLEXOR", naturalGroupProp,
outcome_model = TRUE)
# Parallel bootstrap
result <- causal.estimate(S, Z, X, Y, B = 100, method = "FLEXOR", naturalGroupProp,
parallel = TRUE, n_cores = 2)
Check if factor levels are valid
Description
Validates that factor levels are exactly 1, 2, ..., num
Usage
check.factor(factor.vec, num)
Arguments
factor.vec |
Factor vector to check |
num |
Expected number of levels |
Value
Logical: TRUE if factor levels are invalid, FALSE if valid
Validate and resample bootstrap data
Description
Validate and resample bootstrap data
Usage
checkSample(data.in, wt_in.v)
Arguments
data.in |
Orignal data list |
wt_in.v |
Sampling weihgts (length N) |
Value
Resampled data list with updated indices
Demo Dataset
Description
A dataset containing example data for demonstration purposes.
Usage
data(demo)
Format
An rda object, with 450 observations and the following variables:
- S
A vector of factor levels, representing the study memberships.
- Z
A vector of factor levels, representing the group memberships.
- X
A covariate matrix.
- Y
An outcome matrix.
- naturalGroupProp
The relative group prevalences of the larger natural population. Necessary only for FLEXOR weights; it should be skipped for IC and IGO weights.
- groupNames
Disease subtype names "IDC" or "ILC"
Details
Demo Dataset for WMAP Examples
A demonstration dataset containing multi-site, multi-group observational data for testing WMAP weighting methods. The data simulates a study of breast cancer subtypes across mutliple hospitals.
See Also
balancing.weights for computing weights
causal.estimate for estimating causal effects
Examples
# Load the demo dataset
data(demo)
# Examine the structure
str(S) # Study memberships
str(Z) # Group memberships
table(S, Z) # Cross-tabulation of studies and groups
# Basic usage with IC method
weights <- balancing.weights(S, Z, X, method = "IC", naturalGroupProp)
summary(weights)
# Full causal analysis
results <- causal.estimate(S, Z, X, Y, B = 10, method = "IC", naturalGroupProp)
summary(results)
plot(results)
Function for FLEXOR optimization
Description
Function for FLEXOR optimization
Usage
fn.ESS_FLEXOR(sub_gamma_s, theta_z, parm, data)
Arguments
sub_gamma_s |
First (J-1) elements of gamma_s vector |
theta_z |
Group probabilities vector |
parm |
Parameter list containing tmp1.ar |
data |
Structured data list |
Value
Negative normalized ESS (scalar value to minimize)
Estimate multiple propensity scores
Description
Wrapper that calls fn.RF_ZFirst and prepares propensity scores
for use in weight calculations.
Usage
fn.Estimate_mgPS(data, nodesize = NULL)
Arguments
data |
Structured data list |
nodesize |
Integer min.node.size for ranger, or NULL to tune |
Value
Parameter list with propensity scores:
tmp.ar - Truncated propensity scores, dim (N, K, J)
tmp1.ar - Negative log propensities (for weight calculation)
e$sz - Joint propensity scores after truncation
selected_nodesize - min.node.size used
diagnostics - List with frac_truncated and prob_quantiles
Calculate FLEXOR weights
Description
Wrapper function that calls the iterative optimization loop to maximize effective sample size
Usage
fn.FLEXOR(start_theta_z, start_gamma_s, data, parm)
Arguments
start_theta_z |
Initial group probabilities (fixed) |
start_gamma_s |
Initial study probabilities (optimized) |
data |
Structured data list |
parm |
Parameter list with propensity scores |
Value
Updated parm with FLEXOR weights and convergence info
Calculate IC weights
Description
Calculate IC weights
Usage
fn.IC(theta_z, gamma_s, data, parm)
Arguments
theta_z |
Group probability vector (length K, sums to 1) |
gamma_s |
Study probability vector (length J, sums to 1) |
data |
Structured data list |
parm |
Parameter list containing tmp1.ar (negative log propensities) |
Value
Updated parm with:
wt.v - Weight vector (normalize to mean 1)
ESS - Effective sample size
gamma_s - Study probability used
theta_z - Group probabilities used
Calculate IGO weights
Description
Calculate IGO weights
Usage
fn.Omnibus(theta_z, gamma_s, data, parm)
Arguments
theta_z |
Group probability vector (length K, sums to 1) |
gamma_s |
Study probability vector (length J, sums to 1) |
data |
Structured data list |
parm |
Parameter list containing tmp1.ar (negative log propensities) |
Value
Updated parm with weights, ESS, and parameters
Calculate the weighted quantile using probability mass function
Description
Computes a quantile of discrete weighted distribution by constructing the cumulative distribution function from probability masses
Usage
fn.PMF_quantile(val, q, mass)
Arguments
val |
Numeric vector of values |
q |
Quantile to compute (between 0 and 1, e.g., 0.5 for median) |
mass |
Numeric vector of weights/masses corresponding to each value |
Value
Numeric quantile value. For the minimum value, returns that value. Otherwise, returns the average of adjacent values for smoothness.
Estimate joint propensity scores with cross-fitting or single fit
Description
When nodesize = NULL (original data), generates 5-fold assignments,
runs fn.RF_tune_nodesize to select min.node.size and obtain
out-of-fold propensity scores in one pass. When nodesize is supplied
(bootstrap), skips tuning and fits one ranger model on the full data instead.
Usage
fn.RF_ZFirst(data, svdCutoff, nodesize = NULL)
Arguments
data |
Structured data list |
svdCutoff |
Proportion of variance to retain in SVD preprocessing |
nodesize |
Integer min.node.size for ranger, or NULL to tune |
Value
Parameter list with propensity scores:
e$sz - P(S=s, Z=z | X) after truncation, dim (N, K, J)
selected_nodesize - min.node.size used for the final fit
diagnostics - List with frac_truncated, prob_quantiles, and crossfit_accuracy
Run one complete 5-fold cross-fit for propensity score estimation
Description
For each fold, fits a joint (S,Z) ranger probability forest on the training folds and predicts on the held-out fold. Returns out-of-fold joint propensity scores.
Usage
fn.RF_crossfit_once(data, matX2, min.node.size, fold_ids)
Arguments
data |
Structured data list |
matX2 |
SVD-preprocessed covariate matrix (N x p) |
min.node.size |
Minimum node size for the ranger forest |
fold_ids |
Integer vector of fold assignments (length N) |
Value
Array of dim (N, K, J): out-of-fold P(S=s, Z=z | X_i). Columns of the intermediate matrix are ordered by factor level: (s=1,z=1), (s=1,z=2), ..., (s=J,z=K), matching column index (s-1)*K + z.
Single-fit propensity score estimation for bootstrap samples
Description
Fits one joint (S,Z) ranger probability forest on the full (bootstrap) data and returns in-sample predictions.
Usage
fn.RF_fit_single(data, matX2, min.node.size)
Arguments
data |
Structured data list |
matX2 |
SVD-preprocessed covariate matrix (N x p) |
min.node.size |
Minimum node size for the ranger forest |
Value
Array of dim (N, K, J): in-sample P(S=s, Z=z | X_i)
Select min.node.size for propensity RF via weight-stability criteria
Description
Evaluates each candidate in c(10, 25, 50, 100) using 5-fold
cross-fitted propensity scores (same fold assignments across candidates)
and selects the smallest value that satisfies all three weight-stability
criteria. The out-of-fold predictions for the selected candidate are
returned directly as the final propensity scores. If no candidate passes,
uses 100 and issues a warning.
Usage
fn.RF_tune_nodesize(data, matX2, fold_ids)
Arguments
data |
Structured data list |
matX2 |
SVD-preprocessed covariate matrix (N x p) |
fold_ids |
Integer vector of fold assignments (length N) |
Value
Named list with:
nodesize - Selected min.node.size (integer)
e_sz - Out-of-fold propensity array, dim (N, K, J)
crossfit_accuracy - Proportion of subjects correctly classified by argmax of OOF predictions
Perform SVD dimensionality reduction on covariates
Description
Perform SVD dimensionality reduction on covariates
Usage
fn.SVD(data, cutoff)
Arguments
data |
Structured data list containing X (covariate matrix) |
cutoff |
Proportion of variance to retain (e.g., 0.6) |
Value
Reduced-dimension covariate matrix with same dimensions as original
Calculate weighted moments and group differences
Description
Calculate weighted moments and group differences
Usage
fn.Stage2(local_data, local_wt.v, Y_hat = NULL, outcome_model = FALSE)
Arguments
local_data |
Structured data list containing Y (outcomes), Z (groups), K |
local_wt.v |
Vector of weights (length N) |
Y_hat |
Predicted outcomes matrix (N x L) from |
outcome_model |
Logical; if TRUE, uses RF-predicted Y in place of observed Y. Default FALSE. |
Value
List with two elements:
moments.ar - Array (3 * K * L) of means, SDs, medians
moreFeatures.v - Vector (length L) of mean differences
Wrapper for Stage1 function with retry logic
Description
Wrapper for Stage1 function with retry logic
Usage
fn.Weights(
data,
method,
flexorFlag,
num.random,
naturalGroupProp,
gammaMin,
gammaMax,
verbose,
nodesize = NULL
)
Arguments
data |
Structured data list |
method |
Character string: "IC", "IGO", or "FLEXOR" |
flexorFlag |
Logical indicating if FLEXOR is selected |
num.random |
Number of random starting points for FLEXOR |
naturalGroupProp |
Probability vector theta for FLEXOR |
gammaMin |
Lower bound for gamma (FLEXOR only) |
gammaMax |
Upper bound for gamma (FLEXOR only) |
verbose |
Logical; if TRUE, display progress messages |
Value
List with return.parm and percentESS, or NULL if all attempts fail
Check for low effective sample size
Description
Warns if the percentage ESS falls below a threshold, indicating that the psuedo-population weights may be unreliable.
Usage
fn.check_ess(percentESS, threshold = DIAG_ESS_THRESHOLD)
Arguments
percentESS |
Percentage ESS value (0-100) |
threshold |
Minimum acceptable percentage ESS (default: 5) |
Value
Invisibly returns TRUE if warning issued, FALSE otherwise
Check for extreme weights
Description
Warns if any weights are excessively large relative to the mean, which can indicate positivity violations or model misspecification.
Usage
fn.check_extreme_weights(wt.v, ratio_threshold = DIAG_WEIGHT_RATIO)
Arguments
wt.v |
Vector of normalized weights |
ratio_threshold |
Maximum acceptable max/mean weight ratio (default: 20) |
Value
Invisibly returns TRUE if warning issued, FALSE otherwise
Check for positivity violations
Description
Warns if any study-group combination has very few observations or estimated propensities near zero, suggesting positivity may be violated.
Usage
fn.check_positivity(data, parm, propensity_min = DIAG_PROPENSITY_MIN)
Arguments
data |
Structured data list with N.sz (study-group counts) |
parm |
Parameter list with diagnostics (frac_truncated) |
propensity_min |
Fraction threshold: warn if this fraction of subjects had near-zero pre-truncation propensity (default: 0.05) |
Value
Invisibly returns TRUE if warning issued, FALSE otherwise
Clip vector values to bounds and renormalize
Description
Ensures all values are within specified bounds and sum to 1
Usage
fn.clip(vec, gammaMin, gammaMax)
Arguments
vec |
Numeric vector to clip |
gammaMin |
Lower Bound |
gammaMax |
Upper bound |
Value
Clipped and renormalized vector that sums to 1
Create structured data list from input vectors
Description
Converts raw input vectors into a structured list format used throughout the package
Usage
fn.createListData(S, Z, X, Y = NULL)
Arguments
S |
Vector of study memberships (factor or numeric, values 1...J) |
Z |
Vector of group memberships (factor or numeric, values 1...Z) |
X |
Covariate matrix (N + p) |
Y |
Outcome matrix (N + L), optional |
Value
Structured list containing:
S, Z, X, Y - Original inputs
N - Total sample size
J - Number of studies
K - Number of groups
p - Number of covariates
Plus all components added by preStage1()
Fit random forest outcome model and generate predicted outcomes
Description
Fits a random forest regressor for each outcome column using covariates X,
study membership S, and group membership Z. Predicts each subject's outcome
under their actual group. These predictions are used in fn.Stage2
when outcome_model = TRUE.
Usage
fn.fit_outcome_model(data, crossfit_folds = NULL)
Arguments
data |
Structured data list containing X, S, Z, Y, N, J, K, p |
crossfit_folds |
Integer >= 2 for K-fold cross-fitting, or NULL (default) to fit on the full data. |
Value
Matrix of dimension N \times L of predicted outcomes.
Y_hat[i, l] is the predicted outcome for individual i
under their actual group for outcome l.
Iterative optimization loop for FLEXOR
Description
Iterative optimization loop for FLEXOR
Usage
fn.loop(
start_theta_z,
start_gamma_s,
data,
parm,
FUN,
FUN2,
tol = 0.001,
optim.maxit = 2,
loop.maxit = 50
)
Arguments
start_theta_z |
Initial group probabilities (fixed during optimization) |
start_gamma_s |
Initial study probabilities (optimized) |
data |
Structured data list |
parm |
Parameter list with propensity scores |
FUN |
Objective function to minimize (typically fn.ESS_FLEXOR) |
FUN2 |
Weight calculation function (typically fn.Omnibus) |
tol |
Convergence tolerance for relative ESS change (default: 1e-3) |
optim.maxit |
Maximum iterations for optim() per loop (default: 2) |
loop.maxit |
Maximum outer loop iterations (default: 50) |
Value
Updated parm with:
wt.v - Optimized weights
ESS - Final effective sample size
gamma_s - Optimized study probabilities
theta_z - Group probailities (unchanged)
count - Number of iterations performed
change - Final relative ESS change
Sample from Dirichlet distribution
Description
Sample from Dirichlet distribution
Usage
fn.rdirichlet(alpha)
Arguments
alpha |
Numeric vector of concentration parameters |
Value
Numeric vector sampled from Dirichlet(alpha)
Run all diagnostic checks on balancing weights
Description
Convenience wrapper that runs ESS, extreme weight, and positivity checks. Called automatically by balancing.weights() and causal.estimate().
Usage
fn.run_diagnostics(wt.v, percentESS, data, parm = NULL)
Arguments
wt.v |
Vector of normalized weights |
percentESS |
Percentage effective sample size |
data |
Structured data list |
parm |
Parameter list with propensity scores (optional) |
Value
Invisibly returns named logical vector of which warnings were issued
Validate method and FLEXOR-specific parameters
Description
Checks that the selected method is valid and that FLEXOR parameters meet required constraints
Usage
fn.userInputChecks_1(
method,
flexorFlag,
gammaMin,
gammaMax,
num.random,
naturalGroupProp
)
Arguments
method |
Character string: "IC", "IGO", or "FLEXOR" (case insensitive) |
flexorFlag |
Logical indicating if FLEXOR method is selected |
gammaMin |
Lower bound for gamma parameters (FLEXOR only) |
gammaMax |
Upper bound for gamma parameters (FLEXOR only) |
num.random |
Number of random starting points (FLEXOR only) |
naturalGroupProp |
Probability vector for group prevalences (FLEXOR only) |
Value
NULL (stops with error if validation fails)
Validate data dimensions and completeness
Description
Checks that S, Z, X dimensions match and that there are no missing values
Usage
fn.userInputChecks_2(data, B = NULL)
Arguments
data |
Structured data list from fn.createListData() |
B |
Number of bootstrap samples (optional) |
Value
NULL (stops with error if validation fails)
Variable outcome dimensions
Description
Checks that Y dimensions match S
Usage
fn.userInputChecks_3(data)
Arguments
data |
Structured data list |
Value
NULL (stops with error if validation fails)
Global variable declarations for R CMD check
Description
These variables are created using the zeallot package;s which allows multiple assignment. Declaring them here prevents R CMD check warnings about undefined globals.
Null coalescing operator Returns first argument if not NULL, otherwise returns second argument
Description
Null coalescing operator Returns first argument if not NULL, otherwise returns second argument
Usage
a %||% b
Check if value is a natural number
Description
Check if value is a natural number
Usage
is.natural(x, tol = .Machine$double.eps^0.5)
Arguments
x |
Numeric value to check |
tol |
Tolerance for floating point comparison |
Value
Logical indicating if x is a natural number (positive integer)
Check if vector is a valid probability vector
Description
Tests if values are non-negative and sum to 1 (within tolerance)
Usage
is.probvector(x, tol = .Machine$double.eps^0.5)
Arguments
x |
Numeric vector to check |
tol |
Tolerance for floating point comparison |
Value
Logical indicating if x is a natural number (positive integer)
Plot method for objects of class 'causal_estimates'
Description
Creates a boxplot showing the distribution of effective sample size (ESS) across bootstrap samples for the specified weighting method.
Usage
## S3 method for class 'causal_estimates'
plot(x, ...)
Arguments
x |
An object of class 'causal_estimates' returned by |
... |
Additional arguments:
|
Value
A boxplot of percent sample ESS for a specific weighting method (FLEXOR, IC, or IGO
Examples
## Not run:
data(demo)
result <- causal.estimate(S, Z, X, Y, B = 5, method = "FLEXOR", naturalGroupProp)
plot(result)
plot(result, y_limit = c(0, 100), color = "steelblue")
## End(Not run)
Preprocess data for Stage 1 analysis
Description
Creates an index lists and counts for each study-group combination, which are used throughout the weighting calculations
Usage
preStage1(data.local)
Arguments
data.local |
List containing S (studies), Z (groups), X (covariates), and metadata |
Value
Updated data list with added components:
N.sz - Matrix of counts for each study-group combination
indx.sz.lst - List of indices for each study-group combination
N.z - Total count per group
N.s - TOtal count per study
which.binary - Indices of binary covariates
Summary method for objects of class 'balancing_weights'
Description
Displays a summary of balancing weights including the numnber of weights. their distribution, and the effective sample size.
Usage
## S3 method for class 'balancing_weights'
summary(object, ...)
Arguments
object |
An object of class 'balancing_weights' returned by |
... |
Additional arguments (currently unused, reserved for future extensions). |
Value
No return value, called for side effects (prints summary to console)
The total number of weights
Statistical summary of weight values
Percentage sample effective sample size (ESS) for the pseudo-population
Examples
data(demo)
result <- balancing.weights(S, Z, X, method = "IC", naturalGroupProp)
summary(result)
Summary method for objects of class 'causal_estimates'
Description
Displays a comprehensive summary of causal estimates including effective sample size, mean differences between groups with confidence intervals, and standard deviation ratios.
Usage
## S3 method for class 'causal_estimates'
summary(object, ...)
Arguments
object |
An object of class 'causal_estimates' returned by |
... |
Additional arguments (currently unused, reserved for future extensions). |
Value
No return value, called for side effects (prints summary to console):
Percentage sample effective sample size (ESS) for the pseudo-population
The mean differences between two groups with their corresponding 95
The ratios of standard deviations between two groups with their corresponding 95
Examples
data(demo)
set.seed(1)
result <- causal.estimate(S, Z, X, Y, B = 5, method = "IC", naturalGroupProp)
summary(result)
Format estimates with confidence intervals
Description
Creates formatted strings displaying point estimates with their confidence intervals in the format: "estimate (lower, upper)"
Usage
write_res(estimates, CI)
Arguments
estimates |
Numeric vector of point estimates |
CI |
Matrix with 2 columns: lower bounds (column 1) and upper bounds (column 2) |
Value
Character vector of formatted estimates with CIs
Calculate standard deviation ratios with confidence intervals
Description
Calculate standard deviation ratios with confidence intervals
Usage
write_sigma_ratio(output)
Arguments
output |
An object of class 'causal_estimates' containing:
|
Value
Character vector of formatted SD ratios with 95