---
title: "Practice Problems 8"
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 Saturday, 12/06 at 11:59pm on Moodle.**
</center>

# Purpose

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

- Interpreting test statistics and p-values and using them to test statistical hypotheses
- Determining when an F-test is needed/appropriate for a specific hypothesis


# Directions

1. Create a code chunk in which you load the `tidyverse` and `ggmosaic` 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.


# Context

Throughout this problem set, we'll continue working with data on poisonous mushrooms.
In addition to cap shape, we now have information on gill size as well.
We will investigate whether this additional variable adds "value" to our logistic regression model, in addition to cap shape.

```{r warning = FALSE, message = FALSE}
# Read in mushroom data
mushrooms <- read_csv("https://Mac-STAT.github.io/data/mushrooms.csv")
```

# Exercises

## Exercise 1

### Part a

Construct a visualization of the relationship of `poisonous` status with `gill_size`.


### Part b

In 1-2 sentences, comment on what you learn from the plot in part a.




## Exercise 2

### Part a 

Fit a multiple logistic regression model of whether or not a mushroom is `poisonous` by 2 predictors: its `shape` and `gill_size`.
Do not include an interaction term.
Show a model `summary()` table.


### Part b

Interpret the coefficient for the `cap_shapesunken` coefficient, in context and on the odds scale.



## Exercise 3

### Part a

State the null and alternative hypothesis associated with the p-value given by the logistic regression summary output for the `cap_shapesunken` coefficient.
Use symbols / notation, including $\beta_?$ notation, not words.

$H_0:$ ???

$H_1:$ ???

### Part b

The hypothesis test in Part a only tests whether or not the log(odds) / odds of being poisonous differ for sunken vs bell shaped mushrooms, after adjusting for gill size.
It does not address *all* differences between *all* cap shapes when adjusting for gill size.
State the appropriate null and alternative hypothesis that would address this question.
Use symbols / notation, including $\beta_?$ notation, not words.

$H_0:$ ???

$H_a:$ ???


### Part c

Conduct the hypothesis test you stated in Part b at the 0.05 significance level.
Just include your code here.


### Part d

For the test in Part c, state a conclusion in context and support your conclusion with the appropriate p-value.


## Exercise 4

Returning to our original research question, we wanted to investigate whether gill size added "value" to our logistic regression model, in addition to cap shape.
Let's consider "value" in terms of statistical significance.

### Part a 

State the appropriate hypotheses, again using notation / symbols.


### Part b 

Report the test statistic and p-value for this test.
(You can but are not required to interpret these.)
THINK: Can you use a t-test from the original model summary table, or do you need to do an F test?

### Part c

At the 0.05 significance level, do we have evidence that gill size added "value" to our logistic regression model, in addition to cap shape? 
Explain.


## Exercise 5

Again, recall our original research question about whether gill size added "value" to our logistic regression model, in addition to cap shape.
Let's consider "value" by comparing the overall accuracy, sensitivity, and specificity of 2 models, 1 that predicts `poisonous` using `cap_shape` alone and 1 that predicts `poisonous` using both `cap_shape` and `gill_size`:

- `poisonous ~ cap_shape`

- `poisonous ~ cap_shape + gill_size`

### Part a

Using a probability threshold of 0.5, the (overall) accuracy, sensitivity, and specificity of the `poisonous ~ cap_shape` model are summarized in the table below.
Calculate these quantities for our model of `poisonous ~ cap_shape + gill_size`.
Show your work for the calculations and put the final results in the table below:

|             | cap_shape | cap_shape + gill_size |
|-------------|-----------|-----------------------|
| accuracy    | 0.56      | ????                  |
| sensitivity | 0.15      | ????                  |
| specificity | 0.95      | ????                  |

### Part b

For each of the following metrics separately, determine whether `gill_size` added value to our logistic regression model:

> Overall accuracy: 

> Sensitivity: 

> Specificity: 

### Part c

Suppose you are going mushroom hunting.
Would you prefer a model with higher sensitivity or higher specificity?
Explain your answer, and using this justification, conclude which model from Part a you would prefer.


# 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:**




