---
title: "Practice Set 5"
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
---

```{r setup}
#| include: false

# Do NOT modify this chunk
knitr::opts_chunk$set(
  collapse = TRUE, 
  warning = FALSE,
  message = FALSE,
  fig.height = 2.75, 
  fig.width = 4.25,
  fig.env = 'figure',
  fig.pos = 'h',
  fig.align = 'center')

# Use a color blind friendly color palette throughout doc
library(tidyverse)
cb_palette <- c("black", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
scale_colour_discrete <- function(...) scale_colour_manual(values = cb_palette, ...)
scale_fill_discrete   <- function(...) scale_fill_manual(values = cb_palette, ...)
theme_set(theme_bw())
```

# Purpose

The goal of this set of practice problems is to practice the following skills:

- Formulate descriptive, predictive, and causal research questions
- Connect the concepts of redundancy and multicollinearity to multiple $R^2$ and adjusted $R^2$
- Construct, interpret, and evaluate logistic regression models



# Directions

1. Create a code chunk in which you load the `ggplot2`, `dplyr`, and `readr` packages. Include the following command in the code chunk to read in the data: `games <- read_csv("https://mac-stat.github.io/data/boardgamegeeks.csv")`

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

## Context

We will be looking at data on the play characteristics and popularity of board games from the [Board Game Geek](https://boardgamegeek.com/) database. More information about the data and a codebook are available [here](https://github.com/Mac-STAT/data/blob/main/boardgamegeeks_codebook.md). The dataset contains many measures of game popularity (summaries of user ratings) and game attributes (categories, themes, and gameplay mechanics).

We will be exploring a range of research questions related to this data.



## Exercise 1: Descriptive, predictive, and causal questions

Suppose that you are an analyst helping out a local board game convention. Your job is to help convention attendees have a great time.
After exploring the [codebook](https://github.com/Mac-STAT/data/blob/main/boardgamegeeks_codebook.md), consider the following:

### Part a

Provide a (non-causal) *descriptive* research question that would help you do your job of helping conference attendees have a great time.

### Part b

Provide a *predictive* research question that would help you do your job of helping conference attendees have a great time.


### Part c

Provide a *causal* research question that would help you provide advice to a game designer.



## Exercise 2: Family and children's categories

**Question:** In terms of explaining average ratings, does a game being in the family category (`cat_family`) provide meaningfully different information from a game being in the children's category (`cat_childrens`)? That is, if we already have *one* of these predictors in a model of average ratings, does adding the other meaningfully improve the model?

### Part a

Fit 2 models that will allow you to address this question.
Show their model `summary()` tables.

### Part b

Report and compare the multiple and adjusted R-squared measures for these 2 models. Use this comparison to answer our question.


## Exercise 3: Popular or not?

Let's explore popularity by a different metric.
Define a game to be `popular` (TRUE or FALSE) if its `mean_rating` is over 8 AND the `p25_rating` is over 6.5:

```{r}
games <- games %>% 
  mutate(popular = (mean_rating > 8) & (p25_rating > 6.5))
```

### Part a

Construct *and* interpret a visualization that shows how popularity (`popular`) is related to a game's complexity (`game_weight`).


### Part b

Fit a simple logistic regression model called `log_mod_complexity` that models popularity (`popular`) by complexity (`game_weight`).
Show the model `summary()` table *and* calculate the exponentiated coefficient estimates (`exp()`).

### Part c

Interpret *both* coefficients from Part b in context (on the *odds* not log(odds) scale!).
Is the intercept meaningful in this context?


### Part d

Use your model to calculate the *probability* that a game with a complexity rating of "4" is popular.
You can use `predict()` to *check* your answer but must demonstrate how to obtain this calculation from the model coefficients.






## Exercise 4: More logistic regression models


### Part a

Construct *and* interpret a visualization that shows how popularity (`popular`) is related to whether or not a game was kickstarted (`kickstarted`).
Note: `kickstarted` is defined as `1` (game was kickstarted) or `0` (game wasn't kickstarted). To ensure that R views `kickstarted` as a categorical not quantitative variable, you will want to use `factor(kickstarted)` in your code.


### Part b

Fit a simple logistic regression model called `log_mod_kick` that models popularity (`popular`) by `kickstarted`.
Show the model `summary()` table *and* calculate the exponentiated coefficient estimates (`exp()`).


### Part c

Interpret *both* coefficients from Part b in context (on the *odds* not log(odds) scale!).
Is the intercept meaningful in this context?


### Part d

Use your model to calculate the *probability* that a game that was kickstarted is popular.
You can use `predict()` to *check* your answer but must demonstrate how to obtain this calculation from the model coefficients.





# Disclosures & citations

In this final section, please share whether you worked with others on this PS, whether you attended office hours to discuss this PS, 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 PSs, though all submitted work must be in your own words / code and you must be able to explain everything therein.
Did you discuss this PS / work on this PS 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 PS?
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 PS?
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:**





