Title: | Power and Sample Size Calculations for Bayes Factor Analysis |
---|---|
Description: | Implements z-test, t-test, and normal moment prior Bayes factors based on summary statistics, along with functionality to perform corresponding power and sample size calculations as described in Pawel and Held (2024) <doi:10.48550/arXiv.2406.19940>. |
Authors: | Samuel Pawel [aut, cre] |
Maintainer: | Samuel Pawel <[email protected]> |
License: | GPL-3 |
Version: | 0.1.3 |
Built: | 2024-10-29 06:51:22 UTC |
Source: | CRAN |
This function computes the Bayes factor that quantifies the evidence that the data (in the form of an asymptotically normally distributed parameter estimate with standard error) provide for a point null hypothesis with a normal prior assigned to the parameter under the alternative. The standard error is assumed to be known.
bf01(estimate, se, null = 0, pm, psd, log = FALSE)
bf01(estimate, se, null = 0, pm, psd, log = FALSE)
estimate |
Parameter estimate |
se |
Standard error of the parameter estimate |
null |
Parameter value under the point null hypothesis. Defaults to
|
pm |
Mean of the normal prior assigned to the parameter under the alternative |
psd |
Standard deviation of the normal prior assigned to the parameter
under the alternative. Set to |
log |
Logical indicating whether the natural logarithm of the Bayes
factor should be returned. Defaults to |
Bayes factor in favor of the null hypothesis over the alternative (BF > 1 indicates evidence for the null hypothesis, whereas BF < 1 indicates evidence for the alternative)
Samuel Pawel
bf01(estimate = 0.2, se = 0.05, null = 0, pm = 0, psd = 2)
bf01(estimate = 0.2, se = 0.05, null = 0, pm = 0, psd = 2)
This function computes the required sample size to obtain a
Bayes factor (bf01) more extreme than a threshold k
with a
specified target power.
nbf01( k, power, usd, null = 0, pm, psd, dpm = pm, dpsd = psd, nrange = c(1, 10^5), lower.tail = TRUE, integer = TRUE, analytical = TRUE, ... )
nbf01( k, power, usd, null = 0, pm, psd, dpm = pm, dpsd = psd, nrange = c(1, 10^5), lower.tail = TRUE, integer = TRUE, analytical = TRUE, ... )
k |
Bayes factor threshold |
power |
Target power |
usd |
Unit standard deviation, the standard error of the parameter
estimate based on |
null |
Parameter value under the point null hypothesis. Defaults to
|
pm |
Mean of the normal prior assigned to the parameter under the alternative in the analysis |
psd |
Standard deviation of the normal prior assigned to the parameter
under the alternative in the analysis. Set to |
dpm |
Mean of the normal design prior assigned to the parameter.
Defaults to the same value as the analysis prior |
dpsd |
Standard deviation of the normal design prior assigned to the
parameter. Defaults to the same value as the analysis prior |
nrange |
Sample size search range over which numerical search is
performed. Defaults to |
lower.tail |
Logical indicating whether Pr(BF |
integer |
Logical indicating whether only integer valued sample sizes
should be returned. If |
analytical |
Logical indicating whether analytical (if available) or
numerical method should be used. Defaults to |
... |
Other arguments passed to |
It is assumed that the standard error of the future parameter
estimate is of the form . For example, for normally distributed data with known
standard deviation
sd
and two equally sized groups of size
n
, the standard error of an estimated standardized mean difference
is , so the
corresponding unit standard deviation is
. See the vignette for more
information.
The required sample size to achieve the specified power
A warning message will be displayed in case that the specified target power is not achievable under the specified analysis and design priors.
Samuel Pawel
## point alternative (analytical and numerical solution available) nbf01(k = 1/10, power = 0.9, usd = 1, null = 0, pm = 0.5, psd = 0, analytical = c(TRUE, FALSE), integer = FALSE) ## standardized mean difference (usd = sqrt(2), effective sample size = per group size) nbf01(k = 1/10, power = 0.9, usd = sqrt(2), null = 0, pm = 0, psd = 1) ## this is the sample size per group (assuming equally sized groups) ## z-transformed correlation (usd = 1, effective sample size = n - 3) nbf01(k = 1/10, power = 0.9, usd = 1, null = 0, pm = 0.2, psd = 0.5) ## have to add 3 to obtain the actual sample size ## log hazard/odds ratio (usd = 2, effective sample size = total number of events) nbf01(k = 1/10, power = 0.9, usd = 2, null = 0, pm = 0, psd = sqrt(0.5)) ## have to convert the number of events to a sample size
## point alternative (analytical and numerical solution available) nbf01(k = 1/10, power = 0.9, usd = 1, null = 0, pm = 0.5, psd = 0, analytical = c(TRUE, FALSE), integer = FALSE) ## standardized mean difference (usd = sqrt(2), effective sample size = per group size) nbf01(k = 1/10, power = 0.9, usd = sqrt(2), null = 0, pm = 0, psd = 1) ## this is the sample size per group (assuming equally sized groups) ## z-transformed correlation (usd = 1, effective sample size = n - 3) nbf01(k = 1/10, power = 0.9, usd = 1, null = 0, pm = 0.2, psd = 0.5) ## have to add 3 to obtain the actual sample size ## log hazard/odds ratio (usd = 2, effective sample size = total number of events) nbf01(k = 1/10, power = 0.9, usd = 2, null = 0, pm = 0, psd = sqrt(0.5)) ## have to convert the number of events to a sample size
This function computes the Bayes factor that quantifies the evidence that the data (in the form of an asymptotically normally distributed parameter estimate with standard error) provide for a point null hypothesis with a normal moment prior assigned to the parameter under the alternative.
nmbf01(estimate, se, null = 0, psd, log = FALSE)
nmbf01(estimate, se, null = 0, psd, log = FALSE)
estimate |
Parameter estimate |
se |
Standard error of the parameter estimate |
null |
Parameter value under the point null hypothesis. Defaults to
|
psd |
Spread of the normal moment prior assigned to the parameter under
the alternative. The modes of the prior are located at
|
log |
Logical indicating whether the natural logarithm of the Bayes
factor should be returned. Defaults to |
A normal moment prior has density with
the normal density with mean
and
variance
evaluated at
.
Bayes factor in favor of the null hypothesis over the alternative (BF > 1 indicates evidence for the null hypothesis, whereas BF < 1 indicates evidence for the alternative)
Samuel Pawel
Johnson, V. E. and Rossell, D. (2010). On the use of non-local prior densities in Bayesian hypothesis tests. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 72(2):143–170. doi:10.1111/j.1467-9868.2009.00730.x
Pramanik, S. and Johnson, V. E. (2024). Efficient alternatives for Bayesian hypothesis tests in psychology. Psychological Methods, 29(2):243–261. doi:10.1037/met0000482
nmbf01, pnmbf01, nnmbf01, powernmbf01
nmbf01(estimate = 0.25, se = 0.05, null = 0, psd = 0.5/sqrt(2)) # mode at 0.5
nmbf01(estimate = 0.25, se = 0.05, null = 0, psd = 0.5/sqrt(2)) # mode at 0.5
This function computes the required sample size to obtain a
normal moment prior Bayes factor (nbf01) more extreme than a
threshold k
with a specified target power.
nnmbf01( k, power, usd, null = 0, psd, dpm, dpsd, nrange = c(1, 10^5), lower.tail = TRUE, integer = TRUE, ... )
nnmbf01( k, power, usd, null = 0, psd, dpm, dpsd, nrange = c(1, 10^5), lower.tail = TRUE, integer = TRUE, ... )
k |
Bayes factor threshold |
power |
Target power |
usd |
Unit standard deviation, the standard error of the parameter
estimate based on |
null |
Parameter value under the point null hypothesis. Defaults to
|
psd |
Spread of the normal moment prior assigned to the parameter under
the alternative in the analysis. The modes of the prior are located at
|
dpm |
Mean of the normal design prior assigned to the parameter |
dpsd |
Standard deviation of the normal design prior assigned to the parameter. Set to 0 to obtain a point prior at the design prior mean |
nrange |
Sample size search range over which numerical search is
performed. Defaults to |
lower.tail |
Logical indicating whether Pr(BF |
integer |
Logical indicating whether only integer valued sample sizes
should be returned. If |
... |
Other arguments passed to |
It is assumed that the standard error of the future parameter
estimate is of the form . For example, for normally distributed data with known
standard deviation
sd
and two equally sized groups of size
n
, the standard error of an estimated standardized mean difference
is , so the
corresponding unit standard deviation is
. See the vignette for more
information.
The required sample size to achieve the specified power
Samuel Pawel
nnmbf01(k = 1/10, power = 0.9, usd = 1, null = 0, psd = 0.5/sqrt(2), dpm = 0.5, dpsd = 0)
nnmbf01(k = 1/10, power = 0.9, usd = 1, null = 0, psd = 0.5/sqrt(2), dpm = 0.5, dpsd = 0)
-test Bayes factorThis function computes the required sample size to obtain a
-test Bayes factor (tbf01) more extreme than a threshold
k
with a specified target power.
ntbf01( k, power, null = 0, plocation = 0, pscale = 1/sqrt(2), pdf = 1, type = c("two.sample", "one.sample", "paired"), alternative = c("two.sided", "less", "greater"), dpm = plocation, dpsd = pscale, lower.tail = TRUE, integer = TRUE, nrange = c(2, 10^4), ... )
ntbf01( k, power, null = 0, plocation = 0, pscale = 1/sqrt(2), pdf = 1, type = c("two.sample", "one.sample", "paired"), alternative = c("two.sided", "less", "greater"), dpm = plocation, dpsd = pscale, lower.tail = TRUE, integer = TRUE, nrange = c(2, 10^4), ... )
k |
Bayes factor threshold |
power |
Target power |
null |
Standardized mean difference under the point null hypothesis.
Defaults to |
plocation |
|
pscale |
|
pdf |
|
type |
Type of |
alternative |
Direction of the test. Can be either |
dpm |
Mean of the normal design prior assigned to the standardized mean difference. Defaults to the analysis prior location |
dpsd |
Standard deviation of the normal design prior assigned to the
standardized mean difference. Set to |
lower.tail |
Logical indicating whether Pr(BF |
integer |
Logical indicating whether only integer valued sample sizes
should be returned. If |
nrange |
Sample size search range over which numerical search is
performed. Defaults to |
... |
Other arguments passed to |
The required sample size to achieve the specified power
Samuel Pawel
## example from Schönbrodt and Wagenmakers (2018, p.135) ntbf01(k = 1/6, power = 0.95, dpm = 0.5, dpsd = 0, alternative = "greater") ntbf01(k = 1/6, power = 0.95, dpm = 0.5, dpsd = 0.1, alternative = "greater") ntbf01(k = 6, power = 0.95, dpm = 0, dpsd = 0, alternative = "greater", lower.tail = FALSE, nrange = c(2, 10000))
## example from Schönbrodt and Wagenmakers (2018, p.135) ntbf01(k = 1/6, power = 0.95, dpm = 0.5, dpsd = 0, alternative = "greater") ntbf01(k = 1/6, power = 0.95, dpm = 0.5, dpsd = 0.1, alternative = "greater") ntbf01(k = 6, power = 0.95, dpm = 0, dpsd = 0, alternative = "greater", lower.tail = FALSE, nrange = c(2, 10000))
This function computes the probability of obtaining a Bayes
factor (bf01) more extreme than a threshold k
with a
specified sample size.
pbf01(k, n, usd, null = 0, pm, psd, dpm = pm, dpsd = psd, lower.tail = TRUE)
pbf01(k, n, usd, null = 0, pm, psd, dpm = pm, dpsd = psd, lower.tail = TRUE)
k |
Bayes factor threshold |
n |
Sample size |
usd |
Unit standard deviation, the standard error of the parameter
estimate based on |
null |
Parameter value under the point null hypothesis. Defaults to
|
pm |
Mean of the normal prior assigned to the parameter under the alternative in the analysis |
psd |
Standard deviation of the normal prior assigned to the parameter
under the alternative in the analysis. Set to |
dpm |
Mean of the normal design prior assigned to the parameter.
Defaults to the same value as the analysis prior |
dpsd |
Standard deviation of the normal design prior assigned to the
parameter. Defaults to the same value as the analysis prior |
lower.tail |
Logical indicating whether Pr(BF |
It is assumed that the standard error of the future parameter
estimate is of the form . For example, for normally distributed data with known
standard deviation
sd
and two equally sized groups of size
n
, the standard error of an estimated standardized mean difference
is , so the
corresponding unit standard deviation is
. See the vignette for more
information.
The probability that the Bayes factor is less or greater (depending
on the specified lower.tail
) than the specified threshold k
Samuel Pawel
## point alternative (psd = 0) pbf01(k = 1/10, n = 200, usd = 2, null = 0, pm = 0.5, psd = 0) ## normal alternative (psd > 0) pbf01(k = 1/10, n = 100, usd = 2, null = 0, pm = 0.5, psd = 2) ## design prior is the null hypothesis (dpm = 0, dpsd = 0) pbf01(k = 10, n = 1000, usd = 2, null = 0, pm = 0.3, psd = 2, dpm = 0, dpsd = 0, lower.tail = FALSE) ## draw a power curve nseq <- round(exp(seq(log(10), log(10000), length.out = 100))) plot(nseq, pbf01(k = 1/10, n = nseq, usd = 2, null = 0, pm = 0.3, psd = 0), type = "l", xlab = "n", ylab = bquote("Pr(BF"["01"] <= 1/10 * ")"), ylim = c(0, 1), log = "x", las = 1) ## standardized mean difference (usd = sqrt(2), effective sample size = per group size) n <- 30 pbf01(k = 1/10, n = n, usd = sqrt(2), null = 0, pm = 0, psd = 1) ## z-transformed correlation (usd = 1, effective sample size = n - 3) n <- 100 pbf01(k = 1/10, n = n - 3, usd = 1, null = 0, pm = 0.2, psd = 0.5) ## log hazard/odds ratio (usd = 2, effective sample size = total number of events) nevents <- 100 pbf01(k = 1/10, n = nevents, usd = 2, null = 0, pm = 0, psd = sqrt(0.5))
## point alternative (psd = 0) pbf01(k = 1/10, n = 200, usd = 2, null = 0, pm = 0.5, psd = 0) ## normal alternative (psd > 0) pbf01(k = 1/10, n = 100, usd = 2, null = 0, pm = 0.5, psd = 2) ## design prior is the null hypothesis (dpm = 0, dpsd = 0) pbf01(k = 10, n = 1000, usd = 2, null = 0, pm = 0.3, psd = 2, dpm = 0, dpsd = 0, lower.tail = FALSE) ## draw a power curve nseq <- round(exp(seq(log(10), log(10000), length.out = 100))) plot(nseq, pbf01(k = 1/10, n = nseq, usd = 2, null = 0, pm = 0.3, psd = 0), type = "l", xlab = "n", ylab = bquote("Pr(BF"["01"] <= 1/10 * ")"), ylim = c(0, 1), log = "x", las = 1) ## standardized mean difference (usd = sqrt(2), effective sample size = per group size) n <- 30 pbf01(k = 1/10, n = n, usd = sqrt(2), null = 0, pm = 0, psd = 1) ## z-transformed correlation (usd = 1, effective sample size = n - 3) n <- 100 pbf01(k = 1/10, n = n - 3, usd = 1, null = 0, pm = 0.2, psd = 0.5) ## log hazard/odds ratio (usd = 2, effective sample size = total number of events) nevents <- 100 pbf01(k = 1/10, n = nevents, usd = 2, null = 0, pm = 0, psd = sqrt(0.5))
"power.bftest"
Plot method for class "power.bftest"
## S3 method for class 'power.bftest' plot(x, nlim = c(2, 500), ngrid = 100, plot = TRUE, nullplot = TRUE, ...)
## S3 method for class 'power.bftest' plot(x, nlim = c(2, 500), ngrid = 100, plot = TRUE, nullplot = TRUE, ...)
x |
Object of class |
nlim |
Range of sample sizes over which the power should be computed.
Defaults to |
ngrid |
Number of grid point for which power should be computed. Defaults to 100 |
plot |
Logical indicating whether data should be plotted. If
|
nullplot |
Logcal indicating whether a second plot with the power in
favor of the null (using a Bayes factor threshold of 1/k) should be
created. Defaults to |
... |
Other arguments (for consistency with the generic) |
Plots power curves (if specified) and invisibly returns a list of data frames containing the data underlying the power curves
Samuel Pawel
powerbf01, powertbf01, powernmbf01
ssd1 <- powerbf01(k = 1/6, power = 0.95, pm = 0, psd = 1/sqrt(2), dpm = 0.5, dpsd = 0) plot(ssd1, nlim = c(1, 8000)) power1 <- powerbf01(k = 1/2, n = 120, pm = 0, psd = 1/sqrt(2), dpm = 0.5, dpsd = 0) plot(power1, nlim = c(1, 1000))
ssd1 <- powerbf01(k = 1/6, power = 0.95, pm = 0, psd = 1/sqrt(2), dpm = 0.5, dpsd = 0) plot(ssd1, nlim = c(1, 8000)) power1 <- powerbf01(k = 1/2, n = 120, pm = 0, psd = 1/sqrt(2), dpm = 0.5, dpsd = 0) plot(power1, nlim = c(1, 1000))
This function computes the probability of obtaining a normal
moment prior Bayes factor (nmbf01) more extreme than a threshold
k
with a specified sample size.
pnmbf01(k, n, usd, null = 0, psd, dpm, dpsd, lower.tail = TRUE)
pnmbf01(k, n, usd, null = 0, psd, dpm, dpsd, lower.tail = TRUE)
k |
Bayes factor threshold |
n |
Sample size |
usd |
Unit standard deviation, the standard error of the parameter
estimate based on |
null |
Parameter value under the point null hypothesis. Defaults to
|
psd |
Spread of the normal moment prior assigned to the parameter under
the alternative in the analysis. The modes of the prior are located at
|
dpm |
Mean of the normal design prior assigned to the parameter |
dpsd |
Standard deviation of the normal design prior assigned to the parameter. Set to 0 to obtain a point prior at the design prior mean |
lower.tail |
Logical indicating whether Pr(BF |
It is assumed that the standard error of the future parameter
estimate is of the form . For example, for normally distributed data with known
standard deviation
sd
and two equally sized groups of size
n
, the standard error of an estimated standardized mean difference
is , so the
corresponding unit standard deviation is
. See the vignette for more
information.
The probability that the Bayes factor is less or greater (depending
on the specified lower.tail
) than the specified threshold k
Samuel Pawel
## point desing prior (psd = 0) pnmbf01(k = 1/10, n = 200, usd = 2, null = 0, psd = 0.5/sqrt(2), dpm = 0.5, dpsd = 0) ## normal design prior to incorporate parameter uncertainty (psd > 0) pnmbf01(k = 1/10, n = 200, usd = 2, null = 0, psd = 0.5/sqrt(2), dpm = 0.5, dpsd = 0.25) ## design prior is the null hypothesis (dpm = 0, dpsd = 0) pnmbf01(k = 10, n = 200, usd = 2, null = 0, psd = 0.5/sqrt(2), dpm = 0, dpsd = 0, lower.tail = FALSE)
## point desing prior (psd = 0) pnmbf01(k = 1/10, n = 200, usd = 2, null = 0, psd = 0.5/sqrt(2), dpm = 0.5, dpsd = 0) ## normal design prior to incorporate parameter uncertainty (psd > 0) pnmbf01(k = 1/10, n = 200, usd = 2, null = 0, psd = 0.5/sqrt(2), dpm = 0.5, dpsd = 0.25) ## design prior is the null hypothesis (dpm = 0, dpsd = 0) pnmbf01(k = 10, n = 200, usd = 2, null = 0, psd = 0.5/sqrt(2), dpm = 0, dpsd = 0, lower.tail = FALSE)
Compute probability that z-test Bayes factor is smaller than a specified threshold (the power), or determine sample size to obtain a target power.
powerbf01( n = NULL, power = NULL, k = 1/10, sd = 1, null = 0, pm, psd, type = c("two.sample", "one.sample", "paired"), dpm = pm, dpsd = psd, nrange = c(1, 10^5) )
powerbf01( n = NULL, power = NULL, k = 1/10, sd = 1, null = 0, pm, psd, type = c("two.sample", "one.sample", "paired"), dpm = pm, dpsd = psd, nrange = c(1, 10^5) )
n |
Sample size (per group for two-sample tests). Has to be |
power |
Target power. Has to be |
k |
Bayes factor threshold. Defaults to |
sd |
Standard deviation of one observation (for |
null |
Mean difference under the point null hypothesis. Defaults to
|
pm |
Mean of the normal prior assigned to the mean difference under the alternative in the analysis |
psd |
Standard deviation of the normal prior assigned to the mean
difference under the alternative in the analysis. Set to |
type |
The type of test. One of |
dpm |
Mean of the normal design prior assigned to the mean difference.
Defaults to the same value as the analysis prior |
dpsd |
Standard deviation of the normal design prior assigned to the
mean difference. Defaults to the same value as the analysis prior
|
nrange |
Sample size search range over which numerical search is
performed (only taken into account when |
This function provides a similar interface as
stats::power.t.test
. It also assumes that the data are continuous
and that the parameter of interest is either a mean or a (standardized)
mean difference. For some users, the low-level functions nbf01 (to
directly compute the sample size for a fixed power) and pbf01 (to
directly compute the power for a fixed sample size) may also be useful
because they can be used for other data and parameter types.
Object of class "power.bftest"
, a list of the arguments
(including the computed one) augmented with method
and note
elements
A warning message will be displayed in case that the specified target power is not achievable under the specified analysis and design priors.
Samuel Pawel
plot.power.bftest, nbf01, pbf01, bf01
## determine power powerbf01(n = 100, pm = 0, psd = 1, dpm = 0.5, dpsd = 0) ## determine sample size powerbf01(power = 0.99, pm = 0, psd = 1, dpm = 0.5, dpsd = 0)
## determine power powerbf01(n = 100, pm = 0, psd = 1, dpm = 0.5, dpsd = 0) ## determine sample size powerbf01(power = 0.99, pm = 0, psd = 1, dpm = 0.5, dpsd = 0)
Compute probability that normal moment prior Bayes factor is smaller than a specified threshold (the power), or determine sample size to obtain a target power.
powernmbf01( n = NULL, power = NULL, k = 1/10, sd = 1, null = 0, psd, type = c("two.sample", "one.sample", "paired"), dpm, dpsd, nrange = c(1, 10^5) )
powernmbf01( n = NULL, power = NULL, k = 1/10, sd = 1, null = 0, psd, type = c("two.sample", "one.sample", "paired"), dpm, dpsd, nrange = c(1, 10^5) )
n |
Sample size (per group for two-sample tests). Has to be |
power |
Target power. Has to be |
k |
Bayes factor threshold. Defaults to |
sd |
Standard deviation of one observation (for |
null |
Parameter value under the point null hypothesis. Defaults to
|
psd |
Spread of the normal moment prior assigned to the parameter under
the alternative in the analysis. The modes of the prior are located at
|
type |
The type of test. One of |
dpm |
Mean of the normal design prior assigned to the parameter |
dpsd |
Standard deviation of the normal design prior assigned to the parameter. Set to 0 to obtain a point prior at the design prior mean |
nrange |
Sample size search range over which numerical search is
performed (only taken into account when |
This function provides a similar interface as
stats::power.t.test
. It also assumes that the data are continuous
and that the parameter of interest is either a mean or a (standardized)
mean difference. For some users, the low-level functions nnmbf01
(to directly compute the sample size for a fixed power) and
pnmbf01 (to directly compute the power for a fixed sample size)
may also be useful because they can be used for other data and parameter
types.
Object of class "power.bftest"
, a list of the arguments
(including the computed one) augmented with method
and note
elements
Samuel Pawel
plot.power.bftest, nnmbf01, pnmbf01, nmbf01
## determine power powernmbf01(n = 100, psd = 1, dpm = 0.5, dpsd = 0) ## determine sample size powernmbf01(power = 0.99, psd = 1, dpm = 0.5, dpsd = 0)
## determine power powernmbf01(n = 100, psd = 1, dpm = 0.5, dpsd = 0) ## determine sample size powernmbf01(power = 0.99, psd = 1, dpm = 0.5, dpsd = 0)
-test Bayes factorCompute probability that -test Bayes factor is smaller
than a specified threshold (the power), or determine sample size to
obtain a target power.
powertbf01( n = NULL, power = NULL, k = 1/10, null = 0, plocation = 0, pscale = 1/sqrt(2), pdf = 1, type = c("two.sample", "one.sample", "paired"), alternative = c("two.sided", "less", "greater"), dpm = plocation, dpsd = pscale, nrange = c(2, 10^4) )
powertbf01( n = NULL, power = NULL, k = 1/10, null = 0, plocation = 0, pscale = 1/sqrt(2), pdf = 1, type = c("two.sample", "one.sample", "paired"), alternative = c("two.sided", "less", "greater"), dpm = plocation, dpsd = pscale, nrange = c(2, 10^4) )
n |
Sample size (per group) |
power |
Target power. Has to be |
k |
Bayes factor threshold. Defaults to |
null |
Standardized mean difference under the point null hypothesis.
Defaults to |
plocation |
|
pscale |
|
pdf |
|
type |
Type of |
alternative |
Direction of the test. Can be either |
dpm |
Mean of the normal design prior assigned to the standardized mean difference. Defaults to the analysis prior location |
dpsd |
Standard deviation of the normal design prior assigned to the
standardized mean difference. Set to |
nrange |
Sample size search range over which numerical search is
performed (only taken into account when |
This function provides a similar interface as
stats::power.t.test
. For some users, the low-level functions
ntbf01 (to directly compute the sample size for a fixed power) and
ptbf01 (to directly compute the power for a fixed sample size) may
also be useful.
Object of class "power.bftest"
, a list of the arguments
(including the computed one) augmented with method
and note
elements
Samuel Pawel
plot.power.bftest, ptbf01, ntbf01, tbf01
## determine power powertbf01(n = 146, k = 1/6, dpm = 0.5, dps = 0, alternative = "greater") ## determine sample size powertbf01(power = 0.95, k = 1/6, dpm = 0.5, dps = 0, alternative = "greater")
## determine power powertbf01(n = 146, k = 1/6, dpm = 0.5, dps = 0, alternative = "greater") ## determine sample size powertbf01(power = 0.95, k = 1/6, dpm = 0.5, dps = 0, alternative = "greater")
"power.bftest"
Print method for class "power.bftest"
## S3 method for class 'power.bftest' print(x, digits = getOption("digits"), ...)
## S3 method for class 'power.bftest' print(x, digits = getOption("digits"), ...)
x |
Object of class |
digits |
Number of digits for formatting of numbers |
... |
Other arguments (for consistency with the generic) |
Prints text summary in the console and invisibly returns the
"power.bftest"
object
Function adapted from stats:::print.power.htest
written by Peter
Dalgaard
Samuel Pawel
powerbf01(power = 0.95, pm = 0, psd = 1, dpm = 0.5, dpsd = 0) powerbf01(power = 0.95, pm = 0, psd = 1, dpm = 0.5, dpsd = 0, type = "one.sample") powerbf01(power = 0.95, pm = 0, psd = 1, dpm = 0.5, dpsd = 0, type = "paired") powerbf01(power = 0.95, pm = 1, psd = 0, dpm = 0.8, dpsd = 0, type = "paired")
powerbf01(power = 0.95, pm = 0, psd = 1, dpm = 0.5, dpsd = 0) powerbf01(power = 0.95, pm = 0, psd = 1, dpm = 0.5, dpsd = 0, type = "one.sample") powerbf01(power = 0.95, pm = 0, psd = 1, dpm = 0.5, dpsd = 0, type = "paired") powerbf01(power = 0.95, pm = 1, psd = 0, dpm = 0.8, dpsd = 0, type = "paired")
This function computes the probability of obtaining a
-test Bayes factor (tbf01) more extreme than a threshold
k
with a specified sample size.
ptbf01( k, n, n1 = n, n2 = n, null = 0, plocation = 0, pscale = 1/sqrt(2), pdf = 1, dpm = plocation, dpsd = pscale, type = c("two.sample", "one.sample", "paired"), alternative = c("two.sided", "less", "greater"), lower.tail = TRUE, drange = "adaptive", ... )
ptbf01( k, n, n1 = n, n2 = n, null = 0, plocation = 0, pscale = 1/sqrt(2), pdf = 1, dpm = plocation, dpsd = pscale, type = c("two.sample", "one.sample", "paired"), alternative = c("two.sided", "less", "greater"), lower.tail = TRUE, drange = "adaptive", ... )
k |
Bayes factor threshold |
n |
Sample size (per group) |
n1 |
Sample size in group 1 (only required for two-sample |
n2 |
Sample size in group 2 (only required for two-sample |
null |
Standardized mean difference under the point null hypothesis.
Defaults to |
plocation |
|
pscale |
|
pdf |
|
dpm |
Mean of the normal design prior assigned to the standardized mean difference. Defaults to the analysis prior location |
dpsd |
Standard deviation of the normal design prior assigned to the
standardized mean difference. Set to |
type |
Type of |
alternative |
Direction of the test. Can be either |
lower.tail |
Logical indicating whether Pr(BF |
drange |
Standardized mean difference search range over which the
critical values are searched for. Can be either set to a numerical range
or to |
... |
Other arguments passed to |
The probability that the Bayes factor is less or greater (depending
on the specified lower.tail
) than the specified threshold k
Samuel Pawel
## example from Schönbrodt and Wagenmakers (2018, p. 135) ptbf01(k = 1/6, n = 146, dpm = 0.5, dpsd = 0, alternative = "greater") ptbf01(k = 6, n = 146, dpm = 0, dpsd = 0, alternative = "greater", lower.tail = FALSE) ## two-sided ptbf01(k = 1/6, n = 146, dpm = 0.5, dpsd = 0) ptbf01(k = 6, n = 146, dpm = 0, dpsd = 0, lower.tail = FALSE) ## one-sample test ptbf01(k = 1/6, n = 146, dpm = 0.5, dpsd = 0, alternative = "greater", type = "one.sample")
## example from Schönbrodt and Wagenmakers (2018, p. 135) ptbf01(k = 1/6, n = 146, dpm = 0.5, dpsd = 0, alternative = "greater") ptbf01(k = 6, n = 146, dpm = 0, dpsd = 0, alternative = "greater", lower.tail = FALSE) ## two-sided ptbf01(k = 1/6, n = 146, dpm = 0.5, dpsd = 0) ptbf01(k = 6, n = 146, dpm = 0, dpsd = 0, lower.tail = FALSE) ## one-sample test ptbf01(k = 1/6, n = 146, dpm = 0.5, dpsd = 0, alternative = "greater", type = "one.sample")
This function computes the Bayes factor that forms the basis of
the informed Bayesian -test from Gronau et al. (2020). The Bayes
factor quantifies the evidence that the data provide for the null
hypothesis that the standardized mean difference (SMD) is zero against
the alternative that the SMD is non-zero. A location-scale
-distribution is assumed for the SMD under the alternative
hypothesis. The Jeffreys-Zellner-Siow (JZS) Bayes factor (Rouder et al.,
2009) is obtained as a special case by setting the location of the prior
to zero and the prior degrees of freedom to one, which is the default.
The data are summarized by -statistics and sample sizes. The
following types of
-statistics are accepted:
Two-sample -test where the SMD represents the standardized
mean difference between two group means (assuming equal variances in
both groups)
One-sample -test where the SMD represents the standardized
mean difference to the null value
Paired -test where the SMD represents the standardized mean
change score
tbf01( t, n, n1 = n, n2 = n, plocation = 0, pscale = 1/sqrt(2), pdf = 1, type = c("two.sample", "one.sample", "paired"), alternative = c("two.sided", "less", "greater"), log = FALSE, ... )
tbf01( t, n, n1 = n, n2 = n, plocation = 0, pscale = 1/sqrt(2), pdf = 1, type = c("two.sample", "one.sample", "paired"), alternative = c("two.sided", "less", "greater"), log = FALSE, ... )
t |
|
n |
Sample size (per group) |
n1 |
Sample size in group 1 (only required for two-sample |
n2 |
Sample size in group 2 (only required for two-sample |
plocation |
|
pscale |
|
pdf |
|
type |
Type of |
alternative |
Direction of the test. Can be either |
log |
Logical indicating whether the natural logarithm of the Bayes
factor should be returned. Defaults to |
... |
Additional arguments passed to |
The Bayes factor is implemented as in equation (5) in Gronau et al.
(2020), and using suitable truncation in case of one-sided alternatives.
Integration is performed numerically with stats::integrate
.
Bayes factor in favor of the null hypothesis over the alternative (BF > 1 indicates evidence for the null hypothesis, whereas BF < 1 indicates evidence for the alternative)
Samuel Pawel
Rouder, J. N., Speckman, P. L., Sun, D., Morey, R. D., Iverson,
G. (2009). Bayesian tests for accepting and rejecting the null
hypothesis. Psychonomic Bulletin & Review, 16(2):225-237.
doi:10.3758/PBR.16.2.225
Gronau, Q. F., Ly., A., Wagenmakers, E.J. (2020). Informed Bayesian
-Tests. The American Statistician, 74(2):137-143.
doi:10.1080/00031305.2018.1562983
## analyses from Rouder et al. (2009): ## values from Table 1 tbf01(t = c(0.69, 3.20), n = 100, pscale = 1, type = "one.sample") ## examples from p. 232 tbf01(t = c(2.24, 2.03), n = 80, pscale = 1, type = "one.sample") ## analyses from Gronau et al. (2020) section 3.2: ## informed prior tbf01(t = -0.90, n1 = 53, n2 = 57, plocation = 0.350, pscale = 0.102, pdf = 3, alternative = "greater", type = "two.sample") ## default (one-sided) prior tbf01(t = -0.90, n1 = 53, n2 = 57, plocation = 0, pscale = 1/sqrt(2), pdf = 1, alternative = "greater", type = "two.sample")
## analyses from Rouder et al. (2009): ## values from Table 1 tbf01(t = c(0.69, 3.20), n = 100, pscale = 1, type = "one.sample") ## examples from p. 232 tbf01(t = c(2.24, 2.03), n = 80, pscale = 1, type = "one.sample") ## analyses from Gronau et al. (2020) section 3.2: ## informed prior tbf01(t = -0.90, n1 = 53, n2 = 57, plocation = 0.350, pscale = 0.102, pdf = 3, alternative = "greater", type = "two.sample") ## default (one-sided) prior tbf01(t = -0.90, n1 = 53, n2 = 57, plocation = 0, pscale = 1/sqrt(2), pdf = 1, alternative = "greater", type = "two.sample")