#' Bootstrap Confidence interval
#'
#' Creates a bootstrap 1-alpha confidence interval with the point estimate for a parameter from the population
#'
#' @param iter number of iterations the sample will be run
#' @param x a vector of numbers which makes up the sample of the population
#' @param fun the parameter of the sample estimated
#' @param alpha the likelihood that the true population parameter lies outside the confidence interval
#' @param cx controls the final character size for text on the graph
#' @param ... ellipse allow added parameters to be added to control the format of the histogram
#'
#' @return A histogram with the point estimate of the statistic and the confidence interval
#' @export
#'
#' @examples
#' myboot2(x=fire$DAMAGE)
myboot2<-function(iter=10000,x,fun="mean",alpha=0.05,cx=1.5,...){
n=length(x)
y=sample(x,n*iter,replace=TRUE)
rs.mat=matrix(y,nr=n,nc=iter,byrow=TRUE)
xstat=apply(rs.mat,2,fun)
ci=quantile(xstat,c(alpha/2,1-alpha/2))
para=hist(xstat,freq=FALSE,las=1,
main=paste("Histogram of Bootstrap sample statistics","\n","alpha=",alpha," iter=",iter,sep=""),
...)
mat=matrix(x,nr=length(x),nc=1,byrow=TRUE)
pte=apply(mat,2,fun)
abline(v=pte,lwd=3,col="Black")
segments(ci[1],0,ci[2],0,lwd=4)
text(ci[1],0,paste("(",round(ci[1],2),sep=""),col="Red",cex=cx)
text(ci[2],0,paste(round(ci[2],2),")",sep=""),col="Red",cex=cx)
text(pte,max(para$density)/2,round(pte,2),cex=cx)
invisible(list(ci=ci,fun=fun,x=x))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.