par.est.theta <- function(sample){
n=length(sample)
log.lik<-function(theta){
return(-n*log(pi)-sum(log(1+(theta-sample)^2)));
}
diff.f<-function(theta){
return(-2*sum((theta-sample)/(1+(theta-sample)^2)))
}
hess.f<-function(theta){
return(matrix(-2*sum((1-(theta-sample)^2)/(1+(theta-sample)^2)^2),nrow=1));
}
theta.value=seq(-10,10,by=1);
plot(theta.value,log.lik(theta.value),xlab="parameter",
ylab="log-likelihood", type="l");
theta.est=nlminb(start=-11,-log.lik,-diff.f,-hess.f,lower=-10,upper=10);
return(theta.est);
}
a=c(1.77,-.23,2.76,3.8,3.47,56.75,-1.34,4.24,-2.44,3.29,3.711,-2.4,4.53,-.07,-1.05,13.87,-2.53,-1.75,0.27,43.21)
par.est.theta(a)