| bayesianSynth | R Documentation |
A Bayesian Synthetic Control has raw data and draws from the posterior distribution. This is represented by an R6 Class.
public methods:
initialize() initializes the variables and model parameters
fit() fits the stan model and returns a fit object
updateWidth updates the width of the credible interval
placeboPlot generates a counterfactual placebo plot
effectPlot returns a plot of the treatment effect over time
summarizeLiftreturns descriptive statistics of the lift estimate
biasDraws returns a plot of the relative bias in a LFM
liftDraws returns a plot of the posterior lift distribution
liftBias returns a plot of the relative bias given a lift offset
Data structure:
vizdraws object with the relative bias with offset.
timeTilesggplot2 object that shows when the intervention happened.
plotDatareturns tibble with the observed outcome and the counterfactual data.
interventionTimereturns intervention time period (e.g., year) in which the treatment occurred.
syntheticreturns ggplot2 object that shows the observed and counterfactual outcomes over time.
checksreturns MCMC checks.
liftdraws from the posterior distribution of the lift.
new()Create a new bayesianSynth object.
bayesianSynth$new( data, time, id, treated, outcome, ci_width = 0.75, gp = FALSE, covariates = NULL, predictor_match = FALSE, predictor_match_covariates0 = NULL, predictor_match_covariates1 = NULL, vs = NULL )
dataLong data.frame object with fields outcome, time, id, and treatment indicator.
timeName of the variable in the data frame that identifies the time period (e.g. year, month, week etc).
idName of the variable in the data frame that identifies the units (e.g. country, region etc).
treatedName of the variable in the data frame that contains the treatment assignment of the intervention.
outcomeName of the outcome variable.
ci_widthCredible interval's width. This number is in the (0,1) interval.
gpLogical that indicates whether or not to include a Gaussian Process as part of the model.
covariatesData.frame with time dependent covariates for for each unit and time field. Defaults to NULL if no covariates should be included in the model.
predictor_matchLogical that indicates whether or not to run the matching version of the Bayesian Synthetic Control. This option can not be used with gp, covariates or multiple treated units.
predictor_match_covariates0data.frame with time independent covariates on each row and column indicating the control unit names (dim k x J+1).
predictor_match_covariates1Vector with time independent covariates for the treated unit (dim k x 1).
vsVector of weights for the importance of the predictors used in creating the synthetic control. Defaults to equal weight for all predictors.
A new bayesianSynth object.
fit()Fit Stan model.
bayesianSynth$fit(...)
...other arguments passed to rstan::sampling().
updateWidth()Update the width of the credible interval.
bayesianSynth$updateWidth(ci_width = 0.75)
ci_widthNew width for the credible interval. This number should be in the (0,1) interval.
summarizeLift()returns descriptive statistics of the lift estimate.
bayesianSynth$summarizeLift()
effectPlot()effect ggplot2 object that shows the effect of the intervention over time.
bayesianSynth$effectPlot(facet = TRUE, subset = NULL)
facetBoolean that is TRUE if we want to divide the plot for each unit.
subsetSet of units to use in the effect plot.
placeboPlot()Plot placebo intervention.
bayesianSynth$placeboPlot(periods, ...)
periodsPositive number of periods for the placebo intervention.
...other arguments passed to rstan::sampling().
ggplot2 object for placebo treatment effect.
biasDraws()Plots relative upper bias / tau for a time period (firstT, lastT).
bayesianSynth$biasDraws(small_bias = 0.3, firstT, lastT)
small_biasThreshold value for considering the bias "small".
firstTStart of the time period to compute relative bias over. Must be after the intervention.
lastTEnd of the time period to compute relative bias over. Must be after the intervention.
vizdraw object with the posterior distribution of relative bias. Bias is scaled by the time periods.
liftDraws()Plots lift.
bayesianSynth$liftDraws(from, to, ...)
fromFirst period to consider when calculating lift. If infinite, set to the time of the intervention.
toLast period to consider when calculating lift. If infinite, set to the last period.
...other arguments passed to vizdraws::vizdraws().
vizdraws object with the posterior distribution of the lift.
liftBias()Plot Bias magnitude in terms of lift for period (firstT, lastT) pre_MADs / y0 relative to lift thresholds.
bayesianSynth$liftBias(firstT, lastT, offset, ...)
firstTstart of the time period to compute relative bias over. They must be after the intervention.
lastTend of the Time period to compute relative bias over. They must be after the intervention.
offsetTarget lift %.
...other arguments passed to vizdraws::vizdraws().
weightDraws()Plot implicit weight distribution across draws.
bayesianSynth$weightDraws()
ggplot object with weight distribution per unit.
weightCorr()Plots correlations between weights across draws.
bayesianSynth$weightCorr()
ggplot heatmap object with correlations.
clone()The objects of this class are cloneable with this method.
bayesianSynth$clone(deep = FALSE)
deepWhether to make a deep clone.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.