rdu_flights <- read_csv("data/rdu-flights.csv")Lab 6
Due: end-of-lab Friday October 30
In this lab you’ll explore the relationship between distance (in miles) and air time (in minutes) of flights out of RDU in 2024.
Setup
- Log-in to your container;
- Double-check that you have the
sta101-f26-filesproject loaded in the upper-right corner of RStudio (this should always be true); - Go to the “Git” tab in the upper-right panel of RStudio and click the Pull button (arrow pointing down). Now the new assignment template and dataset should appear in the
labfolder of your Files; - At the top of the new
.qmd, in between---, you have the settings for the document (the so-called YAML, but don’t worry about that). Modify theauthorsso it lists yourself and your teammates.
Question 1 - visualization
Visualize the relationship between distance (x) and air_time (y) using a scatter plot. Add a regression line to the scatter plot, but do not display the standard error ribbon around the regression line. Comment on the observed relationship.
Question 2 - point estimation
Estimate the simple linear regression predicting air time from distance. Display the output and interpret the coefficients.
Question 3 - interval estimation
Compute a 95% bootstrap interval for the slope of the regression line for predicting air_time from distance. In your narrative, provide an interpretation of the 95% confidence interval for the slope. Also, don’t forget to set a random number seed so that your results are reproducible. Everyone on your team should get exactly the same numbers.
Below is a step-by-step recipe for constructing a confidence interval. The code snippets shown are not “complete.” They include some blanks you need to fill in, and they are just intended to guide you in the right direction.
- Step 1: Calculate the point estimate for the slope and the intercept of the regression line. You technically already did this, but you need to use the new syntax that plays nice with the code that runs the simulations.
obs_fit <- rdu_flights |>
specify(______ ~ ______) |>
fit()- Step 2: Simulate a bootstrap distribution of regression estimates.
boot_dist <- rdu_flights |>
specify(_____ ~ ______) |>
generate(reps = ____, type = _______) |>
fit()- Step 3: Calculate the bounds of the confidence interval.
conf_ints <- get_confidence_interval(
____,
level = ___,
point_estimate = ____
)Question 4 - hypothesis testing
Calculate, visualize, and interpret the \(p\)-value from a permutation test for the following hypotheses:
\[ \begin{aligned} \text{H}_0&: \beta_1=0\\ \text{H}_A&: \beta_1\neq 0. \end{aligned} \]
The code for this is almost identical to the code for bootstrapping, with some small but crucial alterations:
null_dist <- rdu_flights |>
specify(_____ ~ ______) |>
hypothesize(null = ________) |>
generate(reps = ____, type = _______) |>
fit()
pval <- get_p_value(
____,
obs_stat = ___,
direction = ____
)Submission
You collaborated with your team, but now everyone submits individually:
- Hit the blue Render button to generate your final PDF;
- Give your work a final look over to double-check a few things:
- that your code is stylish;
- that none of your code or pictures runs off the page. We cannot grade what we cannot read;
- that all of your plots are well-labeled and human-readable. In other words “Flipper length (mm)” instead of
flipper_length_mm; - If your work is lacking on any of these items, fix them and re-render as needed;
- Download the PDF from your container;
- Upload it to Gradescope;
- Don’t forget to mark your pages.
