x<-rt(250,df=9) par(pty="s") qqnorm(x); qqline(x) x<-rcauchy(250) qqnorm(x) qqline(x) help(ppoints) library(MASS) help(fitdistr) list(location=0,scale=1) fitdistr(x,dcauchy,start=list(location=0,scale=1)) logLik(fitdistr(x,dcauchy,start=list(location=0,scale=1))) logLik(fitdistr(x,dcauchy,start=list(location=0),scale=1)) help(optimize) mu<-seq(from=-1,to=1,by=.1) apply(outer(mu,x,logdcauchy),1,sum) logdcauchy<-function(mu,x){ dcauchy(x,scale=1,location=mu,log=TRUE)} apply(outer(mu,x,logdcauchy),1,sum) loglikcauchy<-function(mu){ apply(outer(mu,x,logdcauchy),1,sum)} logdcauchy loglikcauchy loglikcauchy(0) optimize(loglikcauchy,lower=-1,upper=1) result<-optimize(loglikcauchy,lower=-1,upper=1) mu<-seq(from=-1,to=1,by=.01) plot(mu,loglikcauchy(mu),type="l") optimize(loglikcauchy,lower=-1,upper=1) points(result[[1]],result[[2]]) negloglikcauchy<-function(mu){ -apply(outer(mu,x,logdcauchy),1,sum)} optimize(negloglikcauchy,lower=-1,upper=1) result<-optimize(negloglikcauchy,lower=-1,upper=1) points(result[[1]],-result[[2]]) abline(h=-result[[2]]-(qchisq(0.95,1)/2)) mu<-seq(from=-.4,to=.4,by=.01) optimize(negloglikcauchy,lower=-.4,upper=.4) plot(mu,loglikcauchy(mu),type="l") result<-optimize(negloglikcauchy,lower=-.4,upper=.4) points(result[[1]],-result[[2]]) abline(h=-result[[2]]-(qchisq(0.95,1)/2))