# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .r
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: R
#     language: R
#     name: ir
# ---

# # Chapter 3 Exercise 10
# Textbook page 123, PDF page 137.

# ## Setup Code (ok to hide)

# +
# install.packages(c("moderndive","skimr","ISLR","ggfortify","GGally"))
# -

library(tidyverse)
library(moderndive)
library(skimr)
library(ISLR)
library(GGally)    ## ggpairs
library(ggfortify) ## autoplot

options(width=110)

# ## (z) Exploratory analysis
#
# Examine:
#
# * Raw data
# * Summary statistics
# * Graph

# ## (a) Predict Sales with Price, Urban, US

# Show a summary of your multiple regression.

# ## (b) Provide an interpretation of each coefficient
# Be careful with qualitative variables!

# ## (c) Write out the model in equation form
# For qualitative variabkes you should use an indicator variable $1_{\text{var}}$ or braces
# \\[
# \beta_0 + 
# \begin{cases} 
# \beta_1 + \beta_2 \times \text{var} & \text{if good} \\
# \beta_2 & \text{otherwise}
# \end{cases}
# \\]
#
# Typesetting note: displayed math is `\\\[ ... \\\]`, inline math is `$ ... $`.

# ## (d) For which of the predictors can you reject the null hypothesis?
#
# The null hypothesis is that the variable's coefficient in the linear model is 0.

# ## (e) Smaller model.
# On the basis of your response to the previous question, fit a smaller model that uses only the predictors for which there is eidence of association with the outcome.

# ## (f) How well do (a) and (e) fit the data?
# Do some math and summarize in a sentence.
#

# ## (g) Confidence intervals for the coefficients
# Use the model from (e) to obtain 95% confidence intervals for the coefficients.

# ## (h) Diagnostics: idenfity outliers and high leverage points
# Is there evidence of outliers or high leverage observations in the model from (e)?



# # Lecture on MD 6.2

credit_ch6 <- Credit %>% as_tibble() %>% 
  select(ID, debt = Balance, credit_limit = Limit, 
         income = Income, credit_rating = Rating, age = Age)



StarcoderdataJupyterScriptsDedupFiltered