## sample size parameters
pow <- 0.9
p0 <- 3/4
a <- 1
b <- 1
k <- 1/10
if (FALSE) {
## sample sizes for directional testing
(nH1 <- nbinbf01(k = k, power = pow, p0 = p0, type = "direction", a = a,
b = b, da = a, db = b, dl = p0, du = 1))
(nH0 <- nbinbf01(k = 1/k, power = pow, p0 = p0, type = "direction", a = a,
b = b, da = a, db = b, dl = 0, du = p0, lower.tail = FALSE))
nseq <- seq(1, 1.1*max(c(nH1, nH0)), length.out = 100)
powH1 <- pbinbf01(k = k, n = nseq, p0 = p0, type = "direction", a = a,
b = b, da = a, db = b, dl = p0, du = 1)
powH0 <- pbinbf01(k = 1/k, n = nseq, p0 = p0, type = "direction", a = a,
b = b, da = a, db = b, dl = 0, du = p0, lower.tail = FALSE)
matplot(nseq, cbind(powH1, powH0), type = "s", xlab = "n", ylab = "Power", lty = 1,
ylim = c(0, 1), col = c(2, 4), las = 1)
abline(h = pow, lty = 2)
abline(v = c(nH1, nH0), col = c(2, 4), lty = 2)
legend("topleft", legend = c("H1", "H0"), lty = 1, col = c(2, 4))
## sample sizes for point null testing
(nH1 <- nbinbf01(k = k, power = pow, p0 = p0, type = "point", a = a,
b = b, da = a, db = b))
(nH0 <- nbinbf01(k = 1/k, power = pow, p0 = p0, type = "point", a = a,
b = b, dp = p0, lower.tail = FALSE, nrange = c(1, 10^5)))
nseq <- seq(1, max(c(nH1, nH0)), length.out = 100)
powH1 <- pbinbf01(k = k, n = nseq, p0 = p0, type = "point", a = a,
b = b, da = a, db = b, dl = 0, du = 1)
powH0 <- pbinbf01(k = 1/k, n = nseq, p0 = p0, type = "point", a = a,
b = b, dp = p0, lower.tail = FALSE)
matplot(nseq, cbind(powH1, powH0), type = "s", xlab = "n", ylab = "Power", lty = 1,
ylim = c(0, 1), col = c(2, 4), las = 1)
abline(h = pow, lty = 2)
abline(v = c(nH1, nH0), col = c(2, 4), lty = 2)
legend("topleft", legend = c("H1", "H0"), lty = 1, col = c(2, 4))
}
Run the code above in your browser using DataLab