prop_baseline <- 0.05
prop_treatment <- 0.07
alpha <- 0.05
beta <- 0.2
n <- ceiling(
power.prop.test(
p1 = prop_baseline,
p2 = prop_treatment,
sig.level = alpha,
power = 1-beta,
alternative = c("two.sided")
)$n
)
n
# [1] 2213
# R code
prop_baseline <- 0.05
prop_treatment <- 0.07
alpha <- 0.05
beta <- 0.2
n <- ceiling(
power.prop.test(
p1 = prop_baseline,
p2 = prop_treatment,
sig.level = alpha,
power = 1-beta,
alternative = c("two.sided")
)$n
)
n
# [1] 2213
prop_pooled <- (prop_baseline+prop_treatment)/2
se_h0 <- sqrt(prop_pooled * (1-prop_pooled) * (1/n + 1/n))
se_ha <- sqrt((prop_baseline*(1-prop_baseline))/n + (prop_treatment*(1-prop_treatment))/n)
critical_value <- qnorm(alpha / 2, mean = 0, sd = se_h0, lower.tail = FALSE)
critical_value
# [1] 0.0139930354339993
prop_pooled <- (prop_baseline+prop_treatment)/2
se_h0 <- sqrt(prop_pooled * (1-prop_pooled) * (1/n + 1/n))
se_ha <- sqrt((prop_baseline*(1-prop_baseline))/n +
(prop_treatment*(1-prop_treatment))/n)
critical_value <- qnorm(alpha / 2, mean = 0, sd = se_h0,
lower.tail = FALSE)
critical_value
# [1] 0.0139930354339993
1 - pnorm(0.01536376, mean = 0, sd = se_h0)
# [1] 0.015700354530468
1 - pnorm(0.01536376, mean = 0, sd = se_h0)
# [1] 0.015700354530468
prop.test(x=c(141, 175), n=c(n,n))$p.value
# [1] 0.0540496200600176
prop.test(x=c(141, 175), n=c(n,n))$p.value
# [1] 0.0540496200600176