Lab 7
Due: end-of-lab Friday November 6
Recall the baby data from Homework 5:
We want to understand how reliably we can estimate the relationship between the mother’s age in years (mage) and the birth weight in pounds of the baby (weight). You already did simulation-based inference. Now let’s do inference using the bell curve.
The in-class activity from Tuesday introduced basic commands for working with the bell curve. You may find some of them useful today.
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.
Task 1
Fit (and store!) the simple linear regression weight ~ mage using both techniques we have seen: the one involving linear_reg and the one involving specify. Display both sets of results and verify that they match.
Task 2
Use the filter and pull commands to extract the point estimate and the standard error for the slope from the regression outputs in the previous part. Store these values in new variables b1 and SE.
Task 3
The central limit theorem (and other results) says that if our sample size is large enough, the sampling distribution of the regression slope can be approximated by \(\text{N}(b_1,\,\text{SE})\). Based on this approximation and your numbers from the previous part, use the qnorm command to compute the lower bound and upper bound of a 90% confidence interval for the slope.
Task 4
Use ggplot together with the new layers stat_function and geom_vline to plot the normal distribution and the bounds of your confidence interval.
Task 5
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} \]
So that we all get the same results, you should use the random number seed 123 and you should do 500 repititions of the simulation.
If you need a refresher, see last week’s lab or in-class activity.
Task 6
The central limit theorem (and other results) says that if our sample size is large enough, the null distribution of the regression slope can be approximated by \(\text{N}(0,\,\text{SE})\). Let’s use this approximation to re-do the test from the previous part.
- Use the
normTailcommand to visualize the \(p\)-value of the test; - Use the
pnormcommand to calculate the \(p\)-value of the test.
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.
