blm {imt} | R Documentation |
Bayesian Linear Model Factory
Description
Bayesian Linear Model Factory
Bayesian Linear Model Factory
Active bindings
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
Methods
Public methods
Method 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.
Usage
blm$new( data, y, x, treatment, eta_mean, eta_sd, generate_fake_data = 0, seed = 1982, ... )
Arguments
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
Returns
invisible
Method 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.
Usage
blm$ppcDensOverlay(n = 50)
Arguments
n
Number of posterior draws to use for the overlay
Returns
ggplot2 visualization
Method tracePlot()
Plot MCMC trace for the eta and sigma parameters.
Usage
blm$tracePlot(...)
Arguments
...
Additional arguments for Stan
Returns
A ggplot object.
Method 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.
Usage
blm$posteriorProb(threshold = 0, gt = TRUE)
Arguments
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.
Details
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.
Returns
A character string summarizing the estimated probability.
Method pointEstimate()
Usage
blm$pointEstimate(median = TRUE)
Arguments
median
Logical value. If TRUE (default), the median of the eta draws is returned. If FALSE, the mean is returned.
Details
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.
Returns
A numeric value representing the point estimate.
Method credibleInterval()
Usage
blm$credibleInterval(width = 0.75, round = 0)
Arguments
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.
Details
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.
Returns
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
Method priorProb()
Usage
blm$priorProb(threshold = 0, gt = TRUE)
Arguments
threshold
Numerical threshold for comparison.
gt
Logical indicating whether to calculate probability greater than or less than the threshold.
Returns
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.
Method priorInterval()
Usage
blm$priorInterval(width = 0.75, round = 0)
Arguments
width
Desired probability width of the interval (default: 0.75).
round
Number of decimal places for rounding the bounds (default: 0).
Details
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.
Returns
A character string containing the formatted probability interval statement.
Method vizdraws()
Plots impact's prior and posterior distributions.
For more details see vizdraws::vizdraws()
.
Usage
blm$vizdraws(...)
Arguments
...
other arguments passed to vizdraws.
Returns
An interactive plot of the prior and posterior distributions.
Method clone()
The objects of this class are cloneable with this method.
Usage
blm$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.