---
title: "Practice Problems 7"
author: "STUDENT NAME"
date: now
date-format: "YYYY-MM-DDTHH:mm:ssZ"
format:
  html:
    toc: true
    toc-depth: 2
    embed-resources: true
    code-tools: true   
    df-print: paged
---

<center>
**Due Friday, 11/21 at 11:59 pm on Moodle.**
</center>

# Purpose

The purpose of this assignment is to practice the following skills:

- Translating research questions into statistical models
- Constructing and interpreting confidence intervals for linear and logistic regression model coefficients
- Using confidence intervals to test statistical hypotheses
- Interpreting test statistics and p-values and using them to test statistical hypotheses



# Directions

1. Create a code chunk in which you load the `ggplot2`, `dplyr`, `broom`, and `readr` packages.

2. Continue with the exercises below. You will need to create new code chunks to construct visualizations and models and write interpretations beneath. Put text responses in blockquotes as shown below:

> Response here. (The > at the start of the line starts a blockquote and makes the text larger and easier to read.)

3. Render your work for submission:
    - Click the "Render" button in the menu bar for this pane (blue arrow pointing right). This will create an HTML file containing all of the directions, code, and responses from this activity. A preview of the HTML will appear in the browser.
    - Scroll through and inspect the document to check that your work translated to the HTML format correctly.
    - Close the browser tab.
    - Go to the "Background Jobs" pane in RStudio and click the Stop button to end the rendering process.
    - Locate the rendered HTML file in the folder where this file is saved. Open the HTML to ensure that your work looks as it should (code appears, output displays, interpretations appear). Upload this HTML file to Moodle.





# Exercises

## Exercise 1

> **Research question:** What is the causal effect of adolescent marijuana smoking on adulthood cigarette smoking?

To investigate this question, we will use data from the [Add Health Study](https://addhealth.cpc.unc.edu/). Read in the data below, and take a look at [this codebook](https://mac-stat.github.io/data/addhealth_codebook.html).

```{r}
addhealth <- read_csv("https://mac-stat.github.io/data/addhealth.csv") %>% 
  mutate(across(c(mathG, readG, parentED), factor))
```

### Part a

Analysts have determined `mathG`, `readG`, `parentED`, `white`, and `housesmoke` to be potential confounders of the relationship between adolescent marijuana smoking (`exposure`) on adulthood cigarette smoking (`smoke`).
Fit a *logistic* regression model that addresses our research question.
Show a model summary table.

### Part b 

Let $\beta$ be the (unknown) population coefficient of direct interest to our research question.
Interpret $\hat{\beta}$, the *sample estimate* of $\beta$ on the odds (not log odds) scale.


## Exercise 2

Continue to let $\beta$ be the (unknown) population coefficient of direct interest to our research question.


### Part a

Construct an approximate 95% confidence interval (CI) for $\beta$, on the exponentiated / odds scale, by using the Central Limit Theorem and the 68-95-99.7 Rule.
Show work for how you got to your final answer.

### Part b

Now obtain the exact 95% CI using `confint()`.


### Part c

Interpret the exact 95% CI from Part b in context.


### Part d

Based on the CI, do we have evidence of a "true" causal relationship between adolescent marijuana smoking and adulthood cigarette smoking in the broader population?
Provide a simple "Yes" or "No" answer and explain your answer.
(Assume here that the confounders we have adjusted for represent all confounders of the relationship.)




## Exercise 3

Continue to let $\beta$ be the (unknown) population coefficient of direct interest to our research question.
Let's consider hypothesis tests related to $\beta$ using test statistics and p-values.

### Part a

State the null and alternative hypotheses for $\beta$ (on the log odds scale) in context.
Comment on how the null and alternative hypotheses differ for the exponentiated coefficient.

### Part b

Report and interpret the test statistic for this hypothesis test.

### Part c

Report and interpret the p-value for this hypothesis test.

### Part d

Based on this p-value and a significance level of 0.05, do we have "statistically significant" evidence for a true causal relationship between adolescent marijuana smoking and adulthood cigarette smoking in the broader population?
Explain your answer.
(NOTE: Your general conclusion here should agree with that based on the CI in Part d of the previous exercise!)



## Exercise 4

> **Research question:** Does smoking decrease lung function in children?

To investigate this question, we will use data from a pediatric clinic. Read in the data below, and check out [this codebook](https://mac-stat.github.io/data/fev_codebook.html).

```{r}
fev <- read_csv("https://mac-stat.github.io/data/fev.csv")
```

### Part a

Analysts have determined `age`, `height`, and `sex` to be potential confounders of the relationship between smoking (`smoke`) and lung function as measured by forced expiratory volume (`fev`).
Fit a regression model that addresses our research question.
Show a model summary table.


### Part b 

Let $\beta$ be the (unknown) population coefficient of direct interest to our research question.
Interpret $\hat{\beta}$, the *sample estimate* of $\beta$.

### Part c

Construct an approximate 95% CI for $\beta$ by using the Central Limit Theorem and the 68-95-99.7 Rule.
Show work for how you got to your final answer.

### Part d

Now obtain the exact 95% CI using `confint()`.
*Interpret* this CI in context.


### Part e

Based on the CI, do we have evidence for a true causal relationship between smoking and lung function in the broader population of children?
Provide a simple "Yes" or "No" answer and explain your answer.
(Assume that the confounders we have adjusted for represent all confounders of the relationship.)







## Exercise 5

Continue to let $\beta$ be the (unknown) population coefficient of direct interest to our research question from Exercise 4.
Let's consider hypothesis tests related to $\beta$ using test statistics and p-values.

### Part a

State the null and alternative hypotheses for $\beta$ in context.

### Part b

Report and interpret the test statistic for this test.

### Part c

Report and interpret the p-value for this test.

### Part d

Based on this p-value and a significance level of 0.05, do we have evidence for a true causal relationship between smoking and lung function in the broader population of children?
Explain your answer.
(NOTE: Your general conclusion here should agree with that based on the CI in Part e of the previous exercise!)




# Disclosures & citations

In this final section, please share whether you worked with others on this PP, whether you attended office hours to discuss this PP, and whether and how you used AI.
This is here to both help *you* reflect on your approach to learning / assignment completion, and to help the *instructor / preceptors* understand what resources are being utilized.

## Working with others

You're encouraged to work with others on PPs, though all submitted work must be in your own words / code and you must be able to explain everything therein.
Did you discuss this PP / work on this PP with any other STAT 155 students?
If so, include their name(s) here.
NOTE: No worries if you put somebody's name and they don't put yours, or vice versa.

**Your response:**

## Attending office hours

Did you attend any office hours to get help on / discuss this PP?
If so, include the name of the preceptor or instructor whose office hours you attended and roughly how much time you spent in office hours.

**Your response:**

## AI

You're encouraged to AVOID the use of AI and to NEVER use it as your first approach to an exercise.
Learning comes from you doing the puzzling, not from you producing a correct answer.
Did you use AI for any part of this PP?
If so, describe: where you used it (on which exercises), how long you worked on the exercises before turning to AI, and what prompts you used / typed into AI.

**Your response:**





