In [1]:
wald.test <- function (sample, lambda0, alpha) {
# Conduct 2-sided wald test on sample
# Return TRUE if H0 is discarded
n <- length(sample)
sampleMean <- mean(sample)
sd <- sqrt(sampleMean/n)
z <- qnorm(1-alpha/2)
w <- (sampleMean - lambda0)/sd
discardH0 <- FALSE
if (abs(w) > z) {
discardH0 <- TRUE
}
return(discardH0)
}
In [2]:
l0 <- 1
n <- 20
alpha <- 0.05
In [3]:
trials <- 100000
discards <- 0
for (i in 1:trials) {
sample <- rpois(n, l0)
discards <- discards + wald.test(sample, l0, alpha)
}
discards/trials
Out[3]:
In [ ]: