Sebastian112
Sebastian112

Reputation: 41

Confidence Interval for Standard Deviations from Bootstrapping in R

I'm new to bootstrapping. I would like to find the CIs for the SDs generated from a bootstrap and was wondering if I had done it correctly. Thank you!

Repnumber <- 1000                    
group1.sd.values <- numeric(Repnumber)    

for (i in 1:Repnumber){
group1 = sample(Data, size=length(Data), replace=T)
group1.sd.values[i] = sd(group1)
}

group1.sd.upperCI <- quantile(group1.sd.values, probs = .975) 
group1.sd.lowerCI <- quantile(group1.sd.values, probs = .025)

Upvotes: 0

Views: 1258

Answers (1)

MichaelChirico
MichaelChirico

Reputation: 34763

Here's how I do bootstrapping on a single vector:

CI <- quantile(replicate(Repnumber, sd(sample(Data, rep = TRUE))), c(.025, .975))

This will give you the upper and lower values of the interval in a length-2 vector.

Note that using replicate should in general be much faster than looping.

Upvotes: 1

Related Questions