Title: | Set Alpha Based on Sample Size Using Bayes Factors |
Version: | 0.1.2 |
Description: | Sets the alpha level for coefficients in a regression model as a decreasing function of the sample size through the use of Jeffreys' Approximate Bayes factor. You tell alphaN() your sample size, and it tells you to which value you must lower alpha to avoid Lindley's Paradox. For details, see Wulff and Taylor (2024) <doi:10.1177/14761270231214429>. |
License: | MIT + file LICENSE |
URL: | https://github.com/jespernwulff/alphaN |
BugReports: | https://github.com/jespernwulff/alphaN/issues |
Suggests: | knitr, rmarkdown, spelling, testthat (≥ 3.0.0) |
VignetteBuilder: | knitr |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
Language: | en-US |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2025-07-13 20:47:41 UTC; au205643 |
Author: | Jesper Wulff |
Maintainer: | Jesper Wulff <jwulff@econ.au.dk> |
Repository: | CRAN |
Date/Publication: | 2025-07-13 21:00:02 UTC |
Transforms a t-statistic from a glm or lm object into Jeffreys' approximate Bayes factor
Description
Transforms a t-statistic from a glm or lm object into Jeffreys' approximate Bayes factor
Usage
JAB(glm_obj, covariate, method = "JAB", upper = 1)
Arguments
glm_obj |
a glm or lm object. |
covariate |
the name of the covariate that you want a BF for as a string. |
method |
Used for the choice of 'b'. Currently one of:
|
upper |
The upper limit for the range of realistic effect sizes. Only relevant when method="balanced". Defaults to 1 such that the range of realistic effect sizes is uniformly distributed between 0 and 1, U(0,1). |
Value
A numeric value for the BF in favour of H1.
Examples
# Simulate data
## Sample size
n <- 200
## Regressors
Z1 <- runif(n, -1, 1)
Z2 <- runif(n, -1, 1)
Z3 <- runif(n, -1, 1)
Z4 <- runif(n, -1, 1)
X <- runif(n, -1, 1)
## Error term
U <- rnorm(n, 0, 0.5)
## Outcome
Y <- X/sqrt(n) + U
# Run a GLM
LM <- glm(Y ~ X + Z1 + Z2 + Z3 + Z4)
# Compute JAB for "X" based on the regression results
JAB(LM, "X")
# Compute JAB using the minimum prior
JAB(LM, "X", method = "min")
Plots JAB as a function of the p-value
Description
Plots JAB as a function of the p-value
Usage
JAB_plot(n, BF = 1, method = "JAB")
Arguments
n |
Sample size |
BF |
Bayes factor you would like to match. 1 to avoid the Lindley Paradox, 3 to achieve moderate evidence and 10 to achieve strong evidence. |
method |
Used for the choice of 'b'. Currently one of:
|
Value
Prints a plot.
Examples
# Plot JAB as function of the p-value for a sample size of 2000
JAB_plot(2000)
Title
Description
Title
Usage
JABp(n, p, z = TRUE, df = NULL, method = "JAB", upper = 1)
Arguments
n |
Sample size. |
p |
The p-value. |
z |
Is the p-value based on a z- or t-statistic? TRUE if z. |
df |
If z=FALSE, provide the degrees of freedom for the t-statistic. |
method |
Used for the choice of 'b'. Currently one of:
|
upper |
The upper limit for the range of realistic effect sizes. Only relevant when method="balanced". Defaults to 1 such that the range of realistic effect sizes is uniformly distributed between 0 and 1, U(0,1). |
Value
A numeric value for the BF in favour of H1.
Examples
# Transform a p-value of 0.007038863 from a z-test into JAB
# using a sample size of 200.
JABp(200, 0.007038863)
# Transform a p-value of 0.007038863 from a t-test with 190
# degrees of freedom into JAB using a sample size of 200.
JABp(200, 0.007038863, z=FALSE, df=190)
Transforms a t-statistic into Jeffreys' approximate Bayes factor
Description
Transforms a t-statistic into Jeffreys' approximate Bayes factor
Usage
JABt(n, t, method = "JAB", upper = 1)
Arguments
n |
Sample size. |
t |
The t-statistic. |
method |
Used for the choice of 'b'. Currently one of:
|
upper |
The upper limit for the range of realistic effect sizes. Only relevant when method="balanced". Defaults to 1 such that the range of realistic effect sizes is uniformly distributed between 0 and 1, U(0,1). |
Value
A numeric value for the BF in favour of H1.
Examples
# Transform a t-statistic of 2.695 computed based on a sample size of 200 into JAB
JABt(200, 2.695)
Set the alpha level based on sample size for coefficients in a regression models.
Description
Set the alpha level based on sample size for coefficients in a regression models.
Usage
alphaN(n, BF = 1, method = "JAB", upper = 1)
Arguments
n |
Sample size |
BF |
Bayes factor you would like to match. 1 to avoid Lindley's Paradox, 3 to achieve moderate evidence and 10 to achieve strong evidence. |
method |
Used for the choice of 'b'. Currently one of:
|
upper |
The upper limit for the range of realistic effect sizes. Only relevant when method="balanced". Defaults to 1 such that the range of realistic effect sizes is uniformly distributed between 0 and 1, U(0,1). |
Value
Numeric alpha level required to achieve the desired level of evidence.
References
Gu et al. (2016). Error probabilities in default Bayesian hypothesis testing. Journal of Mathematical Psychology, 72, 130–143.
Gu et al. (2018). Approximated adjusted fractional Bayes factors: A general method for testing informative hypotheses. The British Journal of Mathematical and Statistical Psychology, 71(2).
O’Hagan, A. (1995). Fractional Bayes Factors for Model Comparison. Journal of the Royal Statistical Society. Series B (Methodological), 57(1), 99–138.
Wagenmakers (2002). Approximate Objective Bayes Factors From PValues and Sample Size: The 3pn Rule. psyarxiv.
Wulff & Taylor (2023). How and why alpha should depend on sample size: A Bayesian-frequentist compromise for significance testing. PsyArXiv.
Examples
# Plot of alpha level as a function of n
seqN <- seq(50, 1000, 1)
plot(seqN, alphaN(seqN), type = "l")
Creates a plot of alpha as function of sample size for each of the four prior options
Description
Creates a plot of alpha as function of sample size for each of the four prior options
Usage
alphaN_plot(BF = 1, max = 10000)
Arguments
BF |
Bayes factor you would like to match. 1 to avoid Lindley's Paradox, 3 to achieve moderate evidence and 10 to achieve strong evidence. |
max |
The maximum number of sample size. Defaults to 10,000. |
Value
Prints a plot.
Examples
# Plot of alpha level as a function of n for a Bayes factor of 3
alphaN_plot(BF = 3)