lecauchy=function(x,toler=.001){ #x is a vector here startvalue=median(x) n=length(x); thetahatcurr=startvalue; # Compute first deriviative of log likelihood firstderivll=2*sum((x-thetahatcurr)/(1+(x-thetahatcurr)^2)) # Continue Newton’s method until the first derivative # of the likelihood is within toler of 0.001 while(abs(firstderivll)>toler){ # Compute second derivative of log likelihood secondderivll=2*sum(((x-thetahatcurr)^2-1)/(1+(x-thetahatcurr)^2)^2); # Newton’s method update of estimate of theta thetahatnew=thetahatcurr-firstderivll/secondderivll; thetahatcurr=thetahatnew; # Compute first derivative of log likelihood firstderivll=2*sum((x-thetahatcurr)/(1+(x-thetahatcurr)^2)) } list(thetahat=thetahatcurr); } plotlikecauchy=function(x){ tht=seq(0,200, by = 0.1) li=numeric(length(tht)) for (i in 1:length(tht)){ li[i] = prod(1/(1+(x-tht[i])^2)); } plot(tht,log(li), type="l") return(tht[which.max(log(li))]) } data=c(221,171,198,189,189,135, 162, 135,117,162)