CS计算机代考程序代写 ## ——————————————

## ——————————————
##
## ST4060 / ST6015 / ST6040
## R script – Fri 8 Oct 2021 lecture
## Eric Wolsztynski
##
## ——————————————

## ——————————————

plot(cars, pch=20, cex=2)

x = cars$speed
y = cars$dist
lmo = lm(y~x)

N = nrow(cars)
B = 100
est = numeric(B)
for(b in 1:B){
ib = sample(1:N, size=N, replace=TRUE)
xb = x[ib]
yb = y[ib]
lmb = lm(yb~xb)
est[b] = coef(lmb)[2]
}
hist(est)
abline(v=coef(lmo)[2], col=’green’, lwd=4)

# bootstrap mean estimate…:
mean(est)
coef(lmo)[2]
# … and bootstrap estimate of the bias:
mean(est)-coef(lmo)[2]
# bootstrap SE estimate:
sd(est)
# Naive bootstrapped 95% CI:
quantile(est, c(.025,.975))