I have a linear model:
fit <- lm(lifespan ~ log(Metabolic.by.mass), data = anage)
I've predicted my y-value for an x-value of -6.10529 using this model which is determined to be 17.34775. Now I'm trying to create a 95% confidence interval for that quantity using the nonparametric bootstrap for 1000 iterations and the pivotal confidence interval.
So far I have:
resample = function(x) {
sample(x, size = length(x), replace = TRUE)
}
B = 1000
pred <- numeric(B)
for (ii in 1:B) {
boot <- resample(seq(1, nrow(anage)))
fit <- lm(lifespan ~ log(Metabolic.by.mass), data = anage[boot,])
pred[ii] <- predict(fit) + sample(resid(fit), size = 1)
}
quantile(pred, c(0.025, 0.975))
However, this confidence interval looks to be too large. Is there another way to find the 95% pivotal confidence interval for this value?