I have attached R boot package (1) A researcher is interested in better understanding variability in birth weights of children whose mothers suffer from a particular disease. She takes a SRS of size 12 and records the resulting birth weight in pounds (given below) 3.5, 5.4, 4.2, 4.0, 4.8, 4.8, 3.4, 3.9, 4.7, 4.9, 4.5, 4.5 interquartile range (IQR = Q3-Q1) to measure variabil can be calculated in (a) She decides to use ity. Calculate the IQR for these data.Note that IQR R via: quantile(data,. 75) - quantile(data,.25) (b) She also wishes to construct a 95% confidence interval for IQR. Use R to create the interval using the percentile method with B = 2,000. You may use the R boot package use R to create the same interval using the BCA method with B=2,000. (c) Now, You will want to use the R boot package.
#non-parametric BS
data("faithful")
hist(faithful$eruptions)
#pretend it is reasonable to think that these data are normal
t.test(faithful$eruptions)
#pretend it is reasonable to think that these data are from loc-scale family
#get CI for mean
B <- 1000
boot.samp <- rep(NA,times=B)
for (b in 1:B){
boot.dat <- faithful$eruptions[sample(1:length(faithful$eruptions),length(faithful$eruptions),replace = TRUE)]
boot.samp[b] <- (mean(boot.dat) - mean(faithful$eruptions))/(sd(boot.samp)/sqrt(length(faithful$eruptions)))
}
mean(faithful$eruptions) - quantile(boot.samp,.975)*sd(faithful$eruptions)/sqrt(length(faithful$eruptions))
mean(faithful$eruptions) + quantile(boot.samp,.975)*sd(faithful$eruptions)/sqrt(length(faithful$eruptions))
#percentile method for
B <- 1000
boot.samp <- rep(NA,times=B)
for (b in 1:B){
boot.dat <- faithful$eruptions[sample(1:length(faithful$eruptions),length(faithful$eruptions),replace = TRUE)]
boot.samp[b] <- median(boot.dat)
}
quantile(boot.samp,.025)
quantile(boot.samp,.975)
#residual method for median
B <- 1000
boot.samp <- rep(NA,times=B)
for (b in 1:B){
boot.dat <- faithful$eruptions[sample(1:length(faithful$eruptions),length(faithful$eruptions),replace = TRUE)]
boot.samp[b] <- median(boot.dat) - median(faithful$eruptions)
}
median(faithful$eruptions) - quantile(boot.samp,.975)
median(faithful$eruptions) - quantile(boot.samp,.025)
#use R bootstrap package
library("boot")
boot.out <- boot(data=faithful$eruptions,statistic =
boot.ci(boot.out,type=c("perc", "bca"))


Trending now
This is a popular solution!
Learn your way
Includes step-by-step video
Step by step
Solved in 3 steps with 3 images









