attach(faithful) #Make data available to the R session #Define the negative log-likelihood nllhood=function(theta,y) { p=theta[1];mu=theta[2];sigma=theta[3];nu=theta[4];tau=theta[5] lhood=p*dnorm(y,mu,sigma)+(1-p)*dnorm(y,nu,tau) return(-sum(log(lhood))) } #Use start values inferred from histogram Faithful.fit=optim(c(0.4,52,5,80,5),nllhood,y=waiting,hessian=T) MLE=Faithful.fit$par ObsInfo=Faithful.fit$hess #Observed Fisher information matrix Vhat=solve(ObsInfo) #Inverse of observed Fisher information Std.Errors=sqrt(diag(Vhat)) #Obtain the MLEs,estimated std errors, and approx Wald 95% CIs Wald.table=cbind(MLE, Std.Errors,LowerBound=MLE-qnorm(0.975)*Std.Errors, UpperBound=MLE+qnorm(0.975)*Std.Errors) parnames=c("p","mu","sigma","nu","tau") rownames(Wald.table)=parnames round(Wald.table,4) #Print to 4 decimal places.