plot_microsynth: Plotting for microsynth objects.

View source: R/plot_microsynth.R

plot_microsynthR Documentation

Plotting for microsynth objects.

Description

Using a microsynth object as an input, this function gives time series plots of selected outcomes.

Usage

plot_microsynth(
  ms,
  plot.var = NULL,
  start.pre = NULL,
  end.pre = NULL,
  end.post = NULL,
  file = NULL,
  sep = TRUE,
  plot.first = NULL,
  legend.spot = "bottomleft",
  height = NULL,
  width = NULL,
  at = NULL,
  labels = NULL,
  all = "cases",
  main.tc = NULL,
  main.diff = NULL,
  xlab.tc = NULL,
  xlab.diff = NULL,
  ylab.tc = NULL,
  ylab.diff = NULL
)

Arguments

ms

A microsynth object

plot.var

A vector of variable names giving the outcome variables that are shown in plots. If plot.var = NULL, all outcome variables that are included in ms are plotted. Only variables contained in the input result.var as used in the creation of ms can be plotted using plot().

start.pre

An integer indicating the time point that corresponds to the earliest time period that will be plotted. When start.pre = NULL, it is reset to the minimum time appearing in ms.

end.pre

An integer that gives the final time point of the pre-intervention period. That is, end.pre is the last time at which treatment and synthetic control will were matched to one another. All time points following end.pre are considered to be post-intervention and the behavior of outcomes will be compared between the treatment and synthetic control groups across those time periods. If end.pre = NULL the end of the pre-intervention period will be determined from the object ms.

end.post

An integer that gives final time point that will be plotted. When end.post = NULL (the default), it is reset to the maximum time that appears in ms.

file

A character string giving the name of file that will be created in the home directory containing plots. The name should have a .pdf extension.

sep

If sep = TRUE, separate plots will be generated for each outcome. Applicable only if plots are saved to file ( plot.file is non-NULL). To change display of plots produced as output, use par.

plot.first

The number of permutation groups to plot.

legend.spot

The location of the legend in the plots.

height

The height of the graphics region (in inches) when a pdf is created.

width

The width of the graphics region (in inches) when a pdf is created.

at

A vector that gives the location of user-specified x-axis labels. at should be a (numeric) subset of the named time points contained in ms (e.g., colnames(ms$Plot.Stats$Treatment)).

labels

A vector of the same length as at that gives the names of the labels that will be marked at the times indicated by at in the plots.

all

A scalar character string giving the unit name for cases. If NULL, a third curve showing the overall outcome levels is not plotted.

main.tc

A scalar (or a vector of the same length as plot.var) character string giving the title to be used for the first plots (that show treatment and control). Defaults to plot.var.

main.diff

A scalar (or a vector of the same length as plot.var) character string giving the title to be used for the second plots (that show differences between treatment and control). Defaults to plot.var.

xlab.tc

A scalar (or a vector of the same length as plot.var) character string giving the x-axis labels to be used for the first plots (that show treatment and control). Defaults to ''.

xlab.diff

A scalar (or a vector of the same length as plot.var) character string giving the x-axis labels to be used for the second plots (that show differences between treatment and control). Defaults to ''.

ylab.tc

A scalar (or a vector of the same length as plot.var) character string giving the y-axis labels to be used for the first plots (that show treatment and control). Defaults to plot.var.

ylab.diff

A scalar (or a vector of the same length as plot.var) character string giving the y-axis labels to be used for the second plots (that show differences between treatment and control). Defaults to 'Treatment - Control'.

Details

Plots are given over both pre- and intervention time periods and shown in terms of raw outcome values or treatment/control differences. Time series of permutation groups may be overlaid to help illustrate statistical uncertainty.

Only required input is a parameter ms which is a microsynth object.

Value

No return value, called for side effects (i.e., to produce plots of outcome values and treatment/control differences, with the option to write to file).

Examples


# Declare time-variant (outcome) and time-invariant variables for matching
cov.var <- c('TotalPop', 'BLACK', 'HISPANIC', 'Males_1521',
       'HOUSEHOLDS', 'FAMILYHOUS', 'FEMALE_HOU', 'RENTER_HOU', 'VACANT_HOU')

match.out <- c('i_felony', 'i_misdemea', 'i_drugs', 'any_crime')

set.seed(99199) # for reproducibility



# Perform matching and estimation, without permutations or jackknife
# runtime: <1 min
sea1 <- microsynth(seattledmi,
                  idvar='ID', timevar='time', intvar='Intervention',
                  start.pre=1, end.pre=12, end.post=16,
                  match.out=match.out, match.covar=cov.var,
                  result.var=match.out, omnibus.var=match.out,
                  test='lower',
                  n.cores = min(parallel::detectCores(), 2))

# Plot with default settings in the GUI.
plot_microsynth(sea1)

# Make plots, display, and save to a single file (plots.pdf).
plot_microsynth(sea1, file = file.path(tempdir(), 'plots.pdf'), sep = FALSE)

# Make plots for only one outcome, display, and save to a single file.
plot_microsynth(sea1, plot.var = 'any_crime',
     file = file.path(tempdir(), 'plots.pdf'), sep = FALSE)



microsynth documentation built on July 9, 2023, 5:53 p.m.