Learn R Programming

imt (version 1.0.0)

calcProb: Calculate Probability of Posterior Draws Falling Within a Range

Description

This function estimates the probability that a vector of posterior draws, represented by the parameter eta, falls within a specified range. It provides flexibility to use either prior distributions or posterior draws, and to specify one-sided or two-sided probability calculations.

Usage

calcProb(x, a = NULL, b = NULL, prior = FALSE, group_name = "group average")

Value

A formatted string stating the calculated probability and the specified range. The probability is the proportion of samples (either prior or posterior) that fall within the defined range.

Arguments

x

A numeric vector containing either posterior draws (default) or prior samples of the treatment effect parameter (eta).

a

(Optional) The lower bound of the range (as a proportion, not percentage).

b

(Optional) The upper bound of the range (as a proportion, not percentage).

prior

A logical value indicating whether to use prior samples (TRUE) or posterior draws (FALSE, default) for calculation.

group_name

A string describing the group for which the probability is being calculated (default: "group average").

Details

This function checks the following cases:

  • If both a and b are NULL, it returns an empty string.

  • If b is less than or equal to a, it throws an error.

The calculated probability and range are presented in a human-readable string using the glue package for formatting.