Lab 4

Due: end-of-lab Friday September 24

Let’s continue worshiping the almighty dollar and study loan interest rates. We will consider this dataset on loans actually made through the Lending Club platform. The data were sourced from the OpenIntro project and then cleaned and simplified for your beneft. Please note that each row represents a loan that was actually originated. Not merely an application. So folks that were denied a loan do not appear here, which limits the sort of questions we can ask with these data.

loans <- read_csv("data/loans.csv")

Anyhow, these are the variables:

So the variables include a mix of information on the loan recipient’s financial condition and the details of the loan they were granted. We might expect that a person in a better financial situation is more likely to be offered favorable terms for a loan, and vice versa. So let’s see how a person’s situation predicts the interest_rate that they are offered on a loan. The better the situation, the lower the interest rate? Typically? On average? Sometimes? Oh I give up.

Setup

  1. Log-in to your container;
  2. Double-check that you have the sta101-f26-files project loaded in the upper-right corner of RStudio (this should always be true);
  3. 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 lab folder of your Files;
  4. 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 the authors so it lists yourself and your teammates.

Task 0

Prepare the data for analysis by doing two things:

  • Add a new variable to the data frame called credit_util which represents the recipient’s credit utilization: the proportion of their available credit that they are actually using;
  • Re-level the homeownership variable so that the levels go in order: Rent, Mortgage, Own.

Task 1

Explore the data with several visualizations:

  • Univariate: visualize credit_util by itself and describe the distribution;
  • Univariate: visualize homeownership by itself;
  • Multivariate: visualize interest_rate, credit_util, and homeownership on one plot.

Task 2

Fit a simple linear regression model that predicts interest_rate from credit_util. Display the results, write up the equation of the fitted model, and interpret all of the coefficient estimates.

Task 3

Fit an additive model that predicts interest_rate from credit_util and homeownership. Display the results, and interpret all of the coefficient estimates.

Task 4

Fit an interaction model that predicts interest_rate from credit_util and homeownership. Display the results, and then typeset the three equations for the fitted line of each group.

Task 5

Of the three models you just fit, which is “best”? What do you even mean by that?

Task 6

If we add issue_month as a predictor in the model you identified in the previous task, does it make things better or worse?

Submission

You collaborated with your team, but now everyone submits individually:

  1. Hit the blue Render button to generate your final PDF;
  2. 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;
  3. Download the PDF from your container;
  4. Upload it to Gradescope;
  5. Don’t forget to mark your pages.