MyNixOS website logo
Description

'ggplot2'-Based Visualization for 'PanelMatch' (Imai, Kim, Wang 2023) Results.

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.

prettyPanelMatch

ggplot2-based plotting for PanelMatch (Imai et al. 2023) results. Tidy-and-plot function pairs for treatment effect estimates, placebo tests, and covariate balance diagnostics.

Install

devtools::install_github("jacqpark/prettyPanelMatch")

Functions

TidyPlotInput
tidy_panel_estimate()ggplot_panel_estimate()PanelEstimate summaries
pretty_placebo_test()gg_placebo_test()placebo_test() results
pretty_covariate_balance()gg_covariate_balance()get_covariate_balance() matrices

All plot functions return standard ggplot objects.

Usage

Treatment Effect Estimates

library(prettyPanelMatch)

# Step 1: Tidy — pass all summaries at once, with labels
combined <- tidy_panel_estimate(
  "Energy Dept." = summary(pe.results_e1[[1]]),
  "State Dept."  = summary(pe.results_e2[[1]]),
  "Congress"     = summary(pe.results_e3[[1]]),
  "EOP"          = summary(pe.results_e4[[1]])
)

# Step 2: Plot
ggplot_panel_estimate(combined)

Shapes

Hollow shapes indicate non-significant estimates; filled counterparts are auto-paired for significant ones. The legend only shows hollow shapes, with a footnote explaining the convention.

Choose shapes by name: "circle", "square", "triangle", "diamond", "triangle_down".

ggplot_panel_estimate(combined, shapes = c("circle", "diamond", "triangle", "square"))

Customization (it's just ggplot2)

# Custom axis labels
ggplot_panel_estimate(combined, xlab = "Time (in years)", ylab = "Estimate")

# Add title, move legend
ggplot_panel_estimate(combined) +
  ggtitle("Effect of ENG Lobbying on Energy Outcomes") +
  theme(legend.position = "bottom")

# Faceted layout
ggplot_panel_estimate(combined, facet_by = "label")

# Custom theme
ggplot_panel_estimate(combined, theme_fn = theme_bw)

# Suppress significance footnote
ggplot_panel_estimate(combined, footnote = NULL)

# Single model (legend hidden by default)
t1 <- tidy_panel_estimate(summary(pe_results), labels = "My Model")
ggplot_panel_estimate(t1)

# autoplot method
autoplot(combined)

Placebo Tests

# Step 1: Tidy — pass placebo_test() results with labels
pt_combined <- pretty_placebo_test(
  "Congress Finance" = placebo_test(pm.sets_cngFINfin, ...),
  "Treasury Finance" = placebo_test(pm.sets_trsFINfin, ...)
)

# Step 2: Plot
gg_placebo_test(pt_combined)

# Custom confidence level (default 95%)
pt_90 <- pretty_placebo_test(pt_result, confidence_level = 0.90)

# All ggplot_panel_estimate options work here too
gg_placebo_test(pt_combined, shapes = c("circle", "diamond"), facet_by = "label")

Covariate Balance

Each matrix comes from get_covariate_balance() at a different matching stage. The three stages are: (1) before matching (matching = FALSE, equal weights), (2) after matching but before refinement (equal weights), and (3) after refinement (e.g., CBPS weights).

# Create PanelMatch objects for each stage
pm_nomatch <- PanelMatch(..., matching = FALSE)
pm_matched <- PanelMatch(...) # matching = TRUE by default

# Extract covariate balance matrices
cov_nomatch <- get_covariate_balance(
  pm_nomatch$att, data, covariates = c("congress_fin", "total_mna_us", "total_mna_out", "lobby_nofin"),
  use.equal.weights = TRUE
)
cov_matched <- get_covariate_balance(
  pm_matched$att, data, covariates = c("congress_fin", "total_mna_us", "total_mna_out", "lobby_nofin"),
  use.equal.weights = TRUE
)
cov_refined <- get_covariate_balance(
  pm_matched$att, data, covariates = c("congress_fin", "total_mna_us", "total_mna_out", "lobby_nofin")
)

Each matrix has rows = pre-treatment lag periods and columns = covariates:

> cov_nomatch
    congress_fin total_mna_us total_mna_out lobby_nofin
t_3   -0.2846367    0.5766951  -0.001516477   0.2557049
t_2    0.1935971    0.4932559   0.150367858   0.2818383
t_1    0.2256210    0.1864485   0.758113347   0.3218909

Pass these matrices to pretty_covariate_balance() as a list per model:

# Step 1: Tidy — each named argument is a model, with a list of matrices
#   (one per matching stage: before matching, matched pre-refinement, post-refinement)
cov_data <- pretty_covariate_balance(
  "Cong-FIN; US finan" = list(cov_nomatch, cov_matched, cov_refined),
  "Cong-FIN; US banks" = list(cov_nomatch2, cov_matched2, cov_refined2),
  "Cong-BAN; US finan" = list(cov_nomatch3, cov_matched3, cov_refined3),
  dv = c("congress_fin", "congress_ban")
)

# Step 2: Plot — facet_grid(model ~ stage), DVs black/solid, covariates grey/dashed
gg_covariate_balance(cov_data)

# Custom stage labels
pretty_covariate_balance(
  "My Model" = list(mat1, mat2),
  stage_labels = c("Unmatched", "Matched"),
  dv = "outcome_var"
)

# Customize appearance
gg_covariate_balance(cov_data,
  dv_color = "darkblue", cov_color = "grey50",
  ylim = c(-3, 3), show_legend = TRUE
)

# Add a vertical line at the last pre-treatment period
gg_covariate_balance(cov_data) +
  geom_vline(xintercept = 3, lty = "dashed")
Metadata

Version

0.2.0

License

Unknown

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows