week02excersises.qmd

Author

Henry Frigon

#. Replace the following data path with your data path!
Sys.setenv(STATS_DATA_DIR="~/downloads")
load(paste0(Sys.getenv("STATS_DATA_DIR"),"/loan50.rda"))
with(loan50,mean(annual_income))
[1] 86170
with(loan50,median(annual_income))
[1] 74000

They differ because the mean is the average of all annual incomes but the median is the very middle value when the incomes are listed in order.

with(loan50,table(loan_purpose,grade))
                    grade
loan_purpose           A B C D E F G
                     0 0 0 0 0 0 0 0
  car                0 0 1 1 0 0 0 0
  credit_card        0 6 4 1 1 1 0 0
  debt_consolidation 0 2 9 4 7 1 0 0
  home_improvement   0 1 4 0 0 0 0 0
  house              0 0 1 0 0 0 0 0
  major_purchase     0 0 0 0 0 0 0 0
  medical            0 0 0 0 0 0 0 0
  moving             0 0 0 0 0 0 0 0
  other              0 4 0 0 0 0 0 0
  renewable_energy   0 1 0 0 0 0 0 0
  small_business     0 1 0 0 0 0 0 0
  vacation           0 0 0 0 0 0 0 0
  wedding            0 0 0 0 0 0 0 0

The most common loan purpose is debt consolidation and most frequently occurring grade is B.

summary(loan50$total_credit_limit)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  15980   70526  147364  208547  299766  793009 
colMeans(loan50[,which(sapply(loan50,is.numeric))])
             emp_length                    term           annual_income 
                     NA            4.272000e+01            8.617000e+04 
         debt_to_income      total_credit_limit   total_credit_utilized 
           7.226426e-01            2.085466e+05            6.154654e+04 
num_cc_carrying_balance             loan_amount           interest_rate 
           5.060000e+00            1.708300e+04            1.156720e+01 
 public_record_bankrupt            total_income 
           8.000000e-02            1.052206e+05 
with(loan50,table(state,homeownership))
     homeownership
state rent mortgage own
         0        0   0
   AK    0        0   0
   AL    0        0   0
   AR    0        0   0
   AZ    0        0   1
   CA    7        2   0
   CO    0        0   0
   CT    1        0   0
   DC    0        0   0
   DE    0        0   0
   FL    1        2   0
   GA    0        0   0
   HI    1        1   0
   ID    0        0   0
   IL    3        0   1
   IN    0        1   1
   KS    0        0   0
   KY    0        0   0
   LA    0        0   0
   MA    1        1   0
   MD    2        1   0
   ME    0        0   0
   MI    0        1   0
   MN    0        1   0
   MO    0        1   0
   MS    0        1   0
   MT    0        0   0
   NC    0        0   0
   ND    0        0   0
   NE    0        1   0
   NH    1        0   0
   NJ    2        1   0
   NM    0        0   0
   NV    0        2   0
   NY    1        0   0
   OH    0        1   0
   OK    0        0   0
   OR    0        0   0
   PA    0        0   0
   RI    0        1   0
   SC    0        1   0
   SD    0        0   0
   TN    0        0   0
   TX    0        5   0
   UT    0        0   0
   VA    1        0   0
   VT    0        0   0
   WA    0        0   0
   WI    0        1   0
   WV    0        1   0
   WY    0        0   0

The state with the most mortgages is Texas with 5