This function provides tunes the expected number of crossings.

tuneEcrossCausal(ecross_control_candidates = c(1,2,3),
                 ecross_moderate_candidates = c(1,2,3),
                 y, pihat, z, tgt, x_control, x_moderate,
                 pihatpred=0, zpred=0, tpred=0,
                 xpred_control=matrix(0,0,0), xpred_moderate=matrix(0,0,0),
                 nburn=100, nsim=1000, ntree_control=200, ntree_moderate=50,
                 lambda=NULL, sigq=.9, sighat=NULL, nu=3,
                 base_control=.95, power_control=2,
                 base_moderate=.25, power_moderate=3,
                 sd_control=2*sd(y), sd_moderate=sd(y),
                 treatment_init = rep(1,length(unique(tgt))),
                 use_muscale=T, use_tauscale=T,
                 pihat_in_trt=F,
                 probit=FALSE, yobs=NULL)

Arguments

ecross_control_candidates

Vector where each element is a candidate ecross_control value for tuning. All combinations of ecross_control_candidates and ecross_moderate_candidates are considered.

ecross_moderate_candidates

Vector where each element is a candidate ecross_moderate value for tuning. All combinations of ecross_control_candidates and ecross_moderate_candidates are considered.

y

Length n vector with continuous response values. In probit case, should contain initializations for latent variables (+/- 1.96, for example).

pihat

Length n vector with estimated propensity score values.

z

Length n vector with binary treatment indicators (must be 1/0).

tgt

Length n targeted covariate over which to smooth.

x_control

A (n x p_control) data frame or matrix containing the covariates which are not to be smoothed over, for modeling prognostic effect.

x_moderate

A (n x p_moderate) data frame or matrix containing the covariates which are not to be smoothed over, for modeling treatment effect.

pihatpred

Length npred vector with out-of-sample estimated propensity score values.

zpred

Length npred vector with out-of-sample binary treatment indicators (must be 1/0).

tpred

Length npred out-of-sample targeted covariate.

xpred_control

A (npred x p_control) data frame or matrix containing out of sample covariates, for modeling prognostic effect.

xpred_moderate

A (npred x p_moderate) data frame or matrix containing out of sample covariates, for modeling treatment effect.

nburn

Number of burn-in MCMC iterations. Defaults to 100.

nsim

Number of MCMC iterations to save after burn-in. Defaults to 1000.

ntree_control

Number of trees for prognostic fit. Defaults to 200.

ntree_moderate

Number of trees for treatment fit. Defaults to 50.

lambda

Scale parameter in the chisq prior sigma^2. Defaults to NULL, ie being estimated from sigq and sighat. Not appicable for binary case.

sigq

Calibration quantile in the chisq prior on sigma^2. Defaults to .9. Not applicable for binary case.

sighat

Calibration estimate for chisq prior on sigma^2. Defaults to being estimated from data using linear model. Not applicable for binary case.

nu

Degrees of freedom in the chisq prior on sigma^2. Defaults to 3. Not applicable for binary case.

base_control

Base for prognostic tree prior. Defaults to 0.95.

power_control

Power for prognostic tree prior. Defaults to 2.

base_moderate

Base for treatment tree prior. Defaults to 0.25.

power_moderate

Power for treatment tree prior. Defaults to 3.

sd_control

SD(mu(x,t)) marginally at any covariate value (or its prior median if use_muscale=TRUE), for prognostic fit. Default is 2*sd(y).

sd_moderate

SD(tau(x,t)) marginally at any covariate value (or its prior median if use_tauscale=TRUE), for treatment fit. Default is sd(y).

treatment_init

T-length vector of initial treatment values. Defaults to 1's. Must be length of number of unique values in tgt and tpred combined.

use_muscale

Use a half-Cauchy prior on the scale of mu(x,t), the prognostic fit.

use_tauscale

Use a half-Normal prior on the scale of tau(x,t), the treatment fit.

pihat_in_trt

Boolean, ndicates whether to include the estimated propensity score as a covariate for the treatment tree fit. (Is always included in prognostic tree fit.) Defaults to TRUE.

probit

0 indicates continuous response; 1 indicates probit response. Default is 0. If 1, then yobs must be populated.

yobs

Length n vector of binary responses; only populated for probit=1 case.

Value

A list object, containing the following items:

ecross_control

The ecross_control value from the optimal ecross_control, ecross_moderate pair.

ecross_moderate

The ecross_moderate value from the optimal ecross_control, ecross_moderate pair.

waic_plot

A ggplot object containing diagnostics for tuning expected crossings.

waic_grid

A data frame containing the expected crossing candidates and corresponding WAIC values.

Examples

if (FALSE) { ## Evaluate optimal number of crossings. ecrossTune = tuneEcrossCausal(ecross_control_candidates = c(1,2.5,5), ecross_moderate_candidates = c(1,2.5,5,7.5,10), y, pihat, z, tgt, x_control, x_moderate, pihatpred=0, zpred=0, tpred=0, xpred_control=matrix(0,0,0), xpred_moderate=matrix(0,0,0), nburn=100, nsim=1000, ntree_control=200, ntree_moderate=50, lambda=NULL, sigq=.9, sighat=NULL, nu=3, base_control=.95, power_control=2, base_moderate=.25, power_moderate=3, sd_control=2*sd(y), sd_moderate=sd(y), treatment_init = rep(1,length(unique(tgt))), use_muscale=T, use_tauscale=T, pihat_in_trt=F, probit=FALSE, yobs=NULL) ## View expected number of crossings. ecrossTune[["ecross_opt"]] }