View source: R/find_sample_size.R
find_sample_size | R Documentation |
This function calculates the minimum sample size needed to obtain a conclusive Bayes factor (BF) in favor of either H1 or H0. The calculation is based on an iterative approach that increases the sample size until the Bayes factor exceeds a predefined threshold.
find_sample_size(
predicted_value,
n,
design,
distribution_likelihood,
distribution_prior,
sd1,
sd2,
sd_of_theory,
stop_value,
n_end,
create_likelihood,
create_prior,
tail
)
predicted_value |
The mean of the hypothesis being tested. Typically, this is either the effect size under H1 or 0 under H0. |
n |
A numeric vector representing the sequence of sample sizes to be tested. |
design |
A character string, either '"within"' or '"between"', specifying the study design. |
distribution_likelihood |
A character string specifying the likelihood distribution (e.g., '"normal"' or '"t"'). |
distribution_prior |
A character string specifying the prior distribution (e.g., '"normal"', '"cauchy"', or '"uniform"'). |
sd1 |
Standard deviation of the first sample. |
sd2 |
Standard deviation of the second sample (if applicable; 'NULL' for within-subject designs). |
sd_of_theory |
Standard deviation of the theoretical prior distribution. |
stop_value |
The Bayes factor threshold at which the function stops iterating. |
n_end |
The maximum sample size allowed before stopping the search. |
create_likelihood |
A function that constructs the likelihood given a mean, standard error, and degrees of freedom. |
create_prior |
A function that constructs the prior distribution. |
tail |
The number of tails (1 or 2). |
The function iterates through increasing sample sizes, calculating the corresponding standard error and degrees of freedom. For each sample size, it computes the Bayes factor using the provided likelihood and prior distributions. The process stops when the Bayes factor exceeds the predefined threshold ('stop_value') or when the maximum allowed sample size ('n_end') is reached.
The smallest sample size 'n' required to reach the stopping Bayes factor threshold. Returns 'NA' if the maximum sample size is reached without reaching conclusive evidence.
Bf_samplesize
, bayesplay::likelihood
,
bayesplay::prior
## Not run:
# Example: Find required sample size for a given hypothesis mean
required_n <- find_sample_size(
predicted_value = 0.5,
n = seq(5, 100, 5),
design = "within",
distribution_likelihood = "normal",
distribution_prior = "cauchy",
sd1 = 1,
sd2 = NULL,
sd_of_theory = 0.5,
stop_value = 6,
n_end = 100,
create_likelihood = create_likelihood,
create_prior = create_prior
)
print(required_n)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.