Boston

Import data

library(MASS)
attach(Boston)
medv = Boston$medv

a)

uHat = mean(medv)
uHat
## [1] 22.53281

b)

n = length(medv)
sdMedv = sd(medv)/sqrt(n)
sdMedv
## [1] 0.4088611

c)

N = 10^4
medv.mean = numeric(N)
medv.median = numeric(N)
medv.tenth = numeric(N)

for (i in 1:N)
{
  x = sample(medv, n, replace = TRUE)
  medv.mean[i] = mean(x)
  medv.median[i] = median(x)
  medv.tenth[i] = quantile(x, c(0.1))
}

sd(medv.mean)
## [1] 0.407738
sdMedv/sd(medv.mean)
## [1] 1.002755

Our answer from part b is 0.9925 the size of our bootstrap estimation.

d)

quantile(medv.mean, c(0.025, 0.975))
##     2.5%    97.5% 
## 21.74447 23.33720
t.test(medv)
## 
##  One Sample t-test
## 
## data:  medv
## t = 55.111, df = 505, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  21.72953 23.33608
## sample estimates:
## mean of x 
##  22.53281

The 95% method is sufficient for bootstrap because the distribution is approximately bell-shaped. The t-test method produces a confidence interval with negligible difference to that of the bootstrap.

e)

mean(medv.median)
## [1] 21.19018

We estimate value of medv to be 21.195

f)

sd(medv.median)
## [1] 0.3753614
quantile(medv.median, c(0.025, 0.975))
##  2.5% 97.5% 
##  20.5  21.9

The standard error of the median of the bootstrap is 0.377. We can say that our stimation of the sample median falls within the interval [20.5, 21.9] 95% of the time.

g)

mean(medv.tenth)
## [1] 12.76314

The tenth percentile of medv is estimated to be 12.758 from our bootstrap.

h)

hist(medv.tenth)

biasBoot = mean(medv.tenth)-quantile(medv, c(.1))
biasBoot/quantile(medv, c(.1))
##         10% 
## 0.001030196
sd(medv.tenth)
## [1] 0.4976625

The histogram is assymetric and not bell-shaped, however the ratio of the boot bias to the sample quantile is remarkably small. For that reason we can expect the standard deviation of the tenth percentile boot to be somewhat reliable.