View source: R/posterior_transformation.R
| sample_bcf_posterior_predictive | R Documentation |
Sample from the posterior predictive distribution for outcomes modeled by BCF
sample_bcf_posterior_predictive(
model_object,
X = NULL,
Z = NULL,
propensity = NULL,
rfx_group_ids = NULL,
rfx_basis = NULL,
num_draws_per_sample = NULL
)
model_object |
A fitted BCF model object of class |
X |
A matrix or data frame of covariates. |
Z |
A vector or matrix of treatment assignments. |
propensity |
(Optional) A vector or matrix of propensity scores. Required if the underlying model depends on user-provided propensities. |
rfx_group_ids |
(Optional) A vector of group IDs for random effects model. Required if the BCF model includes random effects. |
rfx_basis |
(Optional) A matrix of bases for random effects model. Required if the BCF model includes random effects. |
num_draws_per_sample |
(Optional) The number of samples to draw from the likelihood for each draw of the posterior. Defaults to a heuristic based on the number of samples in a BCF model (i.e. if the BCF model has >1000 draws, we use 1 draw from the likelihood per sample, otherwise we upsample to ensure at least 1000 posterior predictive draws). |
Array of posterior predictive samples with dimensions (num_observations, num_posterior_samples, num_draws_per_sample) if num_draws_per_sample > 1, otherwise (num_observations, num_posterior_samples).
n <- 100
p <- 5
X <- matrix(rnorm(n * p), nrow = n, ncol = p)
pi_X <- pnorm(X[,1] / 2)
Z <- rbinom(n, 1, pi_X)
y <- 2 * X[,2] + 0.5 * X[,2] * Z + rnorm(n)
bcf_model <- bcf(X_train = X, Z_train = Z, y_train = y, propensity_train = pi_X)
ppd_samples <- sample_bcf_posterior_predictive(
model_object = bcf_model, X = X,
Z = Z, propensity = pi_X
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.