power | R Documentation |
This function calculates the probability of Type II error when the sample size is known, and the required sample size to achieve a preassigned Type II error probability (beta) for a test of two independent groups. This function uses the $z$-distribution (note the more commonly used $t$-distribution) is used.
power( mu0, mu1, sigma, alpha, n = NULL, n1 = NULL, n2 = NULL, n_vals = NULL, beta = NULL, method = c("sample_size", "type_2", "type_2_seq") )
mu0 |
Population mean of group 0 (e.g., control). |
mu1 |
Population mean of group 1 (e.g., experimental). |
sigma |
The population standard deviation, assumed equal across groups. |
alpha |
The Type I error rate. |
n |
The number of samples, used to calculate Type II error for a given sample size. |
n1 |
The lowest number of samples to consider when generating a sequence of Type II errors. |
n2 |
The highest number of samples to consider when generating a sequence of Type II errors. |
n_vals |
The number of samples to generate Type II error for. |
beta |
The desired Type II error rate, used when calculating the necessary sample size. |
method |
What should the function calculate, (1) "sample_size" returns the calculated sample size necessary to achieve a specified Type II error rate. (2) "type_2" returns the calculated Type II error rate for a given sample size. (3) "type_2_seq" returns a series of length "n_vals" of calculated type II error rates from n1 to n2. |
Depending on the method chosen the function returns either the necessary sample size to achieve a certain type II error, the type II error for a given sample size or a sequence of type II errors for different sample sizes.
Mukhopadhyay, N., \& de Silva, B. M. (2009). Sequential Methods and Their Applications. New York: CRC Press.
# Set parameter values mu0 <- 0 mu1 <- 1 sigma <- 2 alpha <- 0.05 n <- 16 # Calculate type II error t2 <- power(mu0 = mu0, mu1 = mu1, sigma = sigma, alpha = alpha , n = n, method="type_2") t2 # Calculate sample size beta <- 0.361 size <- power(mu0 = mu0, mu1 = mu1, sigma = sigma, alpha = alpha, beta = beta, method = "sample_size") size # Return sequence of type II errors n1 <- 5 n2 <- 50 n_vals <- 10 seq_vals <- power(mu0 = mu0, mu1 = mu1, sigma=sigma, alpha = alpha, n1 = n1, n2 = n2, n_vals = n_vals, method = "type_2_seq") seq_vals
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.