Bulletin

Today

By the end of today you will

library(tidyverse)
library(tidymodels)
manhattan = read_csv("data/manhattan.csv")

Rent in Manhattan

On a given day in 2018, twenty one-bedroom apartments were randomly selected on Craigslist Manhattan from apartments listed as “by owner”. The data are in the manhattan data frame. We will use this sample to conduct inference on the typical rent of 1 bedroom apartments in Manhattan.

Part 1: Drawing a bootstrap sample

Let’s start by using bootstrapping to estimate the mean rent of one-bedroom apartments in Manhattan.

Exercise 1

What is the point estimate of the typical rent?

Exercise 2

Let’s bootstrap!

  • To bootstrap we will sample with replacement by drawing a value from the bowl.
  • How many draws do we need for our bootstrap sample?

Fill in the values from the bootstrap sample conducted in class. Once the values are filled in, uncomment the code.

# class_bootstrap <- c()

Exercise 3

  • About what value do you expect the bootstrap statistic to take?
  • Calculate the statistic from the bootstrap sample.
# add code

Part 2: Bootstrap confidence interval

We will use the infer package, included as part of tidymodels to calculate a 95% confidence interval for the mean rent of one-bedroom apartments in Manhattan.

We start by setting a seed to ensure our analysis is reproducible.

Generating the bootstrap distribution

We can use R to take many bootstrap samples and generate a bootstrap distribution

Uncomment the lines and fill in the blanks to create the bootstrap distribution of sample means and save the results in the data frame boot_dist.

Use 100 reps for the in-class activity. (You will use about 15,000 reps for assignments outsdie of class.)

set.seed(2252022)

boot_dist <- manhattan #%>%
  #specify(______) %>%
  #generate(______) %>%
  #calculate(______)
  • How many rows are in boot_dist?
  • What does each row represent?
  • What are the variables in boot_dist? What do they mean?

Visualize the bootstrap distribution

Visualize the bootstrap distribution using a histogram. Describe the shape, center, and spread of this distribution.

# add code

Calculate the confidence interval

Uncomment the lines and fill in the blanks to construct the 95% bootstrap confidence interval for the mean rent of one-bedroom apartments in Manhattan.

#___ %>%
#  summarize(lower = quantile(______),
  #          upper = quantile(______))

Interpret the interval

Write the interpretation for the interval calculated above.

Part 3: Changing the confidence level

#calculate a 90% confidence interval
#calculate a 99% confidence interval

Part 4: Additional practice

Next, use bootstrapping to estimate the median rent for one-bedroom apartments in Manhattan. - Generate the bootstrap distribution of the sample medians. Use 100 reps. Save the results in boot_dist_median.

set.seed(100)
## add code
## add code