df1 <- data.frame(
  x = c(-0.86, -0.30, -0.05, 0.73),
  n = c(5, 5, 5, 5),
  y = c(0, 1, 3, 5)
)

fit = glm(cbind(y,n-y)~x,data=df1,family="binomial")
theta.hat = c(coef(fit),-coef(fit)[1]/coef(fit)[2])
x = rep(df1$x,each=df1$n)
y = c(0,0,0,0,0,1,0,0,0,0,1,1,1,0,0,1,1,1,1,1)
df2 = data.frame(x=x,y=y)
fit2 = glm(y~x,data=df2,family="binomial")

tab = summary(fit)$coef
show(tab)
show(cbind(tab[,1]-1.96*tab[,2],tab[,1]+1.96*tab[,2]))

#Bootstrapping
B = 100
n = nrow(df2)
theta.star = matrix(nrow=B,ncol=3)
for(b in 1:B)
{
  ind = sample(1:n,n,replace=TRUE)
  fit.star = glm(y~x,data=df2[ind,],family="binomial")
  theta.star[b,1:2] = coef(fit.star)
  theta.star[b,3] = -coef(fit.star)[1]/coef(fit.star)[2]
}
bias = colMeans(theta.star)-theta.hat
show(bias)

show(quantile(theta.star[,1],prob=c(0.025,0.975)))
show(quantile(theta.star[,2],prob=c(0.025,0.975)))
show(quantile(theta.star[,3],prob=c(0.025,0.975)))
