sample.size.one.sample.Z.test <- function(E, S, alpha = 0.025, beta = 0.2) { ## Purpose: Sample Size for One-sample Z test ## H1: mu1 (expected) > mu0 (target) ## Assume type I error of 2.5% (alpha), and power of 80% (1 - beta). ## Arguments: ## E: effect size (difference of expected mean and target mean) ## S: estimated spread (standard deviation) from pilot sample ## alpha: type I error (default to 2.5%) ## beta: type II error (default to 20%) ## Return: sample size ## Author: Feiming Chen ## ________________________________________________ a <- qnorm(1 - alpha) - qnorm(beta) # default = 2.8 ## Note: a minimum sample size of 30 is required for the sample mean to approximate the normal distribution N <- max(30, ceiling((a * S / E)^2)) cat("Sample Size =", N, ", when Effect Size =", E, ", SD =", S, ", Type I Error =", alpha, ", Power = ", 1 - beta, "\n") } if (F) { # Unit Test sample.size.one.sample.Z.test(0.1, 0.2) # 32 for (E in seq(0.05, 0.2, 0.05)) { for (SD in seq(0.2, 0.5, 0.1)) { sample.size.one.sample.Z.test(E, SD) } } ## Sample Size = 126 , when Effect Size = 0.05 , SD = 0.2 , Type I Error = 0.025 , Power = 0.8 ## Sample Size = 283 , when Effect Size = 0.05 , SD = 0.3 , Type I Error = 0.025 , Power = 0.8 ## Sample Size = 503 , when Effect Size = 0.05 , SD = 0.4 , Type I Error = 0.025 , Power = 0.8 ## Sample Size = 785 , when Effect Size = 0.05 , SD = 0.5 , Type I Error = 0.025 , Power = 0.8 ## Sample Size = 32 , when Effect Size = 0.1 , SD = 0.2 , Type I Error = 0.025 , Power = 0.8 ## Sample Size = 71 , when Effect Size = 0.1 , SD = 0.3 , Type I Error = 0.025 , Power = 0.8 ## Sample Size = 126 , when Effect Size = 0.1 , SD = 0.4 , Type I Error = 0.025 , Power = 0.8 ## Sample Size = 197 , when Effect Size = 0.1 , SD = 0.5 , Type I Error = 0.025 , Power = 0.8 ## Sample Size = 30 , when Effect Size = 0.15 , SD = 0.2 , Type I Error = 0.025 , Power = 0.8 ## Sample Size = 32 , when Effect Size = 0.15 , SD = 0.3 , Type I Error = 0.025 , Power = 0.8 ## Sample Size = 56 , when Effect Size = 0.15 , SD = 0.4 , Type I Error = 0.025 , Power = 0.8 ## Sample Size = 88 , when Effect Size = 0.15 , SD = 0.5 , Type I Error = 0.025 , Power = 0.8 ## Sample Size = 30 , when Effect Size = 0.2 , SD = 0.2 , Type I Error = 0.025 , Power = 0.8 ## Sample Size = 30 , when Effect Size = 0.2 , SD = 0.3 , Type I Error = 0.025 , Power = 0.8 ## Sample Size = 32 , when Effect Size = 0.2 , SD = 0.4 , Type I Error = 0.025 , Power = 0.8 ## Sample Size = 50 , when Effect Size = 0.2 , SD = 0.5 , Type I Error = 0.025 , Power = 0.8 }
Thursday, March 25, 2021
Sample Size for One-Sample Z test
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment