This function takes a reference mean value, sample size, mean, standard deviation, significance level and computes the empirical power of R randomly drawn normally distributed samples with mean mu, standard deviation sd and sample size n. The function can compute the power of one-sample t-tests and two-sample t-tests (variance is always assumed to be equal). This function will always return the data it generates internally because its focus is not on efficiency but rather reproducibility
emp_power(n, mu, mu0, sd, alpha = 0.05, R = 1000, type = c("one_sample", "two_sample"), ...)
n | numeric. sample size |
---|---|
mu | mean value used to draw random normal samples. See ?rnorm() for more information |
mu0 | numeric. mean of control group if running a two-sample t-test or, if type = "one_sample", a value indicating the true value of the mean (or difference in means if you are performing a one sample test). See ?t.test() for more information |
sd | standard deviation used to draw random normal samples |
alpha | significance level |
R | number of replications |
type | string. if 'one_sample', then a one-sample t-test, else a two-sample t-test |
... | optional arguments. You may pass selected parameters from the t.test() function. You may also pass the following parameters:
Note that you are required to either pass all parameters related to the control group (n0, mu0, sd0) or a parameter related to the reference mean (ref_mu). |
list containing:
inputs: list. user input values
data: matrix. values of R samples of size n with mean mu and standard deviation sd drawn from a normal distribution using rnorm()
p_values: vector. resulting p-values of R tests comparing the samples against the reference mean ref_mu
power: vector. power calculated by taking the proportion of p-values for which the value falls below or is equal to the significance level alpha
se :standard error of the power estimate. Calculated using the SE formula of a proportion. For more information, see the reference to Rizzo below.
Rizzo, Maria L. 'Statistical Computing with R. Chapman and Hall/CRC, 2007'. (pp. 167-169)