plot: Plot methods for 'bartc'

bartc-plotR Documentation

Plot methods for bartc

Description

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

Usage

plot_sigma(x, main = "Traceplot sigma", 
           xlab = "iteration", ylab = "sigma",
           lty = 1:x$n.chains,
           ...)

plot_est(x, main = paste("Traceplot", x$estimand),
         xlab = "iteration", ylab = x$estimand,
         lty = 1:x$n.chains, col = NULL,
         ...)

plot_indiv(x, main = "Histogram Individual Quantities",
           type = c("icate", "mu.obs", "mu.cf", "mu.0",
                    "mu.1", "y.cf", "y.0", "y.1", "ite"),
           xlab = "treatment effect",
           breaks = 20,
           ...)

plot_support(x, main = "Common Support Scatterplot",
             xvar = "tree.1", yvar = "tree.2",
             sample = c("inferential", "all"),
             xlab = NULL, ylab = NULL,
             pch.trt = 21, bg.trt = "black",
             pch.ctl = pch.trt, bg.ctl = NA,
             pch.sup = pch.trt, bg.sup = NA, col.sup = "red", cex.sup = 1.5,
             legend.x = "topleft", legend.y = NULL,
             ...)

Arguments

x

Object of class bartcFit.

main

Character title of plot.

xlab

Character label of x axis. For plot_support, if NULL a default will be used.

ylab

Character label of y axis. For plot_support, if NULL a default will be used.

lty

For line plots (plot_sigma, plot_est), models use the values of lty to visually distinguish each chain.

col

For line plots, use col vector to distinguish between groups (if any).

breaks

Argument to codehist.

type

The individual quantity to be plotted. See fitted.

xvar

Variable for use on x axis. Can be one of "tree.XX", "pca.XX", "css", any individual level quantity accepted by fitted, the number or name of a column used to fit the response model, or a given vector. See below for details.

sample

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

yvar

Variable for use on the y axis, of the same form as xvar.

pch.trt

pch point value used when plotting treatment observations.

bg.trt

bg background value used when plotting treatment observations.

pch.ctl

pch point value used when plotting control observations.

bg.ctl

bg background value used when plotting treatment observations.

pch.sup

pch point value used when plotting suppressed observations.

bg.sup

bg background value used when plotting suppressed observations.

col.sup

col color value used when plotting suppressed observations.

cex.sup

cex size value used when plotting suppressed observations.

legend.x

x value passed to legend. If NULL, legend plotting is skipped.

legend.y

Optional y value passed to legend

...

Optional graphical parameters.

Details

Produces various plots using objects fit by bartc. plot_sigma and plot_est are traditional parameter trace plots that can be used to diagnose the convergence of the posterior sampler. If the bartc model is fit with n.chains greater than one, by default each chain will be plotted with its own line type.

plot_indiv produces a simple histogram of the distribution of the estimates of the individual effects, taken as the average of their posterior samples.

plot_support is used to visualize the common support diagnostic in the form of a scatterplot. Points that the diagnostic excludes are outlined in red. The contents of the x and y axes are controlled by the xvar and yvar arguments respectively and can be of the form:

  • "tree.XX" - Variable number "XX" as selected by variable importance in predicting individual treatment effects using a tree fit by rpart. "XX" must be a number not exceeding the number of continuous variables used to fit the response model.

  • "pca.XX" - "XX"th principal component axis.

  • "css" - The common support statistic.

  • "y" - Observed response variable.

  • "y0" - Predicted values for the response under the control as obtained by fitted.

  • "y1" - Predicted values for the response under the treatment fitted.

  • "indiv.diff" - Individual treatment effect estimates, or \hat{y}(1) - \hat{y}(0).

  • "p.score" - Propensity score used to fit the response model (if applicable).

  • "p.weights" - Weights used when taking average of individual differences for response method "p.weight".

  • predictor columns - Given by name or number.

  • supplied vector - Any vector of length equal to the number of observations.

Value

None, although plotting occurs as a side-effect.

Author(s)

Vincent Dorie: vdorie@gmail.com.

See Also

bartc

Examples

# generate fake data using 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)

# run with low parameters only for example
fit <- bartc(y, z, x, n.samples = 100L, n.burn = 15L, n.chains = 2L,
             n.threads = 1L,
             commonSup.rule = "sd")


## plot specific functions

# sigma plot can be used to access convergence of chains
plot_sigma(fit)

# show points lacking common support
plot_support(fit, xvar = "tree.1", yvar = "css", legend.x = NULL)

# see example in ?"bartc-generics" for rank-ordered individual effects plot

vdorie/bartCause documentation built on May 3, 2023, 12:54 p.m.