A class for creating and managing Bayesian Logit Models
version
im package version used to fit model
tau_draws
Posterior draws for the treatment effect
mcmChecks
MCMC diagnostics
credible_interval
Credible interval for the treatment effect
prior_eta
Prior distribution for eta
prior_tau
Prior distribution for tau
prior_mean_y
Prior distribution for mean y
eta_draws
Posterior draws for eta
predict_list
List 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,
...
)
data
Data frame to be used
y
Name of the outcome variable in the data frame
x
Vector of names of all covariates in the data frame
treatment
Name of the treatment indicator variable in the data frame
mean_alpha
Prior mean for alpha
sd_alpha
Prior standard deviation for alpha
mean_beta
Prior mean for beta
sd_beta
Prior standard deviation for beta
tau_mean
Prior mean for the treatment effect estimation
tau_sd
Prior standard deviation for the treatment effect estimation
seed
Seed for Stan fitting
fit
Flag 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)
a
Optional. Lower bound for the threshold.
b
Optional. Upper bound for the threshold.
prior
Logical. If TRUE, calculates probabilities based on the prior distribution. If FALSE (default), uses the posterior distribution.
x
A 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)
median
Logical 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)
width
Numeric value between 0 and 1 representing the desired width of the credible interval (e.g., 0.95 for a 95% credible interval).
round
Integer 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, ...)
tau
Logical. 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, ...)
threshold
cutoff 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_data
Data frame to be predicted
name
Group name of the prediction
M
Number of posterior draws to sample from
...
Additional arguments
invisible(self)
getPred()
Get posterior predictive draws
logit$getPred(name = NULL, ...)
name
Group 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,
...
)
name
Optional. Group name of the prediction
subgroup
Optional. A boolean vector to get summary on the conditional group average
median
Optional. Logical value for using median or mean
width
Optional. Numeric value for credible interval width
round
Optional. Integer value for rounding
a
Optional. Lower bound threshold
b
Optional. 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,
...
)
name1
Group name of the first prediction to be compared
name2
Group name of the second prediction to be compared
subgroup1
Optional. A boolean vector for the first group
subgroup2
Optional. A boolean vector for the second group
median
Optional. Logical value for using median or mean
width
Optional. Numeric value for credible interval width
round
Optional. Integer value for rounding
a
Optional. Lower bound threshold
b
Optional. 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)
deep
Whether to make a deep clone.