| Title: | 'ggplot2'-Based Visualization for 'PanelMatch' (Imai, Kim, Wang 2023) Results |
|---|---|
| Description: | Provides 'ggplot2'-based plotting functions for 'PanelMatch' (Imai, Kim, Wang (2023) <doi:10.1111/ajps.12685>) results. Tidy-and-plot function pairs for three 'PanelMatch' outputs: treatment effect estimates (PanelEstimate()), placebo test diagnostics (placebo_test()), and covariate balance checks (get_covariate_balance()). Supports multiple models, significance indicators, faceted balance grids, and full 'ggplot2' extensibility. |
| Authors: | Jihye Park [aut, cre] |
| Maintainer: | Jihye Park <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-05-26 06:31:47 UTC |
| Source: | https://github.com/jacqpark/prettypanelmatch |
Produces a faceted covariate balance plot showing standardized mean differences across matching stages. Dependent variables are drawn as black solid lines; covariates as grey lines with distinct linetypes.
gg_covariate_balance( data, dv_color = "black", cov_color = "grey70", dv_linetype = "solid", cov_linetypes = NULL, hline = 0, ylim = c(-2, 2), xlab = "Time", ylab = "SD", title = NULL, subtitle = NULL, show_legend = FALSE, strip_text_y_size = 8.5, theme_fn = ggplot2::theme_bw ) ## S3 method for class 'ppm_cov_tidy' autoplot(object, ...)gg_covariate_balance( data, dv_color = "black", cov_color = "grey70", dv_linetype = "solid", cov_linetypes = NULL, hline = 0, ylim = c(-2, 2), xlab = "Time", ylab = "SD", title = NULL, subtitle = NULL, show_legend = FALSE, strip_text_y_size = 8.5, theme_fn = ggplot2::theme_bw ) ## S3 method for class 'ppm_cov_tidy' autoplot(object, ...)
data |
A |
dv_color |
Color for DV lines. Default |
cov_color |
Color for covariate lines. Default |
dv_linetype |
Linetype for DV lines. Default |
cov_linetypes |
Character vector of linetypes for covariates. If
|
hline |
Y-intercept for reference line. Default 0. Set to |
ylim |
Y-axis limits as a length-2 numeric vector. Default
|
xlab |
X-axis label. Default |
ylab |
Y-axis label. Default |
title |
Optional plot title. |
subtitle |
Optional plot subtitle. |
show_legend |
Logical. Show legend? Default |
strip_text_y_size |
Font size for row strip labels. Default 8.5.
Set to |
theme_fn |
A ggplot2 theme function. Default |
object |
A |
... |
Additional arguments passed to |
The default layout uses facet_grid(model ~ stage), where models
(different DVs / subsamples) form the rows and matching stages form the
columns, reproducing the standard PanelMatch covariate-balance diagnostic.
A ggplot object that can be further customized with
standard ggplot2 syntax.
pretty_covariate_balance to prepare the input data,
ggplot_panel_estimate for treatment effect plots,
gg_placebo_test for placebo test plots.
# Toy example (runs without PanelMatch) toy <- data.frame( model = factor("Model A", ordered = TRUE), stage = factor("Before matching", ordered = TRUE), time = factor(rep(paste0("t-", 3:1), 2), levels = paste0("t-", 3:1), ordered = TRUE), variable = factor(rep(c("outcome", "covar1"), each = 3), ordered = TRUE), estimate = c(0.3, 0.5, 0.8, -0.1, 0.2, 0.1), is_dv = rep(c(TRUE, FALSE), each = 3), stringsAsFactors = FALSE ) class(toy) <- c("ppm_cov_tidy", "data.frame") gg_covariate_balance(toy)# Toy example (runs without PanelMatch) toy <- data.frame( model = factor("Model A", ordered = TRUE), stage = factor("Before matching", ordered = TRUE), time = factor(rep(paste0("t-", 3:1), 2), levels = paste0("t-", 3:1), ordered = TRUE), variable = factor(rep(c("outcome", "covar1"), each = 3), ordered = TRUE), estimate = c(0.3, 0.5, 0.8, -0.1, 0.2, 0.1), is_dv = rep(c(TRUE, FALSE), each = 3), stringsAsFactors = FALSE ) class(toy) <- c("ppm_cov_tidy", "data.frame") gg_covariate_balance(toy)
Produces a customizable ggplot2 coefficient plot for placebo test estimates
from the PanelMatch package. This is a convenience wrapper around
ggplot_panel_estimate with defaults tailored for placebo tests
(e.g., y-axis label set to "Placebo estimate").
gg_placebo_test(data, ylab = "Placebo estimate", ...) ## S3 method for class 'ppm_placebo_tidy' autoplot(object, ...)gg_placebo_test(data, ylab = "Placebo estimate", ...) ## S3 method for class 'ppm_placebo_tidy' autoplot(object, ...)
data |
A |
ylab |
Y-axis label. Default |
... |
Additional arguments passed to |
object |
A |
All arguments are passed through to ggplot_panel_estimate(), so
the full range of customization (shapes, dodging, significance coding,
faceting, themes) is available.
A ggplot object.
pretty_placebo_test to prepare the input data,
ggplot_panel_estimate for treatment effect plots.
# Toy example (runs without PanelMatch) toy <- data.frame( term = factor(paste0("t-", 3:1), levels = paste0("t-", 3:1), ordered = TRUE), estimate = c(0.1, -0.05, 0.02), std.error = c(0.15, 0.12, 0.10), conf.low = c(-0.19, -0.29, -0.18), conf.high = c(0.39, 0.19, 0.22), label = factor("Model", ordered = TRUE), signif = c("Non-signif", "Non-signif", "Non-signif"), stringsAsFactors = FALSE ) class(toy) <- c("ppm_placebo_tidy", "data.frame") gg_placebo_test(toy)# Toy example (runs without PanelMatch) toy <- data.frame( term = factor(paste0("t-", 3:1), levels = paste0("t-", 3:1), ordered = TRUE), estimate = c(0.1, -0.05, 0.02), std.error = c(0.15, 0.12, 0.10), conf.low = c(-0.19, -0.29, -0.18), conf.high = c(0.39, 0.19, 0.22), label = factor("Model", ordered = TRUE), signif = c("Non-signif", "Non-signif", "Non-signif"), stringsAsFactors = FALSE ) class(toy) <- c("ppm_placebo_tidy", "data.frame") gg_placebo_test(toy)
Produces a customizable ggplot2 coefficient plot showing point estimates and confidence intervals across lead periods. Supports multiple models with dodged positions and significance-based shape coding (hollow = not significant, filled = significant). A footnote is added by default.
ggplot_panel_estimate( data, dodge_width = 0.5, point_size = 2.2, errorbar_alpha = 0.5, errorbar_width = 0, shapes = NULL, show_signif_shapes = TRUE, legend_labels = NULL, footnote = "Filled markers denote statistical significance (CI excludes zero).", footnote_size = NULL, xlab = "Time", ylab = "ATT", title = NULL, subtitle = NULL, hline = 0, facet_by = NULL, theme_fn = ggplot2::theme_minimal ) ## S3 method for class 'ppm_tidy' autoplot(object, ...)ggplot_panel_estimate( data, dodge_width = 0.5, point_size = 2.2, errorbar_alpha = 0.5, errorbar_width = 0, shapes = NULL, show_signif_shapes = TRUE, legend_labels = NULL, footnote = "Filled markers denote statistical significance (CI excludes zero).", footnote_size = NULL, xlab = "Time", ylab = "ATT", title = NULL, subtitle = NULL, hline = 0, facet_by = NULL, theme_fn = ggplot2::theme_minimal ) ## S3 method for class 'ppm_tidy' autoplot(object, ...)
data |
A |
dodge_width |
Width of position dodge for multiple models. Default 0.5. |
point_size |
Size of point estimates. Default 2.2. |
errorbar_alpha |
Alpha transparency for error bars. Default 0.5. |
errorbar_width |
Width of error bar caps. Default 0 (no caps). |
shapes |
A character vector of hollow shape names, one per model.
Filled counterparts are paired automatically. If |
show_signif_shapes |
Logical. If |
legend_labels |
Optional character vector to override legend labels (one per model, in input order). |
footnote |
Character string for the significance footnote. Set to
|
footnote_size |
Font size for the footnote. Default |
xlab |
X-axis label. Default |
ylab |
Y-axis label. Default |
title |
Optional plot title. |
subtitle |
Optional plot subtitle. |
hline |
Intercept for reference line. Default 0. Set to |
facet_by |
Optional variable name to facet by (e.g., |
theme_fn |
A ggplot2 theme function. Default |
object |
A |
... |
Additional arguments passed to |
The returned object is a standard ggplot object, so you can add
any ggplot2 layers, scales, or themes on top of it.
A ggplot object that can be further customized with
standard ggplot2 syntax.
tidy_panel_estimate to prepare the input data,
gg_placebo_test for placebo test plots,
gg_covariate_balance for covariate balance plots.
# Toy example (runs without PanelMatch) toy <- data.frame( term = factor(paste0("t+", 0:2), levels = paste0("t+", 0:2), ordered = TRUE), estimate = c(0.5, 0.8, 1.2), std.error = c(0.2, 0.3, 0.25), conf.low = c(0.1, 0.2, 0.7), conf.high = c(0.9, 1.4, 1.7), label = factor("Model", ordered = TRUE), signif = c("Non-signif", "Signif", "Signif"), stringsAsFactors = FALSE ) class(toy) <- c("ppm_tidy", "data.frame") ggplot_panel_estimate(toy)# Toy example (runs without PanelMatch) toy <- data.frame( term = factor(paste0("t+", 0:2), levels = paste0("t+", 0:2), ordered = TRUE), estimate = c(0.5, 0.8, 1.2), std.error = c(0.2, 0.3, 0.25), conf.low = c(0.1, 0.2, 0.7), conf.high = c(0.9, 1.4, 1.7), label = factor("Model", ordered = TRUE), signif = c("Non-signif", "Signif", "Signif"), stringsAsFactors = FALSE ) class(toy) <- c("ppm_tidy", "data.frame") ggplot_panel_estimate(toy)
Converts get_covariate_balance() matrices from the PanelMatch package
into a single tidy data frame suitable for ggplot2 plotting.
pretty_covariate_balance( ..., stage_labels = c("Before matching", "Matched, pre-refinement", "Post-refinement"), dv = NULL )pretty_covariate_balance( ..., stage_labels = c("Before matching", "Matched, pre-refinement", "Post-refinement"), dv = NULL )
... |
Named arguments where each value is a list of matrices from
|
stage_labels |
Character vector naming the matching stages, in order.
Must be at least as long as the longest list of matrices provided.
Default: |
dv |
Character vector of variable names that are dependent variables. These are styled differently (black solid lines) in the plot. Variables not listed here are treated as covariates (grey, varied linetypes). |
Each named argument should be a list of 1–3 matrices (one per matching stage, e.g., before matching, after matching pre-refinement, post-refinement). The argument names become model/row facet labels.
A data frame (with class "ppm_cov_tidy") containing:
Model label (ordered factor, row facet)
Matching stage label (ordered factor, column facet)
Pre-treatment period label (ordered factor, e.g., "t-3")
Covariate or DV name (ordered factor)
Standardized mean difference
Logical; TRUE for dependent variables
gg_covariate_balance to plot the result,
tidy_panel_estimate for treatment effect estimates,
pretty_placebo_test for placebo test results.
# Create a mock covariate balance matrix (rows = time, cols = variables) mat <- matrix( c(0.3, -0.1, 0.5, 0.2, 0.8, 0.1), nrow = 3, dimnames = list(NULL, c("outcome", "covar1")) ) pretty_covariate_balance( "My Model" = mat, stage_labels = "Before matching", dv = "outcome" )# Create a mock covariate balance matrix (rows = time, cols = variables) mat <- matrix( c(0.3, -0.1, 0.5, 0.2, 0.8, 0.1), nrow = 3, dimnames = list(NULL, c("outcome", "covar1")) ) pretty_covariate_balance( "My Model" = mat, stage_labels = "Before matching", dv = "outcome" )
Converts one or more placebo_test() results from the PanelMatch
package into a single tidy data frame suitable for ggplot2 plotting.
pretty_placebo_test(..., labels = NULL, confidence_level = 0.95)pretty_placebo_test(..., labels = NULL, confidence_level = 0.95)
... |
One or more |
labels |
A character vector of labels, one per result. If |
confidence_level |
Confidence level for constructing intervals. Default 0.95. |
A data frame (with class "ppm_placebo_tidy") containing:
Lag period label (e.g., "t-3", "t-2")
Point estimate
Standard error
Lower confidence bound
Upper confidence bound
Model label (ordered factor preserving input order)
Whether the CI excludes zero ("Signif" or "Non-signif")
gg_placebo_test to plot the result,
tidy_panel_estimate for treatment effect estimates,
pretty_covariate_balance for covariate balance.
# Create a mock placebo_test result pt <- list( estimates = c("t-3" = 0.10, "t-2" = -0.05, "t-1" = 0.02), standard.errors = c("t-3" = 0.15, "t-2" = 0.12, "t-1" = 0.10) ) pretty_placebo_test(pt, labels = "My Model") # Custom confidence level pretty_placebo_test(pt, confidence_level = 0.90)# Create a mock placebo_test result pt <- list( estimates = c("t-3" = 0.10, "t-2" = -0.05, "t-1" = 0.02), standard.errors = c("t-3" = 0.15, "t-2" = 0.12, "t-1" = 0.10) ) pretty_placebo_test(pt, labels = "My Model") # Custom confidence level pretty_placebo_test(pt, confidence_level = 0.90)
Converts one or more summary(PanelEstimate(...)) objects into a
single tidy data frame suitable for ggplot2 plotting.
tidy_panel_estimate(..., labels = NULL)tidy_panel_estimate(..., labels = NULL)
... |
One or more PanelEstimate summary objects (or raw PanelEstimate objects, which will be summarized automatically). Can also be a single named list of summaries. |
labels |
A character vector of labels, one per summary. Used to
distinguish models in the plot legend. If |
A data frame (with class "ppm_tidy") containing columns:
Lead period label (e.g., "t+0", "t+1", ...)
Point estimate (ATT)
Standard error
Lower confidence bound
Upper confidence bound
Model label (ordered factor preserving input order)
Whether the CI excludes zero ("Signif" or "Non-signif")
ggplot_panel_estimate to plot the result,
pretty_placebo_test for placebo test results,
pretty_covariate_balance for covariate balance.
# Create a mock PanelEstimate summary (matrix with 4 columns) pe_sum <- matrix( c(0.5, 0.2, 0.1, 0.9, 0.8, 0.3, 0.2, 1.4, 1.2, 0.25, 0.7, 1.7), nrow = 3, byrow = TRUE, dimnames = list(NULL, c("Estimate", "Std.Error", "lower", "upper")) ) tidy_panel_estimate(pe_sum, labels = "My Model") # Multiple models with named arguments pe_sum2 <- matrix( c(0.3, 0.15, 0.0, 0.6, 0.6, 0.20, 0.2, 1.0, 0.9, 0.18, 0.5, 1.3), nrow = 3, byrow = TRUE, dimnames = list(NULL, c("Estimate", "Std.Error", "lower", "upper")) ) tidy_panel_estimate("Model A" = pe_sum, "Model B" = pe_sum2)# Create a mock PanelEstimate summary (matrix with 4 columns) pe_sum <- matrix( c(0.5, 0.2, 0.1, 0.9, 0.8, 0.3, 0.2, 1.4, 1.2, 0.25, 0.7, 1.7), nrow = 3, byrow = TRUE, dimnames = list(NULL, c("Estimate", "Std.Error", "lower", "upper")) ) tidy_panel_estimate(pe_sum, labels = "My Model") # Multiple models with named arguments pe_sum2 <- matrix( c(0.3, 0.15, 0.0, 0.6, 0.6, 0.20, 0.2, 1.0, 0.9, 0.18, 0.5, 1.3), nrow = 3, byrow = TRUE, dimnames = list(NULL, c("Estimate", "Std.Error", "lower", "upper")) ) tidy_panel_estimate("Model A" = pe_sum, "Model B" = pe_sum2)