-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCI coverage.R
More file actions
24 lines (15 loc) · 803 Bytes
/
CI coverage.R
File metadata and controls
24 lines (15 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Coverage probability of large-sample CI
setwd("/Users/jarrettphillips/desktop/HACSim Simulation Study Paper/Supplemental Information/p = 0.95/hypothetical species")
out <- read.table(file.choose(), sep = ",") # read in data
# large-sample CI based on CLT
ci.low <- out$V2 - qnorm(0.975) * out$V3 # lower CI limit
ci.up <- out$V2 + qnorm(0.975) * out$V3 # upper CI limit
ci <- cbind(ci.low, ci.up)
count <- 0 # initialize counter
for (i in 1:nrow(ci)) {
if ((ci[i, 2] >= 0.95) || ((ci[i, 1] <= 0.95) && (ci[i, 2] >= 0.95))) { # Is p = 0.95 in or above the CI (including the endpoints)?
count = count + 1 # update counter
}
}
(coverage <- count / nrow(ci)) # coverage probability
binom.test(count, nrow(ci), p = 0.95, conf.level = 0.95) # Exact binomial test using Clopper-Pearson CI