Problem set 5
Multiple regression
Purpose
Chapter 6 in ModernDive extends basic regression to models with more than one explanatory variable. Multiple regression lets you look at the relationship between an outcome and one explanatory variable while holding other variables constant, which lets you look at averages and relationships while accounting for other variables.
In this problem set, you’ll run and interpret multiple regression models with numeric and categorical explanatory variables using real data from the V-Dem (Varieties of Democracy) project. You’ll revisit two models from Problem Set 4 and see what happens to them when you account for GDP per capita. You’ll also keep using the {dplyr} and {ggplot2} skills you’ve built so far. By the end, you should be able to:
- Use
filter(),drop_na(), andmutate()to prepare a dataset for analysis, including rescaling a variable (like measuring GDP per capita in thousands of dollars) so that its coefficient is easier to interpret - Calculate a correlation matrix with
select()andcor()to see how an outcome is related to several explanatory variables, and how the explanatory variables are related to each other - Use
group_by()andsummarise()to compare groups before running a model - Fit a multiple regression model with
lm(y ~ x1 + x2)and look at the results withget_regression_table() - Interpret coefficients in a model with one numeric and one categorical explanatory variable, including writing out the separate equation for each group
- Visualize a model with one numeric and one categorical explanatory variable with
geom_parallel_slopes(), and judge whether straight lines fit the data well - Interpret partial slopes in a model with two numeric explanatory variables, making clear what is being held constant
- Interpret coefficients for a categorical variable with many categories as differences from a baseline group, holding other variables constant
- Explain why a coefficient changes (and can even flip direction) when you add another explanatory variable to a model
Criteria for success
This problem is graded using a ✔+/✔/✔− system. I’m looking for correct code and genuine attempts at the interpretation questions, not polished prose.
- ✔+: All chunks run without errors and use the correct functions, variables, and models. There are no warnings or messages/ The datasets, models, and plots you create match the expected output shown in the instructions. The written answers correctly interpret coefficients in plain language with the correct units and say what’s being held constant (e.g., “among countries with the same GDP per capita, democracies have 14.5 fewer child deaths per 1,000 live births than autocracies, on average,” not just “the democracy coefficient is −14.5”). Explanations for why coefficients change between models use the correlations and group averages you calculated. The extension does something new and exciting rather than only copying a previous chunk.
- ✔: This is the expected level of performance. All chunks run and produce mostly correct results; minor mismatches (e.g., column names or rounding) are fine. Written interpretations are attempted and reasonable, though they may be missing units, forget to mention what’s held constant, or mix up small details.
- ✔−: Chunks are missing, don’t run, or use the wrong variables or model (e.g., leaving out one of the explanatory variables or switching x and y in
lm()). Written answers are left blank or only restate numbers from the output without interpreting them.
You may work together in groups of up to four, but you must turn in your own answers and note who you worked with.
And remember: everything human-facing must be human-generated. Don’t submit AI-generated text. I want to hear your voice.
Also, if you do use LLMs to help with the code (I recommend not!), make sure you follow the guidelines from the syllabus about how to cite what you use.
How to submit
Submit a single rendered PDF on Canvas.
Instructions
Download this
.zipfile. Make sure you unzip or extract it after you download it! Open the unzipped folder in Positron.-
04-problem-set.zip - Posit.cloud project: Use this link if you’re using Posit.cloud on your iPad.
-
Rename the Quarto file named
your-name_problem-set-5.qmdto something that matches your name.Complete the tasks given in the Quarto file. You can definitely copy, paste, and adapt from other code in the document—don’t try to write everything from scratch!
This problem set uses the {moderndive} package. If you get an error saying
there is no package called 'moderndive', install it first by going to the Packages panel and searching for “moderndive,” or by runninginstall.packages("moderndive")in the console.When you’re all done, render the document to Typst (pdf), PDF, or Word. Upload that file to Canvas. Do not upload a rendered HTML file (they don’t work on Canvas).