plot_covariate_balance: Check covariate balance

Description Usage Arguments Value Examples

Description

After accounting for propensity, covariate distributions should be balanced between treated and control observations. These functions plot overlaid histograms, one for treated and one for control, of each covariate, using inverse propensity weights.

Usage

1
2
3

Arguments

dat

A data frame of covariates

results

The output from tidy_cf

covars

A character vector of covariates to include in the plot. If omitted, all columns of dat for which is.numeric = TRUE (for the numeric version) or is.numeric = FALSE (for the categorical version) will be plotted.

...

Additional arguments passed to geom_histogram

Value

A ggplot2 plot object, or list of plot objects if plot = FALSE.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
 require(grf)

 n <- 2000; p <- 10

 X <- matrix(rnorm(n * p), n, p)
 dat <- as.data.frame(X)
 dat$a <- sample(letters[1:3], size = n, replace = T)
 dat$b <- sample(letters[10:17], size = n, replace = T)
 W <- rbinom(n, 1, 0.4 + 0.2 * (X[, 1] > 0))
 Y <- pmax(X[, 1], 0) * W + X[, 2] + pmin(X[, 3], 0) + rnorm(n)

 # fit the model and extract results
 cf <- causal_forest(X, Y, W)
 results <- tidy_cf(cf)

 plot_covariate_balance_numeric(dat, results, bins = 20)
 plot_covariate_balance_categorical(dat, results, plot = T)

## End(Not run)

ensley-nexant/cfeval documentation built on May 20, 2020, 12:34 a.m.