Learn R Programming

optinterv (version 0.1.0)

plot_change: Plot the change in the distribution of X

Description

Illustrates how the intervention changes the distribution of X by plotting barchart (for categorical variables) or denisty plot (for continouous variables), before and after the intervention.

Usage

plot_change(x, plot.vars = "sig", graph.col = c("red", "blue"),
  alpha = 0.05, line.type = c(1, 2), n.val = 10)

Arguments

x

an optint object.

plot.vars

which variables to plot? either a number (n) - indicating to plot the first n variables, "sig" (default) - plot only significant variables, or a vector with names of variables to plot.

graph.col

graph color/s.

alpha

significance level for the confidence intervals. also used in order to determine which variables are significant.

line.type

line type for densityplot

n.val

variable with more values than 'n.val' will be displayed by density plot, while variable with fewer values will be displayed by barchart.

Examples

Run this code
# NOT RUN {
# generate data
n <- 50
p <- 3
features <- matrix(rnorm(n*p), ncol = p)
men <- matrix(rbinom(n, 1, 0.5), nrow = n)
outcome <- 2*(features[,1] > 1) + men*pmax(features[,2], 0) + rnorm(n)
outcome <- as.vector(outcome)

#find the optimal intervention using the non-parametric method:
imp_feat <- optint(Y = outcome, X = features, control = men,
                   method = "non-parametric", lambda = 10, plot = TRUE,
                   n.boot = 100, n.perm = 100)

#we can look on the new features distribution more deeply, using plot_change():
plot_change(imp_feat, plot.vars = "sig")
# }

Run the code above in your browser using DataLab