weighting: Estimate Weights for Generalizing Average Treatment Effect

View source: R/weighting.R

weightingR Documentation

Estimate Weights for Generalizing Average Treatment Effect

Description

Estimate Weights for Generalizing Average Treatment Effect

Usage

weighting(
  data,
  sample_indicator,
  treatment_indicator = NULL,
  outcome = NULL,
  covariates,
  estimation_method = "lr",
  disjoint_data = TRUE
)

Arguments

data

data frame comprised of "stacked" sample and target population data

sample_indicator

variable name denoting binary sample membership (1 = in sample, 0 = out of sample)

treatment_indicator

variable name denoting binary treatment assignment (ok if only available in sample, not population)

outcome

variable name denoting outcome

covariates

vector of covariate names in data set that predict sample membership

estimation_method

method to estimate the probability of sample membership (propensity scores). Default is logistic regression ("lr").Other methods supported are Random Forests ("rf") and Lasso ("lasso")

disjoint_data

logical. If TRUE, then sample and population data are considered disjoint. This affects calculation of the weights - see details for more information.

Value

A summary of propensity scores, covariates, and ASMD for both weighted and unweighted data, as well as a summary of the weights. Also weighted and unweighted TATE if outcome and treatment are given

Examples

library(tidyverse)

# creating a stratified sample and recruiting from the sample to prepare for assess
selection_covariates <- c("total", "pct_black_or_african_american", "pct_white",
                          "pct_female", "pct_free_and_reduced_lunch")

strat_output <- stratify(generalizeR:::inference_pop, guided = FALSE, n_strata = 4,
                         variables = selection_covariates, idvar = "ncessch")
rec_output <- recruit(strat_output, guided = FALSE, sample_size = 40)

# creating the sample dataset from the output of recruit
sample_list <- c(rec_output$recruitment_lists[[1]]$ncessch[1:5],
                  rec_output$recruitment_lists[[2]]$ncessch[1:20],
                  rec_output$recruitment_lists[[3]]$ncessch[1:11],
                  rec_output$recruitment_lists[[4]]$ncessch[1:4])
inference_pop_sample <- mutate(generalizeR:::inference_pop,
                               sample = if_else(ncessch %in% sample_list, 1, 0))

# weighting the sample with the given covariates
weighting_output <- weighting(inference_pop_sample, sample_indicator = "sample",
                              covariates = selection_covariates, disjoint_data = FALSE)




NUstat/generalizeR documentation built on Feb. 7, 2024, 6:39 p.m.