source('https://myweb.uiowa.edu/pbreheny/7110/f20/notes/fun.R')

# Binomial
n <- 20
x <- 6
theta <- seq(0, 1, len=499)
L <- plotL(theta, dbinom(x, n, theta))
plotL(theta, dbinom(x, n, theta))
abline(h=0.15, lty=2, col='gray', lwd=2)
theta[which.max(L)]
range(theta[L > 0.15])
range(theta[L > exp(-qchisq(0.95, 1)/2)])
plotL(theta, dbinom(x, n, theta), xaxt='n', xlab=expression(phi1), ylab=expression(L(phi1)))
tt <- seq(0, 1, 0.2)
axis(1, at=tt, label=round(binomial()$linkfun(tt), 2))

# Hypergeometric
m <- 30
x <- 14
k <- 45
theta <- 45:200
L <- plotL(theta, dhyper(x, m, theta-m, k))
plotL(theta, L)
abline(h=0.15, lty=2, col='gray', lwd=2)
theta[which.max(L)]
range(theta[L > 0.15])
