bartc-generics {bartCause}R Documentation

Generic Methods for bartcFit Objects

Description

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

Usage

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

extract(object, ...)

## S3 method for class 'bartcFit'
extract(object,
        type = c("pate", "sate", "cate", "mu.obs", "mu.cf", "mu.0",
                 "mu.1", "y.cf", "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,
        group.by,
        type = c("mu", "y", "mu.0", "mu.1", "y.0", "y.1", "icate", "ite",
                 "p.score"),
        combineChains = TRUE,
        ...)

refit(object, newresp, ...)

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

Arguments

object

Object of class bartcFit.

type

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

sample

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

combineChains

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

newresp

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

newdata

Data corresponding to the confounders in a bartc fit.

group.by

Optional grouping variable. See definition of group.by in bartc.

commonSup.rule, commonSup.cut

As in bartc.

...

Additional parameters passed up the generic method chain.

Details

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.

Value

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.

Author(s)

Vincent Dorie: vdorie@gmail.com.

See Also

bartc

Examples

## 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

set.seed(725)
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.fit <- lm(y ~ z + x)

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

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

ite.o <- order(ite.m)

plot(NULL, type = "n",
     xlim = c(1, length(ite.m)), ylim = range(ite.lb, ite.ub),
     xlab = "effect order", ylab = "individual treatment effect")
lines(rbind(seq_along(ite.m), seq_along(ite.m), NA),
      rbind(ite.lb[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]