plot_par_trends.Rd
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()
)
A data frame containing the data to plot.
A named list of metrics to plot.
The variable indicating treatment status.
The variable indicating time.
Confidence level for confidence intervals (default is 0.95).
Logical; if TRUE, sets negative lower confidence bounds to 0.
Logical; if TRUE, displays confidence intervals.
Format of the output; "plot" returns a list of ggplots, "data.frame" returns a data frame.
Method to use for smoothing; NULL means no smoothing.
A character string specifying the prefix for the plot title (default is "Parallel Trends for").
Custom theme that follows ggplots2
A list of ggplot objects or a data frame.
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)
}