Consider the father.son data in the UsingR package. Create an R markdown document with the following: 1. Plot the bootstrap distribution of the correlation between father and son heights 2. A bootstrap standard error for the correlation between father and son heights. 3. A 95% bootstrap confidence interval for the correlation between the father and son heights.
data(father.son)
attach(father.son)
Plot the bootstrap distribution of the correlation between father and son heights
n = nrow(father.son)
fun1 = function(x,i=c(1:n)){
x_i = x[i,]
return(cor(x_i$fheight,x_i$sheight))
}
Bcorr = boot(data = father.son, statistic=fun1, R = 1000)
fsCor = Bcorr$t;
hist(fsCor,main="Bootstrap distribution of the correlation between father and son heights",xlab="correlation", breaks=40, freq=FALSE)
A bootstrap standard error for the correlation between father and son heights.
sd_corr = sd(fsCor)
sd_corr
## [1] 0.02144559
Standard error of the correlation between father and son heights is 0.021.
A 95% bootstrap confidence interval for the correlation between the father and son heights.
Q = quantile(fsCor, c(0.025, 0.975))
Q
## 2.5% 97.5%
## 0.4601029 0.5413277
95% bootstrap CI for the correlation is 0.458 - 0.544.