myT<-function(x) { return( c(mean(x)-2*sd(x)/sqrt(length(x)), mean(x)+2*sd(x)/sqrt(length(x))) ) } myLR<-function(x) { myfunc<-function(mu,x){length(x)*log(sum((x-mu)^2)/sum((x-mean(x))^2))-3.84} lo=uniroot(myfunc,lower=mean(x)-5*sd(x),upper=mean(x),x=x)$root hi=uniroot(myfunc,lower=mean(x),upper=mean(x)+5*sd(x),x=x)$root return(c(lo,hi)) } do.it<-function(x) { tmp=rbind(myT(x),myLR(x)) tmp=as.data.frame(tmp) dimnames(tmp)[[1]]=c('t','LR') dimnames(tmp)[[2]]=c('lo','hi') return(tmp) }