bartc-generics {bartCause}R Documentation

Generic Methods for bartcFit Objects


Visual exploratory data analysis and model fitting diagnostics for causal inference models fit using the bartc function.


## S3 method for class 'bartcFit'
       type = c("pate", "sate", "cate", "mu.obs", "", "mu.0",
                "mu.1", "", "y.0", "y.1", "icate", "ite",
                "p.score", "p.weights"),
       sample = c("inferential", "all"),

extract(object, ...)

## S3 method for class 'bartcFit'
        type = c("pate", "sate", "cate", "mu.obs", "", "mu.0",
                 "mu.1", "", "y.0", "y.1", "icate", "ite",
                 "p.score", "p.weights", "sigma"),
        sample = c("inferential", "all"),
        combineChains = TRUE,

## S3 method for class 'bartcFit'
predict(object, newdata,,
        type = c("mu", "y", "mu.0", "mu.1", "y.0", "y.1", "icate", "ite",
        combineChains = TRUE,

refit(object, newresp, ...)

## S3 method for class 'bartcFit'
      newresp = NULL,
      commonSup.rule = c("none", "sd", "chisq"),
      commonSup.cut  = c(NA_real_, 1, 0.05),



Object of class bartcFit.


Which quantity to return. See details for a description of possible values.


Return information for either the "inferential" (e.g. treated observations when the estimand is att) or "all" observations.


If the models were fit with more than one chain, results retain the chain structure unless combineChains is TRUE.


Not presently used, but provided for compatibility with other definitions of the refit generic.


Data corresponding to the confounders in a bartc fit.

Optional grouping variable. See definition of in bartc.

commonSup.rule, commonSup.cut

As in bartc.


Additional parameters passed up the generic method chain.


fitted returns the values that would serve as predictions for an object returned by the bartc function, while extract instead returns the full matrix or array of posterior samples. The possible options are:

refit exists to allow the same regressions to be used to calculate estimates under different common support rules. To refit those models on a subset, see the examples in bartc.

predict allows the fitted model to be used to make predictions on an out-of-sample set. Requires model to be fit with keepTrees equal to TRUE. As ‘y’ values are all considered out of sample, the posterior predictive distribution is always used when relevant.


For fitted, extract, and predict, a matrix, array, or vector depending on the dimensions of the result and the number of chains. For the following, when n.chains is one the dimension is dropped.

For refit, an object of class bartcFit.


Vincent Dorie:

See Also



## fit a simple linear model
n <- 100L
beta.z <- c(.75, -0.5,  0.25)
beta.y <- c(.5,   1.0, -1.5)
sigma <- 2

x <- matrix(rnorm(3 * n), n, 3)
tau <- rgamma(1L, 0.25 * 16 * rgamma(1L, 1 * 32, 32), 16)

p.score <- pnorm(x %*% beta.z)
z <- rbinom(n, 1, p.score)

mu.0 <- x %*% beta.y
mu.1 <- x %*% beta.y + tau

y <- mu.0 * (1 - z) + mu.1 * z + rnorm(n, 0, sigma)

# low parameters only for example
fit <- bartc(y, z, x, n.samples = 100L, n.burn = 15L, n.chains = 2L)

# compare fit to linear model <- lm(y ~ z + x)

plot(fitted(fit, type = "mu.obs"), fitted(

# rank order sample individual treatment effect estimates and plot
ites   <- extract(fit, type = "ite")
ite.m  <- apply(ites, 2, mean) <- apply(ites, 2, sd) <- ite.m - 2 *
ite.ub <- ite.m + 2 *

ite.o <- order(ite.m)

plot(NULL, type = "n",
     xlim = c(1, length(ite.m)), ylim = range(, ite.ub),
     xlab = "effect order", ylab = "individual treatment effect")
lines(rbind(seq_along(ite.m), seq_along(ite.m), NA),
      rbind([ite.o], ite.ub[ite.o], NA), lwd = 0.5)
points(seq_along(ite.m), ite.m[ite.o], pch = 20)

[Package bartCause version 1.0-6 Index]