We will now consider the Boston
housing data set, from the MASS
library.
Some of the exercises are not tested by Dodona (for example the plots), but it is still useful to try them.
Based on this data set, provide an estimate for the population mean of medv
, referred to as \(\hat{\mu}\).
Store this estimate in mu.hat
.
Provide an estimate of the standard error of \(\hat{\mu}\). Store this in est.sd
. Interpret the result.
Now estimate the standard error of \(\hat{\mu}\) using the bootstrap.
boot.fn.mean()
that returns the coefficients of a linear regression model with coef()
.
The model is fitted on a dataset data
with indices index
.
Notice that you only need to include an intercept as independent variable to find the mean.boot()
function together with your boot.fn.mean()
function to estimate the standard errors of the mean.
Don’t forget to load the library boot
in your R session.
Set a seed of 1 before running boot()
and specify that we want 10 bootstrap samples.
Store the result in boot.se.mean
. (Note: this command takes a few seconds to run)boot.se.mean2
.
It is not a good practice to hardcode quantities in variables but
boot()
unfortunately has no attribute that returns the desired quantity.
medv
.
Hint: you can approximate a 95% confidence interval using the formula \([\hat{\mu} - 2SE(\hat{\mu}), \hat{\mu} + 2SE(\hat{\mu})]\).
Compare it to the results obtained using t.test(Boston$medv)
.
Based on this data set, provide an estimate, \(\hat{\mu}_{med}\), for the median value of medv
in the population.
Store the result in medv.median
.
We now would like to estimate the standard error of \(\hat{\mu}_{med}\).
Unfortunately, there is no simple formula for computing the standard error of the median.
Instead, estimate the standard error of the median using the bootstrap.
boot.fn.median()
that returns the median value for medv
in a dataset data
with indices index
.boot()
function together with your boot.fn.median()
function to estimate the standard errors of the median.
Set a seed of 1 before running boot()
and specify that we want 10 bootstrap samples.
Store the result in boot.se.median
. (Note: this command takes a few seconds to run)boot.se.median2
.
Based on this data set, provide an estimate for the tenth percentile of medv
in Boston suburbs, referred to as \(\hat{\mu}_{0.1}\).
Store the result in perc10
.
Use the bootstrap to estimate the standard error of \(\hat{\mu}_{0.1}\). Comment on your findings.
boot.fn.perc()
that returns the tenth percentile for medv
in a dataset data
with indices index
.boot()
function together with your boot.fn.perc()
function to estimate the standard errors of the tenth percentile.
Set a seed of 1 before running boot()
and specify that we want 10 bootstrap samples.
Store the result in boot.se.perc
. (Note: this command takes a few seconds to run)boot.se.perc2
.
boot.se.mean2
, boot.se.median2
, and boot.se.perc2
.
Assume that:
MASS
library has been loadedBoston
dataset has been loaded and attachedboot
library has been loaded