Learn R Programming

findn (version 0.1.0)

findn_maruo: Find the Sample Size Using the Algorithm by Maruo et al.

Description

findn_maruo estimates the sample size for a certain target function based on repeated simulations using a model based approach proposed by Maruo et al. (2018).

Usage

findn_maruo(fun, targ, start = 10, k = 100, ...)

Value

findn_maruo returns a list containing the point estimate for the sample size and a list of all sample sizes that for which the trial function was evaluated.

Arguments

fun

A function that estimates the power of a trial. The function has to take at least two arguments: n, the sample size and k, the number of iterations.

targ

The target power. Must be either 0.8 or 0.9.

start

Starting value for the algorithm. Maruo et al. suggest to use 10.

k

Number of trial simulations to use in fun to estimate the power.

...

Further optional arguments.

References

Maruo, K., Tada, K., Ishil, R. and Gosho M. (2018) An Efficient Procedure for Calculating Sample Size Through Statistical Simulations, Statistics in Biopharmaceutical Research 10, 1-8.

Examples

Run this code
# Function that simulates the outcomes of a two-sample t-test
ttest <- function(n, k, mu1 = 0, mu2 = 1, sd = 2) {
  sample1 <- matrix(rnorm(n = ceiling(n) * k, mean = mu1, sd = sd),
    ncol = k)
  mean1 <- apply(sample1, 2, mean)
  sd1_hat <- apply(sample1, 2, sd)
  sample2 <- matrix(rnorm(n = ceiling(n) * k, mean = mu2, sd = sd),
    ncol = k)
  mean2 <- apply(sample2, 2, mean)
  sd2_hat <- apply(sample2, 2, sd)
  sd_hat <- sqrt((sd1_hat^2 + sd2_hat^2) / 2)
  teststatistic <- (mean1 - mean2) / (sd_hat * sqrt(2 / n))
  crit <- qt(1 - 0.025, 2 * n - 2)
  return(mean(teststatistic < -crit))
}

findn_maruo(fun = ttest, targ = 0.8)

Run the code above in your browser using DataLab