Plots parallel trends for given metrics.

plot_par_trends(
  data,
  metrics_and_names,
  treatment_status_var,
  time_var,
  conf_level = 0.95,
  non_negative = FALSE,
  display_CI = TRUE,
  output_format = "plot",
  smoothing_method = NULL,
  title_prefix = "Parallel Trends for",
  theme_use = causalverse::ama_theme()
)

Arguments

data

A data frame containing the data to plot.

metrics_and_names

A named list of metrics to plot.

treatment_status_var

The variable indicating treatment status.

time_var

The variable indicating time.

conf_level

Confidence level for confidence intervals (default is 0.95).

non_negative

Logical; if TRUE, sets negative lower confidence bounds to 0.

display_CI

Logical; if TRUE, displays confidence intervals.

output_format

Format of the output; "plot" returns a list of ggplots, "data.frame" returns a data frame.

smoothing_method

Method to use for smoothing; NULL means no smoothing.

title_prefix

A character string specifying the prefix for the plot title (default is "Parallel Trends for").

theme_use

Custom theme that follows ggplots2

Value

A list of ggplot objects or a data frame.

Examples

if (FALSE) {
library(tidyverse)
data <- expand.grid(entity = 1:100, time = 1:10) %>%
  dplyr::arrange(entity, time) %>%
  dplyr::mutate(
    treatment = ifelse(entity <= 50, "Treated", "Control"),
    outcome1 = 0.5 * time + rnorm(n(), 0, 2) + ifelse(treatment == "Treated", 0, 0),
    outcome2 = 3 + 0.3 * time + rnorm(n(), 0, 1) + ifelse(treatment == "Treated", 0, 2)
  )
results <- plot_par_trends(
  data = data,
  metrics_and_names = list(outcome1 = "Outcome 1", outcome2 = "Outcome 2"),
  treatment_status_var = "treatment",
  time_var = list(time = "Time"),
  smoothing_method = "loess"
)
library(gridExtra)
gridExtra::grid.arrange(grobs = results, ncol = 1)
}