Bayesian Linear Model Factory
Bayesian Linear Model Factory
version
im package version used to fit model
eta_draws
Posterior draws for the treatment effect
mcmChecks
MCMC diagnostics
credible_interval
Credible interval for the treatment effect
new()
Get the package version
Get the posterior draws for eta
Get the MCMC diagnostics
Get the credible interval
Create a new Bayesian Linear Model object.
blm$new(
data,
y,
x,
treatment,
eta_mean,
eta_sd,
generate_fake_data = 0,
seed = 1982,
...
)
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
eta_mean
Prior mean for the treatment effect estimation
eta_sd
Prior standard deviation for the treatment effect estimation
generate_fake_data
Flag for generating fake data
seed
Seed for Stan fitting
...
Additional arguments for Stan
invisible
ppcDensOverlay()
This method compares the empirical distribution of the data 'y'
to the distributions of simulated/replicated data 'yrep' from the
posterior predictive distribution. This is done by creating a density
overlay plot using the bayesplot::ppc_dens_overlay
function.
blm$ppcDensOverlay(n = 50)
n
Number of posterior draws to use for the overlay
ggplot2 visualization
tracePlot()
Plot MCMC trace for the eta and sigma parameters.
blm$tracePlot(...)
...
Additional arguments for Stan
A ggplot object.
posteriorProb()
Calculate posterior probability of effect exceeding a threshold
This function calculates the posterior probability of the effect being larger or smaller than a specified threshold.
blm$posteriorProb(threshold = 0, gt = TRUE)
threshold
A numeric value specifying the threshold.
gt
A logical value indicating whether to calculate the probability of the effect being greater than (TRUE) or less than (FALSE) the threshold.
This function uses the private$..eta_draws internal variable to obtain draws from the posterior distribution of the effect size. Based on the specified arguments, the function calculates the proportion of draws exceeding/falling below the threshold and returns a formatted statement describing 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.
A character string summarizing the estimated probability.
pointEstimate()
blm$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()
blm$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.
Calculate and format probability statement based on prior
This method calculates the probability that the effect is greater than or less than a given threshold based on the prior distribution of the effect. The results are formatted into a statement suitable for reporting.
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
priorProb()
blm$priorProb(threshold = 0, gt = TRUE)
threshold
Numerical threshold for comparison.
gt
Logical indicating whether to calculate probability greater than or less than the threshold.
A character string containing the formatted probability statement. Calculates the prior for the effedt of the intervention based on the hyperpriors.
This method computes and formats a statement about the probability interval of the effect based on the prior distribution.
priorInterval()
blm$priorInterval(width = 0.75, round = 0)
width
Desired probability width of the interval (default: 0.75).
round
Number of decimal places for rounding the bounds (default: 0).
This method calculates the lower and upper bounds of the interval based on the specified probability width and the prior distribution of the effect. It then formats the results into a clear and informative statement.
Note that the probability is checked to be within valid range (0-1) with consideration of machine precision using .Machine$double.eps.
A character string containing the formatted probability interval statement.
vizdraws()
Plots impact's prior and posterior distributions.
For more details see vizdraws::vizdraws()
.
blm$vizdraws(...)
...
other arguments passed to vizdraws.
An interactive plot of the prior and posterior distributions.
clone()
The objects of this class are cloneable with this method.
blm$clone(deep = FALSE)
deep
Whether to make a deep clone.