A class for creating and managing Bayesian Logit Models
versionim package version used to fit model
tau_drawsPosterior draws for the treatment effect
mcmChecksMCMC diagnostics
credible_intervalCredible interval for the treatment effect
prior_etaPrior distribution for eta
prior_tauPrior distribution for tau
prior_mean_yPrior distribution for mean y
eta_drawsPosterior draws for eta
predict_listList of predictions
new()Get the package version
Get the posterior draws for tau
Get the MCMC diagnostics
Get the credible interval
Get the prior for eta
Get the prior for tau
Get the prior for mean y
Get the posterior draws for eta
Get the list of predictions
Create a new Bayesian Logit Model object.
logit$new(
data,
y,
x,
treatment,
mean_alpha,
sd_alpha,
mean_beta,
sd_beta,
tau_mean,
tau_sd,
seed = 1982,
fit = TRUE,
...
)dataData frame to be used
yName of the outcome variable in the data frame
xVector of names of all covariates in the data frame
treatmentName of the treatment indicator variable in the data frame
mean_alphaPrior mean for alpha
sd_alphaPrior standard deviation for alpha
mean_betaPrior mean for beta
sd_betaPrior standard deviation for beta
tau_meanPrior mean for the treatment effect estimation
tau_sdPrior standard deviation for the treatment effect estimation
seedSeed for Stan fitting
fitFlag for fitting the data to the model or not
...Additional arguments for Stan
invisible
tracePlot()Plot MCMC trace for the eta and sigma parameters.
logit$tracePlot(...)...Additional arguments for Stan
A ggplot object.
calcProb()Calculates the posterior of an effect being greater than, less than, or within a range defined by thresholds.
logit$calcProb(a = 0, b = NULL, prior = FALSE)aOptional. Lower bound for the threshold.
bOptional. Upper bound for the threshold.
priorLogical. If TRUE, calculates probabilities based on the prior distribution. If FALSE (default), uses the posterior distribution.
xA numeric vector containing draws from the posterior
A character string summarizing the estimated probability
Calculate point estimate of the effect
This R6 method calculates the point estimate of the effect size based on the posterior draws of the eta parameter.
pointEstimate()logit$pointEstimate(median = TRUE)medianLogical value. If TRUE (default), the median of the eta draws is returned. If FALSE, the mean is returned.
This method uses the private$..eta_draws internal variable which contains MCMC draws of the eta parameter representing the effect size. Based on the specified median argument, the method calculates and returns either the median or the mean of the draws. Calculates credible interval for the effect of the intervention
This R6 method calculates and returns a formatted statement summarizing the credible interval of a specified width for the effect of the intervention.
A numeric value representing the point estimate.
credibleInterval()logit$credibleInterval(width = 0.75, round = 0)widthNumeric value between 0 and 1 representing the desired width of the credible interval (e.g., 0.95 for a 95% credible interval).
roundInteger value indicating the number of decimal places to round the lower and upper bounds of the credible interval.
This method uses the private$..eta_draws internal variable containing MCMC draws of the eta parameter representing the effect size. It calculates the credible interval, stores it internally, and returns a formatted statement summarizing the findings.
A character string with the following information:
The probability associated with the specified width
The lower and upper bounds of the credible interval, rounded to the specified number of decimal places
vizdraws()Plots impact's prior and posterior distributions.
logit$vizdraws(tau = FALSE, ...)tauLogical. If TRUE, plot tau instead of eta
...other arguments passed to vizdraws.
An interactive plot of the prior and posterior distributions.
lollipop()Plots lollipop chart for the prior and posterior of the impact being greater or less than a threshold.
For more details see vizdraws::lollipops().
logit$lollipop(threshold = 0, ...)thresholdcutoff used to calculate the probability. Defaults to zero percent points
...other arguments passed to vizdraws.
A lollipop chart with the prior and posterior probability of the impact being above or below a threshold.
plotPrior()Plots draws from the prior distribution of the outcome, tau, and impact in percentage points.
logit$plotPrior()
new_dataData frame to be predicted
nameGroup name of the prediction
MNumber of posterior draws to sample from
...Additional arguments
invisible(self)
getPred()Get posterior predictive draws
logit$getPred(name = NULL, ...)nameGroup name of the prediction
...Additional arguments (not used)
Matrix of posterior predictive draws
predSummary()Get point estimate, credible interval and prob summary of predictive draws
logit$predSummary(
name = NULL,
subgroup = NULL,
median = TRUE,
width = 0.75,
round = 0,
a = NULL,
b = NULL,
...
)nameOptional. Group name of the prediction
subgroupOptional. A boolean vector to get summary on the conditional group average
medianOptional. Logical value for using median or mean
widthOptional. Numeric value for credible interval width
roundOptional. Integer value for rounding
aOptional. Lower bound threshold
bOptional. Upper bound threshold
...Additional arguments
A character string with summary information
predCompare()Compare the average of the posterior draws of two groups
logit$predCompare(
name1,
name2,
subgroup1 = NULL,
subgroup2 = NULL,
median = TRUE,
width = 0.75,
round = 0,
a = NULL,
b = NULL,
...
)name1Group name of the first prediction to be compared
name2Group name of the second prediction to be compared
subgroup1Optional. A boolean vector for the first group
subgroup2Optional. A boolean vector for the second group
medianOptional. Logical value for using median or mean
widthOptional. Numeric value for credible interval width
roundOptional. Integer value for rounding
aOptional. Lower bound threshold
bOptional. Upper bound threshold
...Additional arguments
A character string with comparison summary
clone()The objects of this class are cloneable with this method.
logit$clone(deep = FALSE)deepWhether to make a deep clone.