pi.Ho <- 0.5
n <- 1000
# pi.Ha <- 0.55
set.seed(9128)
w <- rbinom(n = 10000, size = n, prob = pi.Ho)
# w <- rbinom(n = 10000, size = n, prob = pi.Ha)
head(w)
pi.hat <- w/n # MLE
Lambda <- dbinom(x = w, size = n, prob = pi.Ho)/dbinom(x = w, size = n, prob = pi.hat)
tran <- -2*log(Lambda) # If Ho is true, these values should look like a random sample from a chi-square(1)
# Discuss first stat class - histogram with normal distribution plotted upon it
hist(x = tran, xlab = expression(-2*log(Lambda)), ylab = "Density", freq = FALSE)
curve(expr = dchisq(x = x, df = 1), add = TRUE, col = "red")
qchisq(p = 0.95, df = 1)
quantile(x = tran, probs = 0.95)
sum(-2*log(Lambda) > 3.84)/10000
# What would be an unusual -2log(Lambda)? Relate to hypothesis testing and p-values
# What happens for smaller n? Try 100 and 10
# What would happen if simulate data with a pi NOT under null hypothesis? Relate to power
#