loans <- read_csv("data/loans.csv")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.
Anyhow, these are the variables:
-
interest_rate: interest rate of the loan the applicant received; -
loan_amount: the amount of the loan the applicant received; -
term: the number of months of the loan the applicant received; -
issue_month: month the loan was issued; -
homeownership: does the loan recipient rent, mortgage, or own their home? -
debt_to_income: debt-to-income ratio; -
total_credit_utilized: total credit balance, excluding a mortgage; -
total_credit_limit: total available credit, e.g. if only credit cards, then the total of all the credit limits. This excludes a mortgage;
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
- Log-in to your container;
- Double-check that you have the
sta101-f26-filesproject loaded in the upper-right corner of RStudio (this should always be true); - 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
labfolder of your Files; - 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 theauthorsso 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_utilwhich represents the recipient’s credit utilization: the proportion of their available credit that they are actually using; -
Re-level the
homeownershipvariable so that the levels go in order: Rent, Mortgage, Own.
Task 1
Explore the data with several visualizations:
-
Univariate: visualize
credit_utilby itself and describe the distribution; -
Univariate: visualize
homeownershipby itself; -
Multivariate: visualize
interest_rate,credit_util, andhomeownershipon 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:
- Hit the blue Render button to generate your final PDF;
- 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;
- Download the PDF from your container;
- Upload it to Gradescope;
- Don’t forget to mark your pages.
