Expand a dataset and attach pre-computed inverse-probability weights
Source:R/tters-package.R
expand_trial_weighted.RdUser-facing wrapper around the extendr-generated expand_weighted_parquet().
It expands input_path under estimand, joins the per-(id, period) factor
table at factors_path (id, period, weight_factor), and writes the six
structural columns plus the cumulative-product weight. Weight values are
produced upstream in R; the engine reproduces only their deterministic
accumulation.
Usage
expand_trial_weighted(
input_path,
factors_path,
output_path,
id_col = "id",
period_col = "period",
treatment_col = "treatment",
eligible_col = "eligible",
outcome_col = "outcome",
first_period = 0L,
last_period = .Machine$integer.max,
estimand = "PP"
)Arguments
- input_path
Path to an existing input Parquet file.
- factors_path
Path to the per-
(id, period)factor Parquet file.- output_path
Path to write the weighted Parquet file.
- id_col, period_col, treatment_col, eligible_col, outcome_col
Column names. Defaults match the TrialEmulation conventions.
- first_period, last_period
Inclusive integer period bounds.
- estimand
"ITT"or"PP"; selects the weight model upstream, but the application arithmetic is identical for both.
Examples
input <- system.file("extdata", "weights", "input_data_censored.parquet",
package = "tters")
factors <- system.file("extdata", "weights",
"input_data_censored_itt_weights.parquet",
package = "tters")
expand_trial_weighted(input, factors, tempfile(fileext = ".parquet"),
estimand = "ITT")