plot.apm_pre_fits {apm} | R Documentation |
Plot outputs of apm_pre()
Description
plot()
displays the Bayesian model averaging (BMA) weights for each model (computed by apm_fit()
as the posterior probability of selection) and the distribution of the difference in average prediction errors.
Usage
## S3 method for class 'apm_pre_fits'
plot(
x,
type = "weights",
abs = TRUE,
ncol = 4L,
clip_at = 15,
model = ".optimal",
...
)
Arguments
x |
an |
type |
which values to plot: allowable options include |
abs |
|
ncol |
when |
clip_at |
when |
model |
string; when |
... |
ignored. |
Details
When type = "weights"
, plot()
displays a bar plot with a bar for each model with height equal to the BMA weight/posterior probability of selection for that model. (Note that the plot margins can sometimes cut off the model names; use theme(plot.margins =)
after loading ggplot2
to extend the left margin of the plot to ensure all text is visible. Alternatively, the axis text can be rotated using theme(axis.text.x =)
.)
When type = "errors"
, plot()
displays a lattice of bar plots with a plot for each model displaying the difference in average prediction errors for each validation period. The period with the largest difference in average prediction errors will be shaded black. The model with the smallest maximum absolute difference in average prediction errors will have a gray label.
When type = "predict"
, plot()
displays a lattice of line plots with a plot for each model displaying the observed and predicted outcomes for each validation period under each model. The observed outcomes are displayed as points, while the predicted outcomes are displayed as lines.
When type = "corrected"
, plot()
displays a lattice of line plots with a plot for each model displaying the observed and corrected predictions for the treated group for each validation period under each model. The observed outcomes are displayed as points, while the corrected predictions are displayed as lines. Corrected predictions are computed as the observed outcome in the treated group minus the prediction error in the treated group plus the prediction error in the control group.
Value
A ggplot
object, which can be manipulated using ggplot2
syntax (after loading ggplot2
).
See Also
apm_pre()
to to compute the difference in average prediction errors and BMA weights; ggplot2::geom_col()
, which is used to create the plots.
Examples
data("ptpdata")
# Combination of 8 models: 2 baseline formulas,
# 2 families, 2 lags
models <- apm_mod(crude_rate ~ 1,
family = "gaussian",
time_trend = 0:1,
lag = 0:1,
diff_k = 0:1)
models
# Fit the models to data
fits <- apm_pre(models, data = ptpdata,
group_var = "group",
time_var = "year",
val_times = 1999:2007,
unit_var = "state",
nsim = 50,
verbose = FALSE)
fits
plot(fits, type = "weights")
plot(fits, type = "error", ncol = 2)
plot(fits, type = "predict", model = ".optimal")
plot(fits, type = "corrected", model = ".optimal")