## The population mean. mu = 1 ## The sample size. n = 10 ## The number of simulation replications. nrep = 1e3 Q = array(0, c(nrep,3)) for (k in 1:1e3) { ## Generate the logistic data. U = runif(n) Y = mu + log(U/(1-U)) ## Starting value. m = mean(Y) ## Newton's method. while (TRUE) { V = exp(-(Y-m)) ## The first derivative of the log-likelihood. D1 = n - 2*sum(V/(1+V)) ## Check for convergence. if (abs(D1) < 1e-10) { break } ## The second derivative of the log-likelihood. D2 = -2*sum(V/(1+V)^2) ## Newton's step. m = m - D1/D2 } ## The approximate standard error. SE = sqrt(-1/D2) Q[k,] = c(m, SE, 1*(abs(m-mu) < 2*SE)) }