Package 'bmet'

Title: Bayesian Multigroup Equivalence Testing
Description: Calculates the necessary quantities to perform Bayesian multigroup equivalence testing. Currently the package includes the Bayesian models and equivalence criteria outlined in Pourmohamad and Lee (2023) <doi:10.1002/sta4.645>, but more models and equivalence testing features may be added over time.
Authors: Tony Pourmohamad [aut, cre]
Maintainer: Tony Pourmohamad <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2024-11-04 03:02:36 UTC
Source: https://github.com/tpourmohamad/bmet

Help Index


All pairwise comparisons

Description

Function creates a contrast matrix for all pairwise comparisons

Usage

apc(ngroups, labs = NULL)

Arguments

ngroups

A positive integer greater than 1 denoting the number of groups

labs

A vector of groups labels with length equal to ngroups. The default is set to NULL, and if used, the labels will be set to 1:length(ngroups).

Value

The function returns a matrix of all pairwise contrasts.

Examples

### A contrast matrix based on all pairwise contrasts of 5 groups
apc(5)

### Adding group labels
apc(5, labs = paste("Group", 1:5, sep = " "))

Posterior based Bayesian multigroup equivalence testing

Description

Function provides the necessary tools to carry out Bayesian multigroup equivalence testing based on sampling of the posterior distribution. The function returns posterior samples of the average differences amongst groups, as well as posterior samples of group variances.

Usage

bet(values, groups, em, A, B = 10000, test = "mean")

Arguments

values

A vector of measurements sorted in the same order as the groups variable.

groups

A vector of groups labels corresponding to the individual measurements in the groups variable.

em

A c x 2 matrix of lower and upper equivalence margins. Here, c is the number of pairwise comparisons of interest.

A

A c x k matrix of pairwise contrasts. Here, k is the number of groups, i.e., length(unique(groups)).

B

A positive integer specifying the number of posterior samples to draw. By default B is set to 10000.

test

Setting this to anything other than "mean" tells the function to not calculate the posterior probability that the average differences fall within the equivalence margins (applicable when testing equivalence based on something other than just average differences).

Value

The function returns a list object containing the following:

  • prob: The posterior probability that the average differences fall within the equivalence margins. Only returned if test == "mean".

  • delta: A B x c matrix of posterior samples of the average difference for each pairwise comparison of interest.

  • sigma2: A B x k matrix of posterior samples of the variance for each group.

References

Pourmohamad, T. and Lee, H.K.H. (2023). Equivalence Testing for Multiple Groups. Stat, e645.

Examples

### Multigroup equivalence test for A vs. B and A vs. C
values <- rnorm(75)
groups <- rep(LETTERS[1:3], each = 25)

mad1 <- 0.65  # The equivalence margin for A vs. B
mad2 <- 0.65  # The equivalence margin for A vs. C
mads <- c(mad1, mad2)
mads <- cbind(-mads, mads)

A <- apc(3)
A <- A[1:2, ]

out <- bet(values, groups, mads, A, B = 10000)

out$prob   # The posterior probability that the average
           # differences fall within the equivalence margins

Posterior predictive based Bayesian multigroup equivalence testing

Description

Function provides the necessary tools to carry out Bayesian multigroup equivalence testing based on sampling of the posterior predictive distribution. The function returns posterior predictive samples of future differences amongst groups.

Usage

betpp(values, groups, em, A, B = 10000)

Arguments

values

A vector of measurements sorted in the same order as the groups variable.

groups

A vector of groups labels corresponding to the individual measurements in the groups variable.

em

A c x 2 matrix of lower and upper equivalence margins. Here, c is the number of pairwise comparisons of interest.

A

A c x k matrix of pairwise contrasts. Here, k is the number of groups, i.e., length(unique(groups)).

B

A positive integer specifying the number of posterior predictive samples to draw. By default B is set to 10000.

Value

The function returns a list object containing the following:

  • prob: The probability that future differences fall within the equivalence margins.

  • delta: A B x c matrix of posterior predictive samples of future differences for each pairwise comparison of interest.

References

Pourmohamad, T. and Lee, H.K.H. (2023). Equivalence Testing for Multiple Groups. Stat, e645.

Examples

### Multigroup equivalence test for A vs. B and A vs. C
values <- rnorm(75)
groups <- rep(LETTERS[1:3], each = 25)

mad1 <- 0.65  # The equivalence margin for A vs. B
mad2 <- 0.65  # The equivalence margin for A vs. C
mads <- c(mad1, mad2)
mads <- cbind(-mads, mads)

A <- apc(3)
A <- A[1:2, ]

out <- betpp(values, groups, mads, A, B = 10000)

out$prob   # The probability that future differences
           # fall within the equivalence margins