stratification_plot: Stratification Plot

View source: R/stratification_plot.R

stratification_plotR Documentation

Stratification Plot

Description

Stratification Plot

Usage

stratification_plot(
  ps,
  treatment,
  outcome,
  n_strata = 5,
  level = 0.68,
  colors = c("#fc8d62", "#66c2a5"),
  se_color = "grey80",
  xlab = "Propensity Score",
  ylab = "Outcome",
  treat_lab = "Treatment",
  plot_points = TRUE,
  plot_strata = TRUE,
  label_strata = TRUE
)

Arguments

ps

vector of propensity scores.

treatment

vector of treatment indicators.

outcome

vector of outcome values.

n_strata

number of strata to use.

level

Level of confidence interval to use. Set to NULL to exclude. The default is 0.68 (for 1 standard error) since the primary purpose is to compare overlap between the two lines. See this article for more details: https://towardsdatascience.com/why-overlapping-confidence-intervals-mean-nothing-about-statistical-significance-48360559900a

colors

vector of colors to use for control and treatment, respectively.

se_color

color for the standard error bars.

xlab

label for the x-axis.

ylab

label for the y-axis.

treat_lab

label for the legend.

plot_points

whether to plot the individual points.

plot_strata

whether to plot the vertical lines for the strata.

label_strata

whether the strata should be labeled (as letters).

Value

a ggplot2 expression.

Examples

if(require(Matching)) {
data(lalonde, package = 'Matching')
lr_out <- glm(treat ~ age + I(age^2) + educ + I(educ^2) + black + 
              hisp + married + nodegr + re74  + I(re74^2) + re75 + I(re75^2) +
              u74 + u75,
			  data = lalonde, 
			  family = binomial(link = 'logit'))
lalonde$ps <- fitted(lr_out)
stratification_plot(ps = lalonde$ps,
					treatment = lalonde$treat,
					outcome = log(lalonde$re78 + 1),
					n_strata = 5)
}

jbryer/psa documentation built on Nov. 17, 2023, 8:21 a.m.