Title: | Sample Size and Power for Comparing Inequality Constrained Hypotheses |
---|---|
Description: | A collection of methods to determine the required sample size for the evaluation of inequality constrained hypotheses by means of a Bayes factor. Alternatively, for a given sample size, the unconditional error probabilities or the expected conditional error probabilities can be determined. Additional material on the methods in this package is available in Klaassen, F., Hoijtink, H. & Gu, X. (2019) <doi:10.31219/osf.io/d5kf3>. |
Authors: | Fayette Klaassen |
Maintainer: | Fayette Klaassen <[email protected]> |
License: | LGPL-3 |
Version: | 0.2.3 |
Built: | 2025-03-06 06:04:13 UTC |
Source: | https://github.com/fayetteklaassen/bayesianpower |
Determine the unconditional error probabilities for a set of simulated Bayes factors.
bayes_error(BFs1, BFs2, bound1 = 1, bound2 = 1/bound1)
bayes_error(BFs1, BFs2, bound1 = 1, bound2 = 1/bound1)
BFs1 |
A vector. Simulated BF12 under H1 for a given n |
BFs2 |
A vector. Simulated BF12 under H2 for a given n |
bound1 |
A number. The boundary above which BF12 favors H1 |
bound2 |
A number. The boundary below which BF12 favors H2 |
A named vector. The Type 1, Type 2, Decision error and Area of Indecision probabilities and the median Bayes factors under H1 and H2
Determine the 'power' for a Bayesian hypothesis test
bayes_power( n, h1, h2, m1, m2, sd1 = 1, sd2 = 1, scale = 1000, bound1 = 1, bound2 = 1/bound1, datasets = 1000, nsamp = 1000, seed = 31 )
bayes_power( n, h1, h2, m1, m2, sd1 = 1, sd2 = 1, scale = 1000, bound1 = 1, bound2 = 1/bound1, datasets = 1000, nsamp = 1000, seed = 31 )
n |
A number. The sample size |
h1 |
A constraint matrix defining H1 |
h2 |
A constraint matrix defining H2 |
m1 |
A vector of expected population means under H1 |
m2 |
A vector of expected populations means under H2
|
sd1 |
A vector of standard deviations under H1. Must be a single number (equal
standard deviation under all populations), or a vector of the same length as |
sd2 |
A vector of standard deviations under H2. Must be a single number (equal
standard deviation under all populations), or a vector of the same length as |
scale |
A number specifying the prior scale |
bound1 |
A number. The boundary above which BF12 favors H1 |
bound2 |
A number. The boundary below which BF12 favors H2 |
datasets |
A number. The number of datasets to compute the error probabilities |
nsamp |
A number. The number of prior or posterior samples to determine the fit and complexity |
seed |
A number. The random seed to be set |
The Type 1, Type 2, Decision error and Area of Indecision probability and the median BF12s under H1 and H2
# Short example WITH SMALL AMOUNT OF SAMPLES h1 <- matrix(c(1,-1,0,0,1,-1), nrow= 2, byrow= TRUE) h2 <- "c" m1 <- c(.4,.2,0) m2 <- c(.2,0,.1) bayes_power(40, h1, h2, m1, m2, datasets = 50, nsamp = 50)
# Short example WITH SMALL AMOUNT OF SAMPLES h1 <- matrix(c(1,-1,0,0,1,-1), nrow= 2, byrow= TRUE) h2 <- "c" m1 <- c(.4,.2,0) m2 <- c(.2,0,.1) bayes_power(40, h1, h2, m1, m2, datasets = 50, nsamp = 50)
Determine the required sample size for a Bayesian hypothesis test
bayes_sampsize( h1, h2, m1, m2, sd1 = 1, sd2 = 1, scale = 1000, type = 1, cutoff, bound1 = 1, bound2 = 1/bound1, datasets = 1000, nsamp = 1000, minss = 2, maxss = 1000, seed = 31 )
bayes_sampsize( h1, h2, m1, m2, sd1 = 1, sd2 = 1, scale = 1000, type = 1, cutoff, bound1 = 1, bound2 = 1/bound1, datasets = 1000, nsamp = 1000, minss = 2, maxss = 1000, seed = 31 )
h1 |
A constraint matrix defining H1. |
h2 |
A constraint matrix defining H2. |
m1 |
A vector of expected population means under H1 (standardized). |
m2 |
A vector of expected populations means under H2 (standardized).
|
sd1 |
A vector of standard deviations under H1. Must be a single number (equal
standard deviation under all populations), or a vector of the same length as |
sd2 |
A vector of standard deviations under H2. Must be a single number (equal
standard deviation under all populations), or a vector of the same length as |
scale |
A number specifying the prior scale |
type |
A character. The type of error to be controlled
options are: |
cutoff |
A number. The cutoff criterion for type.
If |
bound1 |
A number. The boundary above which BF12 favors H1 |
bound2 |
A number. The boundary below which BF12 favors H2 |
datasets |
A number. The number of datasets to compute the error probabilities |
nsamp |
A number. The number of prior or posterior samples to determine the fit and complexity |
minss |
A number. The minimum sample size to consider |
maxss |
A number. The maximum sample size to consider |
seed |
A number. The random seed to be set |
The sample size for which the chosen type of error probability is at the set cutoff, and the according error probabilities and median Bayes factors
# Short computation example NOT SUFFICIENT SAMPLES h1 <- matrix(c(1,-1), nrow= 1, byrow= TRUE) h2 <- 'c' m1 <- c(.4, 0) m2 <- c(0, .1) bayes_sampsize(h1, h2, m1, m2, sd1 = 1, sd2 = 1, scale = 1000, type = "de", cutoff = .125, nsamp = 50, datasets = 50, minss = 40, maxss = 70)
# Short computation example NOT SUFFICIENT SAMPLES h1 <- matrix(c(1,-1), nrow= 1, byrow= TRUE) h2 <- 'c' m1 <- c(.4, 0) m2 <- c(0, .1) bayes_sampsize(h1, h2, m1, m2, sd1 = 1, sd2 = 1, scale = 1000, type = "de", cutoff = .125, nsamp = 50, datasets = 50, minss = 40, maxss = 70)
Compute a Bayes factor
calc_bf(data, h1, h2, scale, nsamp = 1000)
calc_bf(data, h1, h2, scale, nsamp = 1000)
data |
A matrix. The dataset for which the BF must be computed |
h1 |
A constraint matrix defining H1. |
h2 |
A constraint matrix defining H2. |
scale |
A number specifying the prior scale. |
nsamp |
A number. The number of prior or posterior samples to determine the |
BF12, that is, the evidence for H1 relative to H2
Compute the complexity or fit for two hypotheses.
calc_fc(hyp, hyp2, means, sds, nsamp = 1000)
calc_fc(hyp, hyp2, means, sds, nsamp = 1000)
hyp |
A constraint matrix defining H1. |
hyp2 |
A constraint matrix defining H2 OR a character |
means |
A vector of posterior or prior means |
sds |
A vector or posterior or prior standard deviation |
nsamp |
A number. The number of prior or posterior samples to determine the fit and complexity |
A vector. The proportion of posterior samples in agreement with H1 and with H2
Evaluate a constraint matrix for a set of prior/posterior samples
eval_const(hyp, samples)
eval_const(hyp, samples)
hyp |
A constraint matrix defining a hypothesis. |
samples |
A matrix. Prior or posterior samples, the number of columns corresponds to the number of groups, the number of rows the number of samples |
A number between 0 and 1. The proportion of samples in which the constraints are met.
Sample multiple datasets and compute the Bayes factor in each
samp_bf(datasets, n, ngroup, means, sds, h1, h2, scale, nsamp)
samp_bf(datasets, n, ngroup, means, sds, h1, h2, scale, nsamp)
datasets |
A number. The number of datasets to simulate for each
sample size |
n |
A number. The group sample size to be used in data simulation |
ngroup |
A number. The number of groups. |
means |
A vector of expected population means. |
sds |
A vector of expected population standard deviations Note, when standardized, this is a vector of 1s |
h1 |
A constraint matrix defining H1. |
h2 |
A constraint matrix defining H2. |
scale |
A number specifying the prior scale. |
nsamp |
A number. The number of samples for the fit and complexity
See |
A vector of Bayes factors BF12 for each of the simulated datasets
Sample from prior or posterior distribution
samp_dist(nsamp, means, sds)
samp_dist(nsamp, means, sds)
nsamp |
A number. The number of prior or posterior samples to determine the fit and complexity |
means |
A vector. The prior or posterior means for each group |
sds |
A number or a vector. The standard deviations for each group If a number is used, the same prior or posterior standard deviation is used for each group. |
A matrix of nsamp
rows and as many columns as the
length of means
.