matching_plot: Propensity score matching plot

View source: R/matching_plot.R

matching_plotR Documentation

Propensity score matching plot

Description

Propensity score matching plot

Usage

matching_plot(
  ps,
  treatment,
  outcome,
  index_treated,
  index_control,
  null_hypothesis = 0,
  method = "loess",
  se = TRUE,
  level = 0.95,
  percent_matches = 1,
  colors = c("#fc8d62", "#66c2a5"),
  xlab = "Propensity Score",
  ylab = "Outcome",
  treat_lab = "Treatment",
  plot_points = TRUE
)

Arguments

ps

vector of propensity scores.

treatment

vector of treatment indicators.

outcome

vector of outcome values.

index_treated

the positions of treated matched pairs.

index_control

the positions of control matched pairs.

null_hypothesis

the value of the null hypothesis (typically zero). A horizontal line will be drawn to compare with regression line.

method

the method to use for the regression line. Typically loess, gan, or lm.

se

Display confidence interval around smooth? (TRUE by default, see level to control.)

level

Level of confidence interval to use (0.95 by default).

percent_matches

the percentage of matches to plot. Set to one to connect all matches.

colors

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

xlab

label for the x-axis.

ylab

label for the y-axis.

treat_lab

label for the legend of group colors.

plot_points

whether to plot the individual points.

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)
match_out <- Matching::Match(Y = lalonde$re78,
							 Tr = lalonde$treat,
							 X = lalonde$ps,
							 caliper = 0.1,
							 replace = FALSE,
							 estimand = 'ATE')
matching_plot(ps = lalonde$ps,
			  treatment = lalonde$treat,
			  outcome = log(lalonde$re78 + 1),
			  index_treated = match_out$index.treated,
			  index_control = match_out$index.control)
}

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