Created
January 9, 2023 15:18
-
-
Save martinctc/06c324d7dabfed1c029a9251d803052b to your computer and use it in GitHub Desktop.
[Power analysis and sample size estimation with R] #R
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
# See <https://rpubs.com/mbounthavong/sample_size_power_analysis_R> | |
library(pwr) | |
# Sample size estimations for two proportions | |
# `pwr::ES.h()` computes effect size for two proportions | |
# n provides required sample size | |
p0 <- pwr.2p.test(h = ES.h(p1 = 0.60, p2 = 0.50), sig.level = 0.05, power = .80) | |
plot(p0) | |
# Power analysis for two proportions | |
p1 <- seq(0.5, 1.0, 0.05) # proportion of responders | |
power1 <-pwr.2p.test(h = ES.h(p1 = p1, p2 = 0.50), | |
n = 388, | |
sig.level = 0.05) | |
powerchange <- data.frame(p1, power = power1$power * 100) | |
plot(powerchange$p1, | |
powerchange$power, | |
type = "b", | |
xlab = "Proportion of Responders in Treatment A", | |
ylab = "Power (%)") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment