MAKE SURE WHEN YOU START CODING YOUR SECTION, YOU RUN FROM THE TOP ALL THE WAY THROUGH BEFORE CODING YOUR SECTION.

Enables knitting

options(repos = c(CRAN = "https://cran.rstudio.com/"))

#use this chunk to load in EVERY install.packages("), library(), and data("") for the project.
#This is so we can easily start coding on the next persons computer
#Before knitting, comment out any install.package()
#install.packages("tidyverse")
#install.packages("corrplot")
#install.packages("summarytools")
#install.packages("MASS")
#install.packages("Boruta")
#install.packages("broom")
#install.packages("leaps")
#install.packages("car")
#install.packages("lmtest")
#install.packages("sandwich")
#install.packages("skedastic")

if (!requireNamespace("conflicted", quietly = TRUE)) {
  install.packages("conflicted")
}

library(conflicted)

# Force conflicts to become errors
#conflict_prefer("filter", winner = "dplyr")
conflict_prefer("lag", winner = "dplyr")
## [conflicted] Will prefer dplyr::lag over any other package.
conflict_prefer("regsubsets", winner = "leaps")
## [conflicted] Will prefer leaps::regsubsets over any other package.
conflict_prefer("subsets", winner = "leaps")
## [conflicted] Will prefer leaps::subsets over any other package.
library(Boruta)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## âś” dplyr     1.1.4     âś” readr     2.1.5
## âś” forcats   1.0.0     âś” stringr   1.5.1
## âś” ggplot2   3.4.4     âś” tibble    3.2.1
## âś” lubridate 1.9.3     âś” tidyr     1.3.0
## âś” purrr     1.0.2
library(corrplot)
## corrplot 0.92 loaded
library(summarytools)
library(MASS)
library(broom)
library(leaps)
library(car)
## Loading required package: carData
library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(sandwich)
library(skedastic)
# Import of Dataset
credit_model <- read.csv("C:/Users/Hagop/Downloads/UCI_Credit_Card.csv/UCI_Credit_Card.csv")

# Dataset Variable Groupings
factor_variables <- sapply(credit_model, is.factor)                                          # Groups factor variables 
numeric_variables <- sapply(credit_model, is.numeric)                                        # Groups numeric variables
binary_variables <- sapply(credit_model, function(x) is.numeric(x) && all(x %in% c(0, 1)))   # Groups binary variables

numeric_data <- credit_model[, numeric_variables]                                # Subset the data to include only numeric variables

# Histogram
for (variable in names(numeric_data)) {
  hist(numeric_data[[variable]], main = paste("Histogram of", variable), xlab = "Values", ylab = "Frequency")
}

# Fitted Distributions
fit_and_plot_distribution <- function(data, variable) {
  data_to_fit <- data[[variable]]
  fit_result <- suppressWarnings(fitdistr(data_to_fit, densfun = "normal"))
  cat("Variable:", variable, "\n")
  cat("Fitted Parameters:", fit_result$estimate, "\n\n")
  hist(data_to_fit, main = paste("Histogram of", variable, "with Fitted Distribution"),
       xlab = "Values", 
       ylab = "Frequency", 
       col = "lightblue", probability = TRUE)
  curve(dnorm(x, mean = fit_result$estimate[1], sd = fit_result$estimate[2]),             #Applies fitted distribution line
      col = "darkblue", lwd = 2, add = TRUE)
}

# Loop through numeric variables and create fitted distribution histograms
for (variable in names(numeric_data)) {
  fit_and_plot_distribution(numeric_data, variable)
}
## Variable: ID 
## Fitted Parameters: 15000.5 8660.254

## Variable: LIMIT_BAL 
## Fitted Parameters: 167484.3 129745.5

## Variable: SEX 
## Fitted Parameters: 1.603733 0.489121

## Variable: EDUCATION 
## Fitted Parameters: 1.853133 0.7903355

## Variable: MARRIAGE 
## Fitted Parameters: 1.551867 0.5219609

## Variable: AGE 
## Fitted Parameters: 35.4855 9.21775

## Variable: PAY_0 
## Fitted Parameters: -0.0167 1.123783

## Variable: PAY_2 
## Fitted Parameters: -0.1337667 1.197166

## Variable: PAY_3 
## Fitted Parameters: -0.1662 1.196848

## Variable: PAY_4 
## Fitted Parameters: -0.2206667 1.169119

## Variable: PAY_5 
## Fitted Parameters: -0.2662 1.133169

## Variable: PAY_6 
## Fitted Parameters: -0.2911 1.149968

## Variable: BILL_AMT1 
## Fitted Parameters: 51223.33 73634.63

## Variable: BILL_AMT2 
## Fitted Parameters: 49179.08 71172.58

## Variable: BILL_AMT3 
## Fitted Parameters: 47013.15 69348.23

## Variable: BILL_AMT4 
## Fitted Parameters: 43262.95 64331.78

## Variable: BILL_AMT5 
## Fitted Parameters: 40311.4 60796.14

## Variable: BILL_AMT6 
## Fitted Parameters: 38871.76 59553.11

## Variable: PAY_AMT1 
## Fitted Parameters: 5663.581 16563

## Variable: PAY_AMT2 
## Fitted Parameters: 5921.163 23040.49

## Variable: PAY_AMT3 
## Fitted Parameters: 5225.681 17606.67

## Variable: PAY_AMT4 
## Fitted Parameters: 4826.077 15665.9

## Variable: PAY_AMT5 
## Fitted Parameters: 4799.388 15278.05

## Variable: PAY_AMT6 
## Fitted Parameters: 5215.503 17777.17

## Variable: default.payment.next.month 
## Fitted Parameters: 0.2212 0.4150549

##Correlation Plot
variables <- credit_model[, c("default.payment.next.month","SEX", "AGE", "EDUCATION", "MARRIAGE", "LIMIT_BAL", "PAY_0", "PAY_2", "PAY_3", "PAY_4", "PAY_5", "PAY_6", "BILL_AMT1", "BILL_AMT2", "BILL_AMT3", "BILL_AMT4", "BILL_AMT5", "BILL_AMT6", "PAY_AMT1", "PAY_AMT2", "PAY_AMT3", "PAY_AMT4", "PAY_AMT5", "PAY_AMT6")]
corvariables <- cor(variables)
corrplotvariables <- corrplot(corvariables,
      tl.col = "black",
      tl.srt = 45)

# Box Plots
options(scipen = 999)                                                            # Disables scientific notation on axes

boxplot(credit_model$LIMIT_BAL,
        main = "Given Credit Limit")

boxplot(credit_model$EDUCATION,
        main = "Education (1 = graduate school; 2 = university; 3 = high school; 4 = others)")

boxplot(credit_model$MARRIAGE,
        main = "Marital status (0 = unknown, 1 = married; 2 = single; 3 = others)")

boxplot(credit_model$AGE,
        main = "Age (Years)")

boxplot(credit_model$PAY_0, 
        main = "Repayment Status in September 2005 (Months Delayed)")

boxplot(credit_model$PAY_6, 
        main = "Repayment Status in April 2005 (Months Delayed)" )

boxplot(credit_model$BILL_AMT1, 
        main = "Amount of Bill Statement in September 2005")

boxplot(credit_model$BILL_AMT6, 
        main = "Amount of Bill Statement in April 2005")

boxplot(credit_model$PAY_AMT1, 
        main = "Amount Paid in September 2005")

boxplot(credit_model$PAY_AMT6, 
        main = "Amount Paid in April 2005")

boxplot(credit_model$default.payment.next.month,
        main = "Default on Payment Next Month")

# Bar Plot
barplot(table(variables$default.payment.next.month), 
        main = "Bar Plot of Default Payment",
        xlab = "Default Payment",
        col = "skyblue")

# Scatter Plots
plot(credit_model$LIMIT_BAL, jitter(credit_model$default.payment.next.month, factor = 1),
     main = "Scatter Plot",
     xlab = "Credit Limit", 
     ylab = "Mean Default Rate",
     pch = 16, col = "blue")

plot(jitter(credit_model$EDUCATION, factor = 2), jitter(credit_model$default.payment.next.month, factor = 1), 
     main = "Scatter Plot", 
     xlab = "Education (1 = graduate school; 2 = university; 3 = high school; 4 = others)", 
     ylab = "Default on Payment Next Month (0 = No, 1 = Yes)", 
     pch = 16, col = "red")

plot(jitter(credit_model$MARRIAGE, factor = 2), jitter(credit_model$default.payment.next.month, factor = 1), 
     main = "Scatter Plot", 
     xlab = "Marital status (0 = unknown, 1 = married; 2 = single; 3 = others)", 
     ylab = "Default on Payment Next Month (0 = No, 1 = Yes)", 
     pch = 16, col = "green")

plot(jitter(credit_model$AGE, factor = 2), jitter(credit_model$default.payment.next.month, factor = 1), 
     main = "Scatter Plot", 
     xlab = "AGE (Years)", 
     ylab = "Default on Payment Next Month (0 = No, 1 = Yes)", 
     pch = 16, col = "cyan")

plot(credit_model$PAY_0, jitter(credit_model$default.payment.next.month, factor = 1), 
     main = "Scatter Plot", 
     xlab = "Repayment Status in September 2005 (Months Delayed)", 
     ylab = "Default on Payment Next Month (0 = No, 1 = Yes)", 
     pch = 16, col = "purple")

plot(credit_model$PAY_6, jitter(credit_model$default.payment.next.month, factor = 1), 
     main = "Scatter Plot", 
     xlab = "Repayment Status in April 2005 (Months Delayed)", 
     ylab = "Default on Payment Next Month (0 = No, 1 = Yes)", 
     pch = 16, col = "purple")

plot(credit_model$BILL_AMT1, jitter(credit_model$default.payment.next.month, factor = 1), 
     main = "Scatter Plot", 
     xlab = "Amount of Bill Statement in September 2005", 
     ylab = "Default on Payment Next Month (0 = No, 1 = Yes)", 
     pch = 16, col = "pink")

plot(credit_model$BILL_AMT6, jitter(credit_model$default.payment.next.month, factor = 1), 
     main = "Scatter Plot", 
     xlab = "Amount of Bill Statement in September 2005", 
     ylab = "Default on Payment Next Month (0 = No, 1 = Yes)", 
     pch = 16, col = "pink")

plot(credit_model$PAY_AMT1, jitter(credit_model$default.payment.next.month, factor = 1), 
     main = "Scatter Plot", 
     xlab = "Amount of Bill Statement in September 2005", 
     ylab = "Default on Payment Next Month (0 = No, 1 = Yes)", 
     pch = 16, col = "yellow")

plot(jitter(credit_model$PAY_AMT6, factor = 2), jitter(credit_model$default.payment.next.month, factor = 1), 
     main = "Scatter Plot", 
     xlab = "Amount of Bill Statement in April 2005", 
     ylab = "Default on Payment Next Month (0 = No, 1 = Yes)", 
     pch = 16, col = "yellow")

# Five-Number Summary
summary(credit_model)
##        ID          LIMIT_BAL            SEX          EDUCATION    
##  Min.   :    1   Min.   :  10000   Min.   :1.000   Min.   :0.000  
##  1st Qu.: 7501   1st Qu.:  50000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :15000   Median : 140000   Median :2.000   Median :2.000  
##  Mean   :15000   Mean   : 167484   Mean   :1.604   Mean   :1.853  
##  3rd Qu.:22500   3rd Qu.: 240000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :30000   Max.   :1000000   Max.   :2.000   Max.   :6.000  
##     MARRIAGE          AGE            PAY_0             PAY_2        
##  Min.   :0.000   Min.   :21.00   Min.   :-2.0000   Min.   :-2.0000  
##  1st Qu.:1.000   1st Qu.:28.00   1st Qu.:-1.0000   1st Qu.:-1.0000  
##  Median :2.000   Median :34.00   Median : 0.0000   Median : 0.0000  
##  Mean   :1.552   Mean   :35.49   Mean   :-0.0167   Mean   :-0.1338  
##  3rd Qu.:2.000   3rd Qu.:41.00   3rd Qu.: 0.0000   3rd Qu.: 0.0000  
##  Max.   :3.000   Max.   :79.00   Max.   : 8.0000   Max.   : 8.0000  
##      PAY_3             PAY_4             PAY_5             PAY_6        
##  Min.   :-2.0000   Min.   :-2.0000   Min.   :-2.0000   Min.   :-2.0000  
##  1st Qu.:-1.0000   1st Qu.:-1.0000   1st Qu.:-1.0000   1st Qu.:-1.0000  
##  Median : 0.0000   Median : 0.0000   Median : 0.0000   Median : 0.0000  
##  Mean   :-0.1662   Mean   :-0.2207   Mean   :-0.2662   Mean   :-0.2911  
##  3rd Qu.: 0.0000   3rd Qu.: 0.0000   3rd Qu.: 0.0000   3rd Qu.: 0.0000  
##  Max.   : 8.0000   Max.   : 8.0000   Max.   : 8.0000   Max.   : 8.0000  
##    BILL_AMT1         BILL_AMT2        BILL_AMT3         BILL_AMT4      
##  Min.   :-165580   Min.   :-69777   Min.   :-157264   Min.   :-170000  
##  1st Qu.:   3559   1st Qu.:  2985   1st Qu.:   2666   1st Qu.:   2327  
##  Median :  22382   Median : 21200   Median :  20089   Median :  19052  
##  Mean   :  51223   Mean   : 49179   Mean   :  47013   Mean   :  43263  
##  3rd Qu.:  67091   3rd Qu.: 64006   3rd Qu.:  60165   3rd Qu.:  54506  
##  Max.   : 964511   Max.   :983931   Max.   :1664089   Max.   : 891586  
##    BILL_AMT5        BILL_AMT6          PAY_AMT1         PAY_AMT2      
##  Min.   :-81334   Min.   :-339603   Min.   :     0   Min.   :      0  
##  1st Qu.:  1763   1st Qu.:   1256   1st Qu.:  1000   1st Qu.:    833  
##  Median : 18105   Median :  17071   Median :  2100   Median :   2009  
##  Mean   : 40311   Mean   :  38872   Mean   :  5664   Mean   :   5921  
##  3rd Qu.: 50191   3rd Qu.:  49198   3rd Qu.:  5006   3rd Qu.:   5000  
##  Max.   :927171   Max.   : 961664   Max.   :873552   Max.   :1684259  
##     PAY_AMT3         PAY_AMT4         PAY_AMT5           PAY_AMT6       
##  Min.   :     0   Min.   :     0   Min.   :     0.0   Min.   :     0.0  
##  1st Qu.:   390   1st Qu.:   296   1st Qu.:   252.5   1st Qu.:   117.8  
##  Median :  1800   Median :  1500   Median :  1500.0   Median :  1500.0  
##  Mean   :  5226   Mean   :  4826   Mean   :  4799.4   Mean   :  5215.5  
##  3rd Qu.:  4505   3rd Qu.:  4013   3rd Qu.:  4031.5   3rd Qu.:  4000.0  
##  Max.   :896040   Max.   :621000   Max.   :426529.0   Max.   :528666.0  
##  default.payment.next.month
##  Min.   :0.0000            
##  1st Qu.:0.0000            
##  Median :0.0000            
##  Mean   :0.2212            
##  3rd Qu.:0.0000            
##  Max.   :1.0000
# Logistic model regression suited for binary response variable
logistic_reg <- glm(default.payment.next.month ~ LIMIT_BAL + SEX + EDUCATION + MARRIAGE + AGE + PAY_0 + PAY_2 + PAY_3 + PAY_4 + PAY_5 + PAY_6 + BILL_AMT1 +
              BILL_AMT2 + BILL_AMT3 +BILL_AMT4 + BILL_AMT5 + BILL_AMT6 + PAY_AMT1 + PAY_AMT2 + PAY_AMT3 + PAY_AMT4 + PAY_AMT5 + PAY_AMT6, data = credit_model, family = "binomial")  
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
summary(logistic_reg)
## 
## Call:
## glm(formula = default.payment.next.month ~ LIMIT_BAL + SEX + 
##     EDUCATION + MARRIAGE + AGE + PAY_0 + PAY_2 + PAY_3 + PAY_4 + 
##     PAY_5 + PAY_6 + BILL_AMT1 + BILL_AMT2 + BILL_AMT3 + BILL_AMT4 + 
##     BILL_AMT5 + BILL_AMT6 + PAY_AMT1 + PAY_AMT2 + PAY_AMT3 + 
##     PAY_AMT4 + PAY_AMT5 + PAY_AMT6, family = "binomial", data = credit_model)
## 
## Coefficients:
##                  Estimate    Std. Error z value             Pr(>|z|)    
## (Intercept) -0.6862839006  0.1186563456  -5.784        0.00000000730 ***
## LIMIT_BAL   -0.0000007623  0.0000001569  -4.859        0.00000118166 ***
## SEX         -0.1086529377  0.0306855813  -3.541             0.000399 ***
## EDUCATION   -0.1015831958  0.0209692353  -4.844        0.00000127000 ***
## MARRIAGE    -0.1543552466  0.0317037048  -4.869        0.00000112345 ***
## AGE          0.0074196858  0.0017791662   4.170        0.00003041772 ***
## PAY_0        0.5774068985  0.0176942620  32.632 < 0.0000000000000002 ***
## PAY_2        0.0828223911  0.0201842570   4.103        0.00004072698 ***
## PAY_3        0.0721409816  0.0226038562   3.192             0.001415 ** 
## PAY_4        0.0238861376  0.0249979099   0.956             0.339312    
## PAY_5        0.0340128719  0.0268766111   1.266             0.205685    
## PAY_6        0.0080380098  0.0221304735   0.363             0.716448    
## BILL_AMT1   -0.0000054924  0.0000011359  -4.835        0.00000133024 ***
## BILL_AMT2    0.0000023563  0.0000015044   1.566             0.117280    
## BILL_AMT3    0.0000013652  0.0000013228   1.032             0.302073    
## BILL_AMT4   -0.0000001821  0.0000013490  -0.135             0.892609    
## BILL_AMT5    0.0000006155  0.0000015185   0.405             0.685246    
## BILL_AMT6    0.0000003938  0.0000011947   0.330             0.741692    
## PAY_AMT1    -0.0000136315  0.0000023053  -5.913        0.00000000336 ***
## PAY_AMT2    -0.0000096157  0.0000020948  -4.590        0.00000442499 ***
## PAY_AMT3    -0.0000027417  0.0000017225  -1.592             0.111456    
## PAY_AMT4    -0.0000040235  0.0000017849  -2.254             0.024185 *  
## PAY_AMT5    -0.0000033111  0.0000017768  -1.864             0.062387 .  
## PAY_AMT6    -0.0000020641  0.0000012959  -1.593             0.111212    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 31705  on 29999  degrees of freedom
## Residual deviance: 27877  on 29976  degrees of freedom
## AIC: 27925
## 
## Number of Fisher Scoring iterations: 6
# Re-estimate of model
logistic_reg_new <- glm(default.payment.next.month ~ LIMIT_BAL + SEX + EDUCATION + MARRIAGE + AGE + PAY_0 + BILL_AMT1 + PAY_AMT1 + PAY_AMT2, data = credit_model, family = "binomial")  
summary(logistic_reg_new)
## 
## Call:
## glm(formula = default.payment.next.month ~ LIMIT_BAL + SEX + 
##     EDUCATION + MARRIAGE + AGE + PAY_0 + BILL_AMT1 + PAY_AMT1 + 
##     PAY_AMT2, family = "binomial", data = credit_model)
## 
## Coefficients:
##                  Estimate    Std. Error z value             Pr(>|z|)    
## (Intercept) -0.6530175560  0.1177272146  -5.547         0.0000000291 ***
## LIMIT_BAL   -0.0000014522  0.0000001475  -9.844 < 0.0000000000000002 ***
## SEX         -0.1203864885  0.0304836102  -3.949         0.0000784062 ***
## EDUCATION   -0.0961974996  0.0207144482  -4.644         0.0000034176 ***
## MARRIAGE    -0.1604838715  0.0315155062  -5.092         0.0000003539 ***
## AGE          0.0070192086  0.0017678924   3.970         0.0000717574 ***
## PAY_0        0.6941222556  0.0148996468  46.586 < 0.0000000000000002 ***
## BILL_AMT1   -0.0000010616  0.0000002500  -4.247         0.0000216927 ***
## PAY_AMT1    -0.0000112506  0.0000020087  -5.601         0.0000000213 ***
## PAY_AMT2    -0.0000095966  0.0000018520  -5.182         0.0000002197 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 31705  on 29999  degrees of freedom
## Residual deviance: 28090  on 29990  degrees of freedom
## AIC: 28110
## 
## Number of Fisher Scoring iterations: 6
# Mallow's CP
# ***Linear regression is not best suited for binary response variables, but for the purposes of the project will demonstrate mock calculation using LIMIT_BAL as response variable. Results will be omitted.
ss <- regsubsets(LIMIT_BAL ~ default.payment.next.month + SEX + EDUCATION + MARRIAGE + AGE + PAY_0 + BILL_AMT1 + PAY_AMT1 + PAY_AMT2, method = "exhaustive", nbest = 3, data = credit_model)
mallows_cp <- summary(ss)$cp
plot(mallows_cp, type = "o", 
     main = "Mallows CP", 
     xlab = "Subset Size", 
     ylab = "Mallows CP", 
     col = "steelblue4")

# The Boruta Algorithm
Bor.res <- Boruta(default.payment.next.month ~ LIMIT_BAL + SEX + EDUCATION + MARRIAGE + AGE + PAY_0 + BILL_AMT1 + PAY_AMT1 + PAY_AMT2, data = credit_model, doTrace = 2)
##  1. run of importance source...
##  2. run of importance source...
##  3. run of importance source...
##  4. run of importance source...
##  5. run of importance source...
##  6. run of importance source...
##  7. run of importance source...
##  8. run of importance source...
##  9. run of importance source...
##  10. run of importance source...
## After 10 iterations, +26 secs:
##  confirmed 8 attributes: AGE, BILL_AMT1, EDUCATION, LIMIT_BAL, MARRIAGE and 3 more;
##  still have 1 attribute left.
##  11. run of importance source...
##  12. run of importance source...
##  13. run of importance source...
##  14. run of importance source...
##  15. run of importance source...
##  16. run of importance source...
##  17. run of importance source...
##  18. run of importance source...
## After 18 iterations, +46 secs:
##  confirmed 1 attribute: SEX;
##  no more attributes left.
#plot(Bor.res,sort=TRUE)
plot(Bor.res, xlab = "", xaxt = "n", main="Boruta Algorithm Feature Importance")
lz<-lapply(1:ncol(Bor.res$ImpHistory),function(i)
Bor.res$ImpHistory[is.finite(Bor.res$ImpHistory[,i]),i])
names(lz) <- colnames(Bor.res$ImpHistory)
Labels <- sort(sapply(lz,median))
axis(side = 1,las=2,labels = names(Labels),
at = 1:ncol(Bor.res$ImpHistory), cex.axis = 0.7)

attStats(Bor.res)                                                               # Look at the statistical attributes in terms of 'variable importance'
# Test for multicollinearity (VIF)
vif(logistic_reg_new)
## LIMIT_BAL       SEX EDUCATION  MARRIAGE       AGE     PAY_0 BILL_AMT1  PAY_AMT1 
##  1.326402  1.021175  1.134282  1.230795  1.270678  1.087315  1.232247  1.115933 
##  PAY_AMT2 
##  1.101594
# Plot residuals vs. predicted values
predicted_probabilities <- predict(logistic_reg_new, type = "response")        
model_residuals <- residuals(logistic_reg_new, type = "response")

plot(predicted_probabilities, model_residuals, 
     main = "Residuals vs. Fitted Values of Model",
     xlab = "Fitted Values of Model", 
     ylab = "Residuals")
     abline(h = 0, col = "red")

model_residuals <- residuals(logistic_reg_new, type = "response")

augmented_model <- glm(default.payment.next.month ~ LIMIT_BAL + SEX + EDUCATION + MARRIAGE + AGE + PAY_0 + BILL_AMT1 + PAY_AMT1 + PAY_AMT2 + I(LIMIT_BAL^2) + I(SEX^2) + I(EDUCATION^2) + I(MARRIAGE^2) + I(AGE^2) + I(PAY_0^2) + I(BILL_AMT1^2) + I(PAY_AMT1^2) + I(PAY_AMT2^2), data = credit_model)
augmented_residuals <- residuals(augmented_model, type = "response")

null_model <- glm(default.payment.next.month ~ 1, data = credit_model, family = "binomial")

lr_test <- lrtest(logistic_reg_new, null_model)
print(lr_test)
## Likelihood ratio test
## 
## Model 1: default.payment.next.month ~ LIMIT_BAL + SEX + EDUCATION + MARRIAGE + 
##     AGE + PAY_0 + BILL_AMT1 + PAY_AMT1 + PAY_AMT2
## Model 2: default.payment.next.month ~ 1
##   #Df LogLik Df Chisq            Pr(>Chisq)    
## 1  10 -14045                                   
## 2   1 -15853 -9  3615 < 0.00000000000000022 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# White Test