1. ## Bootstrap confidence interval

Hey guys, Would you guys please help me do this exercise ? as I'm new to R program and also not very good at it. I need to have this homework finished by this friday but still can not figure it out how to do it. It's about how to construct bootstrap confidence interval by using R program. And I saved it as PDF file. Thank you very much for your help

2. ## Re: Bootstrap confidence interval

Why don't you start from Kabacoff's page on bootstrapping. There is an example on how to compute 95% bootstrap CI for model estimates.

Code:
``````
## From Kabacoff's page

library(boot)

# function to obtain regression
bootstrap<- function(formula, data, indices) {
d <- data[indices,] # allows boot to select sample
fit <- lm(formula, data=d)
return(coef(fit))
}

# bootstrapping with 1000 replications
results <- boot(data=test, statistic=bootstrap, R=1000, formula=y~x)

# Get 95% confidence interval for the slope
boot.ci(results, type="bca", index=2)  ## for the slope``````
HTH

3. ## Re: Bootstrap confidence interval

Thank you Ledzep. I already checked it out but I still don't really get it. I did try to do it but It was said there were over 50 warnings, so would you please help me check it this code for me ?

function (n,alpha,B)
{
L=numeric(B)
U=numeric(B)

for(j in 1:B)
{
x=c(2,4,6,8,10,12,14)
y=c(63,128,194,257,322,387,451)
t=qt(alpha/2,n-2)

xbar.b=numeric(B)
ybar.b=numeric(B)
for(i in 1:n)
{
xb=sample(x,n,replace=T)
x.bar = mean(xb)
yb=sample(y,n,replace=T)
y.bar = mean(y)
}
xbar=mean(x.bar)
ybar=mean(y.bar)

b1 = (sum(x*y)-(n*(xbar)*(ybar)))/(sum(x^2)-(n*(xbar^2)))
b0 = (ybar)-(b1*xbar)
y.hat = b0+(b1*x)
s2 = sum((y-y.hat)^2)/n-2
s2.b1 = s2/(sum(x^2)-(n*((xbar^2))))
s.b1 = sqrt(s2.b1)

L=b1-abs((t*s.b1))
U=b1+abs((t*s.b1))
}
out=cbind(Lower=L,Upper=U)
print(out)

}

4. ## Re: Bootstrap confidence interval

> fix(bootstrap)
> bootstrap(7,0.05,1000)
Lower Upper
[1,] -320.7183 703.0341
There were 50 or more warnings (use warnings() to see the first 50)
this is what I got.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts