rregci <-
function(x,y,regfun=chreg,nboot=599,alpha=.05, ...){
#
# Compute a .95 confidence interval for each of the parameters of
# a linear regression equation. The default regression method is
# a bounded influence M-regression with Schweppe weights
# (the Coakley-Hettmansperger estimator).
#
# When using the least squares estimator, and when n<250, use
# lsfitci instead.
#
# The predictor values are assumed to be in the n by p matrix x.
# The default number of bootstrap samples is nboot=599
#
# regfun can be any R function that returns the coefficients in
# the vector regfun$coef, the first element of which contains the
# estimated intercept, the second element contains the estimated of
# the first predictor, etc.
#
x<-as.matrix(x)
set.seed(2) # set seed of random number generator so that
# results can be duplicated.
print("Taking bootstrap samples. Please wait.")
data<-matrix(sample(length(y),size=length(y)*nboot,replace=TRUE),nrow=nboot)
bvec<-apply(data,1,regboot,x,y,regfun,...) # A p+1 by nboot matrix. The first row
# contains the bootstrap intercepts, the second row
# contains the bootstrap values for first predictor, etc.
p1<-ncol(x)+1
regci<-matrix(0,p1,2)
ilow<-round((alpha/2) * nboot)
ihi<-nboot - ilow
ilow<-ilow+1
se<-NA
pvec<-NA
for(i in 1:p1){
bsort<-sort(bvec[i,])
pvec[i]<-sum(bvec[i,]<0)/nboot
if(pvec[i]>.5)pvec[i]<-1-pvec[i]
regci[i,1]<-bsort[ilow]
regci[i,2]<-bsort[ihi]
se[i]<-sqrt(var(bvec[i,]))
}
pvec<-2*pvec
list(regci=regci,p.value=pvec,se=se)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.