Last active
April 15, 2018 10:28
-
-
Save pgilad/0101146e527452d3d7aa994e500d1e89 to your computer and use it in GitHub Desktop.
Find minimum sample size to obtain minimum power test in non-centralized chi-square
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
u <- c(0.1, 0.3, 0.5) | |
chi_df <- 3 | |
target_power <- 0.9 | |
chi_base <- qchisq(0.95, chi_df) | |
get_power <- function(n) { | |
return (pchisq(q = chi_base, df = chi_df, ncp = n * u %*% u, lower.tail = FALSE)) | |
} | |
get_power(20) | |
get_power(30) | |
n_target <- optimize(function(n) { return(abs(get_power(n) - target_power))}, lower = 1, upper = 300) | |
print(ceiling(n_target$minimum)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment