Plot a coresynth model
Arguments
- x
A
coresynthobject.- type
One of
"trend"(observed vs synthetic),"gap"(ATT over time),"weights"(donor unit weight bar chart; SDID fits get a second panel with the time weight profile), or"pred_weights"(the predictor/variable weight matrix \(V\) as a bar chart; sharp SCM only).- colors
For
type = "trend": a named vector overriding series colors, e.g.c(treated = "black")(valid keys:"treated","synthetic", plus"donors"whenshow_donors > 0). Fortype = "gap": a single color string for the gap line. Ignored fortype = "weights"(usefillinstead).- labels
For
type = "trend": a named vector overriding the legend text of individual series, e.g.c(treated = "California")(valid keys:"treated","synthetic", plus"donors"whenshow_donors > 0). Series not mentioned keep their default label;colorsandlabelsaddress series by the same keys, independent of the displayed legend text. Ignored for other types (no legend).- vline
Aesthetic overrides for the vertical treatment-time line, as a list passed to
ggplot2::geom_vline()(e.g.list(color = "red")).NULLorFALSEhides the line entirely. The list may also carry anxinterceptelement giving one or more absolute positions on the time axis (e.g.list(xintercept = 1988), or a date string such as"1989-01-01"on aDateaxis), replacing the default treatment-time position; for placement relative to the treatment period usevline_offsetinstead. Applies to"trend"and"gap".- vline_offset
For
type = "trend"and"gap": where to draw the vertical treatment line, in periods relative to the first post-treatment period. The default0keeps the line at the first post-treatment period;-1moves it to the last pre-treatment period, and fractional values interpolate between adjacent observed times (-0.5is midway between the last pre- and first post-treatment period), which works on numeric,Date, andPOSIXctaxes alike. Cannot be combined with anxinterceptelement invline.- hline
Aesthetic overrides for the horizontal zero line in
type = "gap", as a list passed toggplot2::geom_hline().NULLorFALSEhides the line. Ignored for other types.- fill
For
type = "weights"andtype = "pred_weights": a single color string overriding the bar fill. Ignored for other types.- top_n
For
type = "weights": show only thetop_ndonors with the largest weights (defaultInfkeeps every donor with a non-negligible weight). Fortype = "pred_weights": show only thetop_npredictors with the largest \(V\) weights (defaultInfshows every predictor). Ignored for other types (and for the SDID time weight panel, which is always shown in full).- align
For
type = "trend"and"gap": whenTRUE, shift the synthetic series by its pre-treatment level gap to the treated series so that both are drawn on the same level. SDID matches trends only up to a free intercept, so its raw trend plot shows the synthetic control at a different level; withalign = TRUEthe offset is the time-weighted (\(\lambda\)) pre-period gap, which makes the average post-period gap in the plot equal the SDID estimate exactly. Other methods use the plain pre-period mean gap (usually a negligible shift, since they already match levels). DefaultFALSE(raw series).- show_donors
For
type = "trend": also draw the outcome paths of theshow_donorsdonor units with the largest weights as thin background lines (Infshows every donor). Requires a fit that stores donor unit weights and outcomes (sharp SCM/SDID/SI). Default0(no donor paths).- ...
Ignored.
Examples
set.seed(1)
panel <- expand.grid(unit = 1:10, year = 1:20)
panel$treated <- as.integer(panel$unit == 5 & panel$year > 15)
panel$gdp <- panel$unit + 0.5 * panel$year +
rnorm(nrow(panel)) + 3 * panel$treated
fit <- scm_fit(gdp ~ treated | unit + year, data = panel, method = "scm")
#> predictors = NULL: using the outcome in each of the 15 pre-treatment periods as predictors (outcomes-only SCM).
# \donttest{
plot(fit, type = "trend")
plot(fit, type = "gap")
plot(fit, type = "weights")
plot(fit, type = "weights", top_n = 5)
# Predictor (V) weights: which predictors the fit leans on
plot(fit, type = "pred_weights")
# Overlay the five largest donors behind the treated/synthetic series
plot(fit, type = "trend", show_donors = 5)
# SDID: align the synthetic series on the lambda-weighted pre-period level
fit_sdid <- scm_fit(gdp ~ treated | unit + year, data = panel, method = "sdid")
plot(fit_sdid, type = "trend", align = TRUE)
plot(fit_sdid, type = "gap", align = TRUE)
# Customize series colors, legend text, and reference lines
plot(fit, type = "trend",
colors = c(treated = "black"),
labels = c(treated = "Unit 5"),
vline = list(color = "red", linetype = "dashed"))
# Move the treatment line one period earlier (last pre-treatment period),
# pin it to an absolute time, or drop it entirely
plot(fit, type = "trend", vline_offset = -1)
plot(fit, type = "trend", vline = list(xintercept = 15.5))
plot(fit, type = "trend", vline = FALSE)
# }
