Read and follow the data mining steps in the textbook for the Charles Book Club case (pp.499-505 in the text).

A. Partition your data into a training set (60%) and a validation set (40%). For your data partition, do not use the seed value mentioned in the book. Instead, use your individual seed value (listed on the PDF that is posted in the folder for this assignment). Show the code you used to make the partition.

Import data

c1<-read.csv("charlesbookclub.csv")
head(c1,5)
##   Seq. ID. Gender   M  R F FirstPurch ChildBks YouthBks CookBks DoItYBks
## 1    1  25      1 297 14 2         22        0        1       1        0
## 2    2  29      0 128  8 2         10        0        0       0        0
## 3    3  46      1 138 22 7         56        2        1       2        0
## 4    4  47      1 228  2 1          2        0        0       0        0
## 5    5  51      1 257 10 1         10        0        0       0        0
##   RefBks ArtBks GeogBks ItalCook ItalAtlas ItalArt Florence
## 1      0      0       0        0         0       0        0
## 2      0      0       0        0         0       0        0
## 3      1      0       1        1         0       0        0
## 4      0      0       0        0         0       0        0
## 5      0      0       0        0         0       0        0
##   Related.Purchase Mcode Rcode Fcode Yes_Florence No_Florence
## 1                0     5     4     2            0           1
## 2                0     4     3     2            0           1
## 3                2     4     4     3            0           1
## 4                0     5     1     1            0           1
## 5                0     5     3     1            0           1
names(c1)
##  [1] "Seq."             "ID."              "Gender"          
##  [4] "M"                "R"                "F"               
##  [7] "FirstPurch"       "ChildBks"         "YouthBks"        
## [10] "CookBks"          "DoItYBks"         "RefBks"          
## [13] "ArtBks"           "GeogBks"          "ItalCook"        
## [16] "ItalAtlas"        "ItalArt"          "Florence"        
## [19] "Related.Purchase" "Mcode"            "Rcode"           
## [22] "Fcode"            "Yes_Florence"     "No_Florence"

Create training and validation sets

set.seed(60)
train.index<-sample(rownames(c1), dim(c1)[1]*0.6)
train.df<-c1[train.index, ]
valid.index <- setdiff(rownames(c1), train.index)
valid.df<-c1[valid.index, ]

1.Show the RFM combinations for the training data and the validation data. the code you used, along with the results, to determine:

a)The response rate for each category from your training data;
mean(train.df$Florence) #The average response rate of column "Florence"
## [1] 0.08125

Melting things

library(reshape)
m<-melt(train.df, id = c("Mcode", "Fcode", "Rcode"),measure = "Florence", na.rm = F)
cst<-cast(m, variable ~ Mcode + Fcode + Rcode, mean)

Reshaping the validation data

m2<-melt(valid.df, id = c("Mcode", "Fcode", "Rcode"), measure = "Florence", na.rm = F)
cst2<-cast(m2, variable ~ Mcode + Fcode + Rcode, mean)
b) The response rate in the validation data for combinations that exceeded the mean response rate for the training data;
above.average.index <- which(t(cst2) > mean(train.df$Florence)) 
above.average <- rownames(t(cst2))[above.average.index]
above.average #this shows the identities of the rows in the validation set that exceeded the mean from the training set
##  [1] "1_1_3" "2_1_2" "2_1_4" "2_2_1" "2_2_2" "2_2_3" "2_2_4" "3_1_2"
##  [9] "3_1_4" "3_2_2" "3_2_3" "3_3_2" "3_3_4" "4_1_1" "4_1_2" "4_2_3"
## [17] "4_3_2" "4_3_3" "4_3_4" "5_1_1" "5_1_2" "5_1_4" "5_3_1" "5_3_2"
## [25] "5_3_3"
cst.length <- cast(m2, variable ~ Mcode + Fcode + Rcode, length)
ind <- colnames(cst2) %in% above.average  #the %in% uses the special binary operator
rate<-sum(cst2[ind]*cst.length[ind])/sum(cst.length[ind])
rate  #this gives the response rate among groups in the validation set that exceeded the training set mean
## [1] 0.1328125
c) The combinations that have response rates that exceed twice the overall response rate (for training data only)

Groups those exceed 2 times the mean in Training Data

above.average.index <- which(t(cst) > 2*mean(train.df$Florence)) 
above.average <- rownames(t(cst))[above.average.index]
ind<-colnames(cst) %in% above.average
rate.s1<-sum(cst[ind]*cst.length[ind])/sum(cst.length[ind])
n.s1<-sum(cst.length[ind])
above.average
## [1] "1_1_2" "1_1_3" "2_1_1" "2_2_1" "2_3_1" "3_3_1" "3_3_2" "4_2_2" "5_3_2"
rate.s1
## [1] 0.1867754
d) The combinations that exceed the overall response rate but do not exceed twice the overall response rate (for training data only)

Groups those greater than mean, but less than 2 times mean

above.average.index <- intersect(which(t(cst) < 2*mean(train.df$Florence)), which(t(cst) > mean(train.df$Florence)))
above.average <- rownames(t(cst))[above.average.index]
ind<-colnames(cst) %in% above.average
rate.s2<-sum(cst[ind]*cst.length[ind])/sum(cst.length[ind]) 
n.s2<-sum(cst.length[ind])
above.average
##  [1] "3_1_4" "4_1_1" "4_1_4" "4_3_2" "5_1_1" "5_1_2" "5_2_1" "5_2_2"
##  [9] "5_3_1" "5_3_3"
rate.s2
## [1] 0.1234764
e) The remaining RFM combinations (less than the mean) for the training data only

The below average segment

below.average.index<-which(t(cst) < mean(train.df$Florence)) 
below.average<-rownames(t(cst))[below.average.index]
ind<-colnames(cst) %in% below.average
rate.s3<-sum(cst[ind]*cst.length[ind])/sum(cst.length[ind]) 
n.s3<-sum(cst.length[ind])
below.average
##  [1] "1_1_1" "1_1_4" "2_1_2" "2_1_3" "2_1_4" "2_2_2" "2_2_3" "2_2_4"
##  [9] "2_3_4" "3_1_1" "3_1_2" "3_1_3" "3_2_1" "3_2_2" "3_2_3" "3_2_4"
## [17] "3_3_3" "3_3_4" "4_1_2" "4_1_3" "4_2_1" "4_2_3" "4_2_4" "4_3_1"
## [25] "4_3_3" "4_3_4" "5_1_3" "5_1_4" "5_2_3" "5_2_4" "5_3_4"
rate.s3
## [1] 0.05689315
f) We will also do the lift curve together in class for the three points for the various segments. Show the code used to create it, along with the result.

Plotting the Rates Aganist the Lengths (group sizes)

plot(c(rate.s1, rate.s2, rate.s3) ~ c(n.s1, n.s2, n.s3), type = "b")

C. For the k-nn portion of this assignment:

1. Convert Florence into a factor. Show how you did this.
c1$Florence<-as.factor(c1$Florence)
str(c1)
## 'data.frame':    4000 obs. of  24 variables:
##  $ Seq.            : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ ID.             : int  25 29 46 47 51 60 61 79 81 90 ...
##  $ Gender          : int  1 0 1 1 1 1 1 1 1 1 ...
##  $ M               : int  297 128 138 228 257 145 190 187 252 240 ...
##  $ R               : int  14 8 22 2 10 6 16 14 10 6 ...
##  $ F               : int  2 2 7 1 1 2 1 1 1 3 ...
##  $ FirstPurch      : int  22 10 56 2 10 12 16 14 10 20 ...
##  $ ChildBks        : int  0 0 2 0 0 0 0 1 0 0 ...
##  $ YouthBks        : int  1 0 1 0 0 0 0 0 0 0 ...
##  $ CookBks         : int  1 0 2 0 0 0 0 0 0 1 ...
##  $ DoItYBks        : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ RefBks          : int  0 0 1 0 0 0 0 0 0 0 ...
##  $ ArtBks          : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ GeogBks         : int  0 0 1 0 0 0 1 0 0 0 ...
##  $ ItalCook        : int  0 0 1 0 0 0 0 0 0 0 ...
##  $ ItalAtlas       : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ ItalArt         : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ Florence        : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
##  $ Related.Purchase: int  0 0 2 0 0 0 1 0 0 0 ...
##  $ Mcode           : int  5 4 4 5 5 4 4 4 5 5 ...
##  $ Rcode           : int  4 3 4 1 3 2 4 4 3 2 ...
##  $ Fcode           : int  2 2 3 1 1 2 1 1 1 3 ...
##  $ Yes_Florence    : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ No_Florence     : int  1 1 1 1 1 1 1 1 1 1 ...
2. Run the knn() function from the fnn package to predict the outcome for Florence for a consumer with an Fcode of 3, an MCode of 3, and an Rcode of 3. Use preProcess() for normalization. Use k =7, and show the result. What did it predict for this consumer? (Use Table 7.2 from the book and/or your own process from the k-nn candy challenge, as a guide here). Show your steps and show the result.
train.norm.df<-train.df #normalizing training and validation data
valid.norm.df<-valid.df
c1.norm.df<-c1

library(caret)
## Warning: package 'caret' was built under R version 3.4.4
## Loading required package: lattice
## Loading required package: ggplot2
names(c1)
##  [1] "Seq."             "ID."              "Gender"          
##  [4] "M"                "R"                "F"               
##  [7] "FirstPurch"       "ChildBks"         "YouthBks"        
## [10] "CookBks"          "DoItYBks"         "RefBks"          
## [13] "ArtBks"           "GeogBks"          "ItalCook"        
## [16] "ItalAtlas"        "ItalArt"          "Florence"        
## [19] "Related.Purchase" "Mcode"            "Rcode"           
## [22] "Fcode"            "Yes_Florence"     "No_Florence"
new.df<-data.frame("Mcode"=3,"Rcode"=3,"Fcode"=3)
new.df
##   Mcode Rcode Fcode
## 1     3     3     3
norm.values<-preProcess(train.df[,20:22], method=c("center","scale"))
train.norm.df[, 20:22] <- predict(norm.values, train.df[, 20:22])
valid.norm.df[, 20:22] <- predict(norm.values, valid.df[, 20:22])
new.norm.df<-predict(norm.values,new.df)

library(FNN)
names(train.norm.df)
##  [1] "Seq."             "ID."              "Gender"          
##  [4] "M"                "R"                "F"               
##  [7] "FirstPurch"       "ChildBks"         "YouthBks"        
## [10] "CookBks"          "DoItYBks"         "RefBks"          
## [13] "ArtBks"           "GeogBks"          "ItalCook"        
## [16] "ItalAtlas"        "ItalArt"          "Florence"        
## [19] "Related.Purchase" "Mcode"            "Rcode"           
## [22] "Fcode"            "Yes_Florence"     "No_Florence"
nn<-knn(train=train.norm.df[ ,20:22],test=new.norm.df,cl=train.norm.df[ ,18], k=7)
row.names(train.df)[attr(nn, "nn.index")]
## [1] "3584" "3205" "3919" "3423" "2743" "3632" "2660"
nn
## [1] 0
## attr(,"nn.index")
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## [1,] 1490 1433  278 1304 1209  209 1999
## attr(,"nn.dist")
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## [1,]    0    0    0    0    0    0    0
## Levels: 0

If we use k=7,the 7 nearest neighbors are “3584” “3205” “3919” “3423” “2743” “3632” and “2660”.The outcome for a consumer with an Fcode of 3, an MCode of 3, and an Rcode of 3 would be classified as Florence of 0.

E.For the logistic regression portion:

1.Run the glm() function on your training data with the predictors in columns 3 through 19, and with Florence as the outcome variable (see p.245 for a coded example of such a function). Show the code you used, and show the result by using summary().
names(train.df)
##  [1] "Seq."             "ID."              "Gender"          
##  [4] "M"                "R"                "F"               
##  [7] "FirstPurch"       "ChildBks"         "YouthBks"        
## [10] "CookBks"          "DoItYBks"         "RefBks"          
## [13] "ArtBks"           "GeogBks"          "ItalCook"        
## [16] "ItalAtlas"        "ItalArt"          "Florence"        
## [19] "Related.Purchase" "Mcode"            "Rcode"           
## [22] "Fcode"            "Yes_Florence"     "No_Florence"
logit.reg<-glm(Florence ~ Gender+M+R+F+FirstPurch+ChildBks+YouthBks+CookBks+DoItYBks+RefBks+
ArtBks+GeogBks+ItalCook+ItalAtlas+ItalArt+Related.Purchase,data = train.df,family = "binomial")
options(scipen=999)
summary(logit.reg)
## 
## Call:
## glm(formula = Florence ~ Gender + M + R + F + FirstPurch + ChildBks + 
##     YouthBks + CookBks + DoItYBks + RefBks + ArtBks + GeogBks + 
##     ItalCook + ItalAtlas + ItalArt + Related.Purchase, family = "binomial", 
##     data = train.df)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.0500  -0.4295  -0.3553  -0.3011   2.6959  
## 
## Coefficients: (1 not defined because of singularities)
##                    Estimate Std. Error z value             Pr(>|z|)    
## (Intercept)      -2.3449911  0.2592120  -9.047 < 0.0000000000000002 ***
## Gender           -0.4526930  0.1591063  -2.845             0.004438 ** 
## M                -0.0007348  0.0009100  -0.807             0.419396    
## R                -0.0143865  0.0152358  -0.944             0.345038    
## F                 0.2273245  0.0669460   3.396             0.000685 ***
## FirstPurch        0.0002617  0.0111320   0.024             0.981244    
## ChildBks         -0.2646801  0.1108514  -2.388             0.016954 *  
## YouthBks         -0.2183066  0.1489582  -1.466             0.142769    
## CookBks          -0.3347406  0.1059120  -3.161             0.001575 ** 
## DoItYBks         -0.1219760  0.1289821  -0.946             0.344311    
## RefBks           -0.2284536  0.1543036  -1.481             0.138728    
## ArtBks            0.4572690  0.1031103   4.435           0.00000922 ***
## GeogBks           0.0852234  0.1021087   0.835             0.403924    
## ItalCook         -0.2493745  0.2147328  -1.161             0.245510    
## ItalAtlas         0.0638245  0.3273920   0.195             0.845433    
## ItalArt           0.3572926  0.2972874   1.202             0.229425    
## Related.Purchase         NA         NA      NA                   NA    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1352.7  on 2399  degrees of freedom
## Residual deviance: 1282.2  on 2384  degrees of freedom
## AIC: 1314.2
## 
## Number of Fisher Scoring iterations: 5
2. Call the predict() function on your validation data. The code sample below might be helpful but bear in mind that if you are using different variable names, it will not work:
newdata<-data.frame(valid.df[3:19])
pred<-predict(logit.reg,newdata,type="response")
3. Now sort out the records. You can do this with something like: sort(pred, decreasing=FALSE). Show your results.
sort(pred,decreasing = FALSE)
##       1218       2702       2045       2707       1752       2907 
## 0.01380184 0.01544257 0.01756401 0.01878696 0.02098483 0.02137832 
##        869       1976         41       3267         31        219 
## 0.02146570 0.02159823 0.02244677 0.02342351 0.02344536 0.02448722 
##        145       1271       3294        576       3355        510 
## 0.02505725 0.02538548 0.02582959 0.02584081 0.02661626 0.02663731 
##       2728       2481       3100       3680        749       2035 
## 0.02702463 0.02726816 0.02786113 0.02787781 0.02790412 0.02805509 
##        404        167       3074        325        581       3768 
## 0.02821764 0.02822079 0.02830222 0.02841644 0.02887376 0.02907828 
##       1097       1702       3109       3268       2249       2914 
## 0.02911116 0.02931054 0.02936869 0.02945189 0.02966915 0.02980887 
##       2240       1302        660       3476       2821        972 
## 0.02986212 0.03000343 0.03007047 0.03017024 0.03028913 0.03034136 
##       2401       3826        345       2837       2522       3009 
## 0.03034932 0.03059120 0.03060100 0.03065238 0.03085475 0.03090204 
##       1814        291       1458        303       3208       1634 
## 0.03093113 0.03098108 0.03114955 0.03124390 0.03139330 0.03152035 
##        746       2835        462       3370       3892       3722 
## 0.03163483 0.03165508 0.03169146 0.03177186 0.03192944 0.03203769 
##       2987       2658       3215       3926       1062       1785 
## 0.03252599 0.03258831 0.03311994 0.03315777 0.03323398 0.03350933 
##       3908       2241       2562       3993        704       3406 
## 0.03359559 0.03366820 0.03371264 0.03374308 0.03382057 0.03392438 
##       3352       1483       1433       3569       1819       1732 
## 0.03399485 0.03409676 0.03413058 0.03424548 0.03433667 0.03445462 
##       1094       3860       3792        678        153       3455 
## 0.03453172 0.03469639 0.03479321 0.03487941 0.03497054 0.03503677 
##       2944        490       3282       3228       3347       3929 
## 0.03504194 0.03519908 0.03525598 0.03534694 0.03549311 0.03549560 
##       2553       2643         91       1012        364       3460 
## 0.03560870 0.03576590 0.03578124 0.03579377 0.03587435 0.03589040 
##       3741       1392       2398       2549        693       2834 
## 0.03590536 0.03590699 0.03605212 0.03608964 0.03616319 0.03617714 
##       3332        217       3953         65       3020        573 
## 0.03628120 0.03636551 0.03636752 0.03642019 0.03650015 0.03652377 
##        476       2095       2184       2335        674         82 
## 0.03656041 0.03673207 0.03695008 0.03712924 0.03731517 0.03742793 
##       1298       3750       2378        992       1331       1281 
## 0.03744847 0.03756754 0.03760926 0.03774961 0.03778247 0.03780919 
##       2928       3944       1769       3273       1669       2637 
## 0.03782982 0.03783864 0.03786264 0.03788766 0.03790172 0.03790508 
##       1818        383       2173       2916       1941       1157 
## 0.03793415 0.03798756 0.03819156 0.03822424 0.03830472 0.03847624 
##       3840       1231       2366       3575        940        240 
## 0.03851317 0.03851475 0.03854579 0.03854779 0.03857450 0.03859213 
##       3793       2512       2808       2423       2074       2150 
## 0.03867448 0.03867695 0.03868390 0.03876999 0.03877434 0.03879163 
##       2101       3459       2607        251        845       2698 
## 0.03882476 0.03884370 0.03887631 0.03889270 0.03896203 0.03896455 
##       2132       3905       3738        758       1550        209 
## 0.03896621 0.03899122 0.03903351 0.03909814 0.03911845 0.03912874 
##       2544        805       3719       2435       2319        498 
## 0.03917121 0.03918604 0.03924232 0.03926566 0.03932531 0.03934920 
##        867       1697       3817        155       2044        239 
## 0.03935833 0.03940847 0.03941426 0.03947534 0.03948949 0.03950480 
##        249        254        520        780       1397       1961 
## 0.03957613 0.03962207 0.03966026 0.03968287 0.03975738 0.03993688 
##       2851       3663       3712       2697       1867       1946 
## 0.04000975 0.04003550 0.04004649 0.04005369 0.04006338 0.04013151 
##       3600       1832       2469          8        733       2980 
## 0.04013390 0.04013746 0.04018156 0.04030269 0.04043589 0.04046880 
##       1737       3226        295       3616        899       1488 
## 0.04047232 0.04051589 0.04054180 0.04068023 0.04068862 0.04070558 
##       1984       1535       1610        628       2768        523 
## 0.04075025 0.04077613 0.04092275 0.04100936 0.04104807 0.04105327 
##       2887       3450       2329       2172       2273       2341 
## 0.04109614 0.04110118 0.04112489 0.04119673 0.04122674 0.04128985 
##       3893       2209        903       3218       1150       1825 
## 0.04129185 0.04132050 0.04134462 0.04137258 0.04141877 0.04142573 
##       2295       3909       3392       3960       2268        652 
## 0.04143166 0.04158829 0.04162984 0.04163752 0.04164966 0.04166310 
##       2976       2786        151        624       1660        305 
## 0.04189423 0.04196410 0.04199310 0.04201919 0.04202875 0.04210285 
##       3859        626       3756       3176       1351        188 
## 0.04219443 0.04219978 0.04226020 0.04226197 0.04235953 0.04240280 
##       2406       1817       2407       2071       2811        555 
## 0.04241422 0.04244603 0.04245196 0.04248681 0.04249733 0.04266891 
##       2008       2538       3734       3605       2793        536 
## 0.04287534 0.04301244 0.04304477 0.04305001 0.04306956 0.04310254 
##       1613       2881       2394       3797       1547       3740 
## 0.04311875 0.04316001 0.04317233 0.04323150 0.04327541 0.04335112 
##        962        417       1496       2736       3742        387 
## 0.04339457 0.04339715 0.04343043 0.04343051 0.04349458 0.04358378 
##       3957       3516       2039        297       2181       3184 
## 0.04359888 0.04364141 0.04364592 0.04364817 0.04365209 0.04367317 
##       3820       1853       1740       1649        735       1798 
## 0.04367805 0.04370609 0.04374031 0.04378243 0.04381176 0.04387215 
##       2647        787        164       1429       3593       2503 
## 0.04387337 0.04389924 0.04390430 0.04391668 0.04397355 0.04417083 
##       1599       1806       1030        927       1544        410 
## 0.04420893 0.04420902 0.04423402 0.04433563 0.04434427 0.04435999 
##        341       2475       3798       3154       3842       2236 
## 0.04437907 0.04438757 0.04447133 0.04449429 0.04452203 0.04453991 
##        347       3745       2229       3112        285       2453 
## 0.04456646 0.04459487 0.04472901 0.04474513 0.04475730 0.04480456 
##       3607        667       1654       3503        792       1189 
## 0.04492498 0.04492540 0.04508067 0.04510346 0.04514064 0.04520960 
##       2551        395       1683       3583        380       3804 
## 0.04523009 0.04527366 0.04528213 0.04540098 0.04548088 0.04549504 
##       2966        984       2783       1162       1723       3471 
## 0.04564032 0.04565343 0.04565826 0.04567893 0.04575249 0.04595138 
##       2791       2087       1575        302       3150       2681 
## 0.04606450 0.04606671 0.04615925 0.04618168 0.04629175 0.04631673 
##       2854       3556        569       3707        589        447 
## 0.04633854 0.04633971 0.04639237 0.04639606 0.04641592 0.04641942 
##       1372       3223       3897       3026       2518       2320 
## 0.04646199 0.04654841 0.04668415 0.04672166 0.04675786 0.04698107 
##       2011       1958       3276       3149       1904       2006 
## 0.04703341 0.04703883 0.04718956 0.04722713 0.04722934 0.04724872 
##       1804       1022       2939        255       2083       3595 
## 0.04727830 0.04735659 0.04737236 0.04743902 0.04750294 0.04758890 
##       1241        731        532        834       3672        828 
## 0.04760278 0.04763073 0.04764723 0.04766762 0.04768359 0.04776375 
##       1171       2246        450        485        529       2345 
## 0.04779249 0.04782963 0.04785368 0.04790167 0.04792392 0.04794904 
##        815        585        140       2776        553       1694 
## 0.04797000 0.04809657 0.04814666 0.04823154 0.04823978 0.04832229 
##       3658       1869       1934       2300       1718       1491 
## 0.04833359 0.04838806 0.04849282 0.04860709 0.04871306 0.04873352 
##       3384       3959       1211        563       1549       1568 
## 0.04876927 0.04879495 0.04884042 0.04890299 0.04890668 0.04901256 
##       2631        820       1198       1050         67         42 
## 0.04916879 0.04918703 0.04928145 0.04935442 0.04940604 0.04945627 
##       3230        990       2761        739       1304       3615 
## 0.04945856 0.04951117 0.04952301 0.04953811 0.04963600 0.04963693 
##       2415       3105       2719       2846       2646       2576 
## 0.04965864 0.04972543 0.04976254 0.04976278 0.04979449 0.04989413 
##        789        938       2642       2127       1915       3278 
## 0.04992935 0.04997933 0.04997933 0.04998100 0.05000886 0.05004916 
##        466       3528       3530        580       3251       2515 
## 0.05006233 0.05015501 0.05015800 0.05020342 0.05022987 0.05030986 
##       1781       3706        844       2820       3068        134 
## 0.05042108 0.05045311 0.05045470 0.05046120 0.05048163 0.05052094 
##       3978       2619       1460       2979       1353        114 
## 0.05054476 0.05055621 0.05056300 0.05061508 0.05067395 0.05071714 
##       2904       1319       1947       1321       3512       1338 
## 0.05075136 0.05076825 0.05080084 0.05085544 0.05090243 0.05097763 
##       2930        250       1227        710       2543        568 
## 0.05099974 0.05100256 0.05100791 0.05107210 0.05111273 0.05120317 
##       1023       1630       3931       2633       2862         97 
## 0.05123059 0.05123059 0.05126631 0.05129454 0.05134188 0.05135775 
##       2529        483       1369        352       1988        712 
## 0.05141938 0.05142025 0.05142694 0.05143498 0.05153234 0.05155299 
##       2452       3910       1899        778       1161        801 
## 0.05161976 0.05162572 0.05163011 0.05165991 0.05166089 0.05166844 
##       2243       3253       1597       2623        526       1753 
## 0.05178706 0.05180410 0.05181162 0.05191143 0.05192802 0.05199306 
##       2460       3010       2533          5       1931       2040 
## 0.05204060 0.05205054 0.05211785 0.05213091 0.05216612 0.05216967 
##       2277       2193       2850       3340       1138        371 
## 0.05222121 0.05229250 0.05231276 0.05238455 0.05239095 0.05247101 
##       1643       2037       1957         64        809       2227 
## 0.05250269 0.05255839 0.05258839 0.05262690 0.05266070 0.05266380 
##       1921       1122       3696       2465       3858       2534 
## 0.05269198 0.05271494 0.05288297 0.05292614 0.05295917 0.05296826 
##        233         83        366        428       1983       1515 
## 0.05297239 0.05298877 0.05300927 0.05306670 0.05308268 0.05310364 
##        923        527       1322       1891       1039       2286 
## 0.05311489 0.05313537 0.05313645 0.05314068 0.05317759 0.05319401 
##       1419       2117       3242       2059       1696        434 
## 0.05321580 0.05322574 0.05335826 0.05339542 0.05353275 0.05356755 
##       2797       2120       2934       3292       3639        711 
## 0.05357223 0.05358599 0.05359103 0.05360760 0.05362248 0.05362628 
##       2081       1013       1089       1624       3990       2605 
## 0.05366336 0.05373111 0.05373111 0.05373112 0.05375608 0.05381008 
##       3526        863       2287       3824       1131       1847 
## 0.05384751 0.05388114 0.05389568 0.05394205 0.05394855 0.05406909 
##        640       3260       3563       2690       1149       1220 
## 0.05407258 0.05410499 0.05410692 0.05410863 0.05410959 0.05411017 
##       1176       1011       3272       1948       1791       1243 
## 0.05418122 0.05423985 0.05425708 0.05434960 0.05441898 0.05442863 
##       1374       3390       3221          7         50        720 
## 0.05444966 0.05458101 0.05462563 0.05464254 0.05467472 0.05475021 
##       3297       2262       1386       2806       1102       2486 
## 0.05477427 0.05477600 0.05486305 0.05486488 0.05490116 0.05496053 
##       1850       1344       2632       3123       2316       3890 
## 0.05501262 0.05504147 0.05504244 0.05506073 0.05508223 0.05509641 
##         86       2790        270       1606       2974        278 
## 0.05512491 0.05513038 0.05513478 0.05519922 0.05524657 0.05527611 
##       3174       2993       2323       3785        178        206 
## 0.05533415 0.05534966 0.05541128 0.05541165 0.05541601 0.05544173 
##       1292       3524       1035        839       3029       3723 
## 0.05548073 0.05553584 0.05556011 0.05561349 0.05561483 0.05563011 
##       1029        469        873       3345       3939       3239 
## 0.05564590 0.05565933 0.05575214 0.05580246 0.05582835 0.05584065 
##        748       3942       1553        826       3887        272 
## 0.05587534 0.05590532 0.05591383 0.05601698 0.05601742 0.05603903 
##       1268       2573       1708       3580        774       2703 
## 0.05610304 0.05610842 0.05612099 0.05620617 0.05620765 0.05629494 
##        981        236       2933        649       1481        982 
## 0.05629729 0.05631176 0.05644694 0.05646091 0.05647255 0.05648390 
##       1673       2052        686       1143        348       3444 
## 0.05650293 0.05653351 0.05658573 0.05658573 0.05660314 0.05665250 
##       3064       2852       1108       1142       3646       1326 
## 0.05668608 0.05671210 0.05678046 0.05688576 0.05690072 0.05699104 
##       1587        979       2290       1015       2194       3285 
## 0.05699681 0.05700015 0.05700133 0.05700992 0.05701297 0.05702630 
##        399       3408       1128        613       2497        463 
## 0.05703189 0.05705338 0.05705720 0.05714477 0.05719154 0.05729153 
##       1581        256         33       3315       2892        790 
## 0.05733334 0.05739752 0.05740250 0.05741517 0.05744067 0.05744086 
##       1880       2046       2528        234       2049        172 
## 0.05746608 0.05748930 0.05751378 0.05756997 0.05759663 0.05771192 
##        888       1626       2853       2568        408       3287 
## 0.05772517 0.05772944 0.05784969 0.05788439 0.05791654 0.05799628 
##        129       1046       3196        377       1800       1707 
## 0.05800559 0.05800808 0.05800970 0.05802206 0.05802222 0.05802368 
##       1019       3865        757       2270       1743        287 
## 0.05807262 0.05812826 0.05813520 0.05814854 0.05816840 0.05820668 
##       2296       1370       2922        496       1340       1358 
## 0.05831102 0.05832010 0.05837617 0.05839955 0.05839955 0.05843121 
##       3874       1091       2430       3028       1163       3234 
## 0.05845701 0.05846027 0.05848930 0.05851525 0.05853291 0.05860757 
##        894       2873       2456       3808       1026       3470 
## 0.05860869 0.05878562 0.05882299 0.05884470 0.05894672 0.05901329 
##       3831        622       1249        549       1829       1987 
## 0.05911667 0.05917571 0.05926290 0.05932668 0.05939129 0.05943620 
##       1766       1066        718       3519        415       2293 
## 0.05950345 0.05950918 0.05955032 0.05957702 0.05958615 0.05959297 
##       2493         21        374       2014       3975       3202 
## 0.05962364 0.05979772 0.05979935 0.05984740 0.05987133 0.05988966 
##       3431       2577       3183       3438       2872       2244 
## 0.05995410 0.06000124 0.06004792 0.06007381 0.06009280 0.06013841 
##       2869       2684       3359       2464       1813       3416 
## 0.06020612 0.06022153 0.06027910 0.06028067 0.06028459 0.06030009 
##       3809        866       3592       3763       2744       1435 
## 0.06033897 0.06036023 0.06039180 0.06049753 0.06059691 0.06069727 
##       1838       2758       2926       1282       2186       1923 
## 0.06071782 0.06078306 0.06079795 0.06086702 0.06087821 0.06092769 
##       1592        892        876       2405       3771        238 
## 0.06095881 0.06105867 0.06105988 0.06109892 0.06113156 0.06123711 
##       1495       3270       1735        817       3732        378 
## 0.06131193 0.06137992 0.06140206 0.06148564 0.06154060 0.06162750 
##       1757        535       3061       2248        160        307 
## 0.06165712 0.06172161 0.06181527 0.06185597 0.06189711 0.06192085 
##       3783       3976       2705        724       3698        717 
## 0.06203422 0.06213941 0.06215843 0.06217548 0.06222703 0.06232999 
##        237       3578       2825       2403       1346       3463 
## 0.06237689 0.06239836 0.06240947 0.06241089 0.06243503 0.06246321 
##        156       3222       3335       3232       1521       3726 
## 0.06261760 0.06263864 0.06275629 0.06278962 0.06279219 0.06283718 
##         72        192        910       1214        438       1051 
## 0.06288578 0.06289431 0.06295320 0.06299656 0.06311607 0.06311882 
##       2757        680       1844       1120       1820        264 
## 0.06313034 0.06323311 0.06325126 0.06325835 0.06327665 0.06328394 
##       1570       3110         66       3856        257       2299 
## 0.06328583 0.06329232 0.06329360 0.06343171 0.06361453 0.06363391 
##        945        509       2421        392        497       2094 
## 0.06363813 0.06365095 0.06385387 0.06387848 0.06388917 0.06389299 
##       2709       2067       1400       3280       1618        525 
## 0.06391337 0.06393829 0.06395759 0.06404464 0.06405429 0.06412776 
##       3033       1167        117       3104        671       2983 
## 0.06415337 0.06422205 0.06429081 0.06431798 0.06435466 0.06447553 
##       3610       3807       3256       1528       1018        901 
## 0.06450721 0.06453231 0.06453660 0.06458584 0.06459389 0.06482331 
##       2337       1355       2139       3483       1828       3213 
## 0.06485408 0.06502646 0.06504416 0.06508608 0.06514279 0.06520047 
##       3198        277       1525       1232       3955        911 
## 0.06526350 0.06529238 0.06546570 0.06553846 0.06565206 0.06569563 
##        534       3403       1893       2649       1427       2485 
## 0.06569642 0.06570861 0.06572376 0.06574674 0.06576587 0.06580416 
##       1221        301       2945       2365        168       2152 
## 0.06591586 0.06593277 0.06600263 0.06601202 0.06603141 0.06604827 
##        191       3814       2773       2946       3971       2199 
## 0.06606777 0.06612210 0.06614734 0.06615039 0.06620812 0.06627784 
##       2750        829       2137       1065       1110        225 
## 0.06627982 0.06640088 0.06643508 0.06643563 0.06649246 0.06653166 
##       1003        788        484       1410       2685       2076 
## 0.06659996 0.06661135 0.06662363 0.06669733 0.06676020 0.06678887 
##       1413       2996       3291       2546        781       1670 
## 0.06685791 0.06691835 0.06693221 0.06697455 0.06700502 0.06704206 
##       2123        595       1666       1054       1883       2506 
## 0.06704826 0.06719840 0.06749437 0.06752525 0.06754168 0.06759367 
##        362        176       1330       3162        822       1917 
## 0.06763534 0.06765623 0.06770509 0.06771661 0.06774694 0.06784840 
##       3899       1364        322        843       1329       2732 
## 0.06796044 0.06809528 0.06827604 0.06834672 0.06837035 0.06854504 
##       1805        871       1563       2905       1540       1731 
## 0.06858767 0.06867618 0.06870337 0.06874462 0.06890057 0.06894760 
##        848       2166       3322       1004        440        157 
## 0.06904122 0.06904279 0.06909366 0.06909525 0.06910737 0.06923257 
##       2324       2161       2910       3090       2511       1308 
## 0.06939697 0.06943276 0.06947594 0.06954772 0.06957446 0.06958192 
##       2531       3755        424        934       2602       3011 
## 0.06958494 0.06969884 0.06979330 0.06986221 0.06987906 0.06990252 
##       3454       3366       2586        976       1662       3608 
## 0.06997690 0.07016305 0.07018668 0.07019510 0.07023293 0.07025877 
##        538       3233       1661        679        261       2043 
## 0.07026935 0.07039531 0.07039567 0.07043577 0.07045104 0.07049098 
##       1057       3402       1385        694       1848       2741 
## 0.07053125 0.07058704 0.07068588 0.07069130 0.07085760 0.07093367 
##       2157       3822        276       2314        495       1190 
## 0.07099702 0.07099832 0.07102922 0.07104482 0.07106237 0.07108952 
##         43       1677       2195        464       2937       2805 
## 0.07110000 0.07112264 0.07121344 0.07127673 0.07129772 0.07137597 
##        409       3195       1159       1090       3309       3912 
## 0.07138894 0.07140036 0.07149324 0.07152395 0.07159321 0.07162577 
##       2351       1693        948       3023       2297       2571 
## 0.07163573 0.07175197 0.07190484 0.07194436 0.07204956 0.07216192 
##       3674       2436       1517       1596       2664        130 
## 0.07223345 0.07226119 0.07227009 0.07242927 0.07243248 0.07244997 
##        292       3769       2863       3762       1199       2202 
## 0.07256647 0.07263854 0.07264951 0.07269054 0.07276786 0.07280318 
##        119       2455       1851       3991       2360       3339 
## 0.07282517 0.07287389 0.07302270 0.07304191 0.07307238 0.07308228 
##       1396       3156       2165       1646       3534       3523 
## 0.07308418 0.07312217 0.07314435 0.07315943 0.07323749 0.07327958 
##       1033       2557        152          6        385       3561 
## 0.07335263 0.07350288 0.07354811 0.07359300 0.07369423 0.07370257 
##       1052        642       1391       3495        182        715 
## 0.07379611 0.07396585 0.07400414 0.07400928 0.07409057 0.07415208 
##       1253       3718        791       1780       2984       1895 
## 0.07419645 0.07419646 0.07431209 0.07440412 0.07440526 0.07443735 
##       3629       1310       1031       1025        558         75 
## 0.07444422 0.07447268 0.07448376 0.07450654 0.07461791 0.07465991 
##        605       1457       1045       3551       2012       1821 
## 0.07470904 0.07474364 0.07476000 0.07476477 0.07480444 0.07485598 
##       2832       2084        232       1705       3854       1177 
## 0.07490842 0.07492194 0.07501277 0.07508608 0.07516297 0.07517283 
##        406       2598        480       2198       1456       3169 
## 0.07518390 0.07521854 0.07540272 0.07546882 0.07550579 0.07553424 
##        363       2912       1650       3582       2957       1285 
## 0.07557889 0.07558804 0.07591984 0.07599068 0.07600400 0.07603419 
##       1306       3418        339       3853       1486        980 
## 0.07629952 0.07630222 0.07639735 0.07640172 0.07640813 0.07641323 
##       2051       3542       3538       3557       1182        937 
## 0.07646000 0.07651616 0.07655297 0.07655297 0.07669845 0.07670802 
##       2603       1808        676        932        319         36 
## 0.07674422 0.07679865 0.07684054 0.07685845 0.07692831 0.07698367 
##       1127       2142       2670        426       2604       2566 
## 0.07700685 0.07705593 0.07708282 0.07723511 0.07726840 0.07734350 
##       1485        198       1431        570       3070       1315 
## 0.07748106 0.07750344 0.07754343 0.07754525 0.07756922 0.07768539 
##       3121       1716       2611       1709       3078        141 
## 0.07799683 0.07819565 0.07820140 0.07825551 0.07836211 0.07839110 
##       1056       1247       2578        482       3341       1383 
## 0.07839939 0.07870321 0.07872132 0.07873290 0.07882620 0.07889290 
##       2225       3515       2704       2113       1448       1181 
## 0.07899745 0.07913695 0.07914593 0.07915952 0.07927969 0.07942958 
##         11        759        818       2929       2124        193 
## 0.07953051 0.07959650 0.07984775 0.07995196 0.08007628 0.08013831 
##       2445       2563       1239       2444        773       3452 
## 0.08019378 0.08026110 0.08034526 0.08040637 0.08042521 0.08050429 
##        797       2666       1840       3054       1226        308 
## 0.08082498 0.08084921 0.08086325 0.08091485 0.08098891 0.08104361 
##        769       2352         53       3065       2350        887 
## 0.08107122 0.08111878 0.08116321 0.08131089 0.08137184 0.08139770 
##       1341       1360       2154       3151       1857       3079 
## 0.08144050 0.08145822 0.08159133 0.08160509 0.08178872 0.08179187 
##       2964       1175       1155       2078       2513        263 
## 0.08182668 0.08186546 0.08188135 0.08199245 0.08199785 0.08203375 
##       1399        608       1614       1759        601       3648 
## 0.08216557 0.08216719 0.08217716 0.08217970 0.08224730 0.08239666 
##       2737       2874       2608        842       1989       1967 
## 0.08250611 0.08251465 0.08263113 0.08266966 0.08268232 0.08271306 
##       2764        738        196       3125        422        893 
## 0.08272874 0.08280012 0.08282813 0.08294746 0.08299300 0.08307358 
##        394       3128        974       3702       1328       1629 
## 0.08308542 0.08314186 0.08318942 0.08334643 0.08342524 0.08352806 
##       1940       2967       1555       2224       3387        620 
## 0.08358037 0.08358933 0.08362195 0.08364063 0.08364965 0.08365327 
##       2443        633       2483        472       1104        269 
## 0.08373463 0.08379097 0.08396607 0.08404502 0.08405169 0.08408314 
##        936        279       2615       3627       1951       2156 
## 0.08409821 0.08422920 0.08441442 0.08453334 0.08458961 0.08462078 
##       1297       2462       2408       2222        226       2023 
## 0.08471371 0.08479332 0.08494747 0.08498991 0.08503419 0.08514520 
##       3317       1444       1973       2190        819       3851 
## 0.08521218 0.08528849 0.08542577 0.08547070 0.08547856 0.08551853 
##       2738       2069       3873       2118       3013       2217 
## 0.08560109 0.08570951 0.08585085 0.08596004 0.08600502 0.08601083 
##        432        554       2206        779       1493        283 
## 0.08601754 0.08606884 0.08610630 0.08612489 0.08616347 0.08616721 
##       3683       1639       3096        956       3587       3353 
## 0.08617847 0.08618840 0.08622190 0.08626857 0.08640372 0.08642357 
##        419       2644       1787        832       1088       2213 
## 0.08647509 0.08674384 0.08676238 0.08684371 0.08689145 0.08701129 
##       2900       2574       2205       3947       3832       1414 
## 0.08714827 0.08717345 0.08728389 0.08752954 0.08755917 0.08784101 
##       1725        772       3485       2021       1641       1520 
## 0.08788430 0.08810695 0.08811174 0.08826567 0.08843599 0.08850500 
##       1809         94       2618        333         68       2311 
## 0.08851707 0.08852110 0.08854514 0.08856270 0.08860315 0.08863078 
##       1121       2200         92       3349       1835       3998 
## 0.08867943 0.08871112 0.08891058 0.08924856 0.08927385 0.08928179 
##       3171       2220        880        964       2307        358 
## 0.08934880 0.08941130 0.08951435 0.08954287 0.08966565 0.08989428 
##       3240       2671       3494        293       2108       3934 
## 0.08995441 0.08997883 0.08999462 0.09011238 0.09011769 0.09012291 
##       1263        370       3691       1764       2777       2802 
## 0.09014857 0.09020209 0.09050778 0.09063144 0.09064294 0.09069266 
##       1815       1841       3994       3204        262       3649 
## 0.09072619 0.09081376 0.09086764 0.09088551 0.09104884 0.09117957 
##        328       3479        186        282       1068       2232 
## 0.09160559 0.09208411 0.09215741 0.09218470 0.09249264 0.09262318 
##       1775       1507       1170       2417       2234       1016 
## 0.09263318 0.09280150 0.09301477 0.09333173 0.09338601 0.09366226 
##       2624       3030       1223       2903        102        616 
## 0.09378374 0.09379755 0.09407748 0.09407981 0.09412334 0.09413666 
##       1380       2041       2542       2818       3736       2570 
## 0.09420436 0.09464093 0.09465956 0.09467746 0.09503196 0.09526706 
##       3714       3540       3766       3721       1564       1497 
## 0.09533101 0.09541182 0.09543267 0.09546379 0.09548653 0.09631073 
##       1272        957        968       3488       2795       3550 
## 0.09668036 0.09695877 0.09714878 0.09733528 0.09750259 0.09762614 
##       2510       2616        765       3375       1286       3396 
## 0.09765649 0.09825175 0.09825321 0.09849782 0.09893527 0.09894577 
##        425       1756       3382       1467       2911        268 
## 0.09904788 0.09912216 0.09949392 0.09961125 0.09966006 0.09977767 
##       2386       1999       2379        846        435       1210 
## 0.10006596 0.10031020 0.10038581 0.10055476 0.10109772 0.10134895 
##       1403       2143       2901       2836       1296       2867 
## 0.10147002 0.10153782 0.10167199 0.10170801 0.10180797 0.10189864 
##        369        220       3199       1309       1008       2554 
## 0.10194293 0.10208386 0.10243290 0.10246246 0.10270711 0.10281293 
##       1807       2804       1659       1526       3224        488 
## 0.10282060 0.10297114 0.10305073 0.10306444 0.10322080 0.10374572 
##       1499       2847       1548        966       2032       1970 
## 0.10398153 0.10406945 0.10426313 0.10433987 0.10461885 0.10467604 
##       3446        465       3422        606       2054       2943 
## 0.10471410 0.10482553 0.10566671 0.10571824 0.10580262 0.10588969 
##       2437       1684        324       3778       2369       3956 
## 0.10594319 0.10650158 0.10667478 0.10700800 0.10724752 0.10727820 
##       2467       3084        499       3558        883       3708 
## 0.10750112 0.10755637 0.10776720 0.10823260 0.10830048 0.10830321 
##        473       3727        154       2492        280       3049 
## 0.10834081 0.10885529 0.10890220 0.10902711 0.10922921 0.10923269 
##        559          2       1455        811       3932       2047 
## 0.10924753 0.10940092 0.11010841 0.11016044 0.11035078 0.11079918 
##       3624       1267       1777        831       1686       2677 
## 0.11098481 0.11103448 0.11106497 0.11112371 0.11116630 0.11125545 
##       2657       1475       3914       3728       2775       2325 
## 0.11149455 0.11162246 0.11173708 0.11184944 0.11205720 0.11222029 
##         51       3055        593       1727       3480       2494 
## 0.11226384 0.11263049 0.11274503 0.11284441 0.11296583 0.11321196 
##       2292       3861        896        468       1179       2958 
## 0.11325066 0.11358959 0.11365535 0.11369746 0.11372940 0.11414784 
##       3016        924        213       2514       2541       3539 
## 0.11437557 0.11480098 0.11509449 0.11518460 0.11571371 0.11573225 
##       2919       2278       1278       1462       2265       3764 
## 0.11573365 0.11576873 0.11579720 0.11604676 0.11627303 0.11642084 
##       2780       2866       3637       3440       2778       3203 
## 0.11648847 0.11658316 0.11669166 0.11690265 0.11705546 0.11747539 
##       3098       1830        965        750       2636        786 
## 0.11789068 0.11797879 0.11802194 0.11830753 0.11836100 0.11851758 
##        929       2105       1522        375       2328       1452 
## 0.11868870 0.11875287 0.11912350 0.11912996 0.11937206 0.11947157 
##       3381       3716       3279       2829       3057       3214 
## 0.11950403 0.11956730 0.11959352 0.11966039 0.11986977 0.12012584 
##       3849        872       1509        562        709       3094 
## 0.12025111 0.12033249 0.12057997 0.12064463 0.12078620 0.12093452 
##       3532       1919        551        248       3668       1095 
## 0.12116375 0.12150716 0.12170724 0.12208828 0.12219126 0.12225567 
##        950       3237       3715       2404       2397       2354 
## 0.12238419 0.12241922 0.12281055 0.12319378 0.12346052 0.12364864 
##       3576       1505        661       1156       3116       2970 
## 0.12386405 0.12390321 0.12419006 0.12433837 0.12450860 0.12477699 
##       3045       3379       3535       2706       1711       3085 
## 0.12489670 0.12570328 0.12570948 0.12572027 0.12617628 0.12653115 
##       1207       2672       2419       1571       1283       3012 
## 0.12703382 0.12704112 0.12737913 0.12745846 0.12979866 0.12997571 
##       2864        625       1738       2519       2109       1773 
## 0.13040926 0.13043809 0.13054956 0.13092961 0.13106001 0.13138567 
##         32       1086       1774       2313       1412       1352 
## 0.13219839 0.13301920 0.13347781 0.13381900 0.13382239 0.13432829 
##       3004       3573        935       2141       3651        889 
## 0.13452739 0.13456921 0.13457382 0.13478423 0.13488186 0.13502517 
##        721        603       2208       1114       2425       3301 
## 0.13554004 0.13554470 0.13575843 0.13596212 0.13600988 0.13618390 
##       3136       3498       2029       3391        588       3456 
## 0.13623978 0.13646096 0.13654657 0.13664367 0.13682465 0.13742294 
##       3602       1992       2499       3314       3657        825 
## 0.13767812 0.13776505 0.13779975 0.13860028 0.13959844 0.14053069 
##        975       2555       2629        673       2948        396 
## 0.14091064 0.14132942 0.14135363 0.14145188 0.14189488 0.14211155 
##       2085       3518       3570         48       3653       1879 
## 0.14219280 0.14329351 0.14329950 0.14369720 0.14405954 0.14433675 
##       2985       1884        149       1871       2650       3979 
## 0.14454533 0.14459436 0.14491490 0.14575760 0.14609092 0.14792861 
##       2155       1868         63        611        598        970 
## 0.14825829 0.14854068 0.14860306 0.14866241 0.14924688 0.14931375 
##       1733        807       1706       3369        502       2106 
## 0.14950548 0.14962175 0.14968759 0.14982143 0.14985870 0.15057048 
##        760       1178       2489       3791       3618       1289 
## 0.15076287 0.15120470 0.15174592 0.15311013 0.15325912 0.15372468 
##         52       1168        744       1450       1240       1676 
## 0.15449864 0.15529287 0.15629791 0.15661160 0.15677915 0.15684181 
##        312       1081       1703       1898       3623       3117 
## 0.15695157 0.15720095 0.15774175 0.15833037 0.15860472 0.15915024 
##       3458       1301       3868       1810        207       2723 
## 0.15947481 0.15950263 0.15971518 0.16003466 0.16144618 0.16161390 
##       2458       2476       3389       2125       3140       1103 
## 0.16235118 0.16324059 0.16341348 0.16399041 0.16421294 0.16523523 
##        971        591       2526       3266        113       2567 
## 0.16648510 0.16720892 0.16784380 0.16918629 0.16929707 0.16949268 
##       2950       3072        921        697       3604       2414 
## 0.16979397 0.17060374 0.17151145 0.17237329 0.17241298 0.17282933 
##       1682       3209       2413       3866       1252       2700 
## 0.17340911 0.17368283 0.17500678 0.17552025 0.17763129 0.17873898 
##       3628       2747       1469       2720       1558       1349 
## 0.17926547 0.18006430 0.18016431 0.18025966 0.18127975 0.18241245 
##        338       2713        747       1890        315         12 
## 0.18359193 0.18386063 0.18393381 0.18594495 0.18755133 0.18771054 
##        755       1536       3675       2380       2065        405 
## 0.18777502 0.18924814 0.18974599 0.19089111 0.19115626 0.19148103 
##       3052       3913       1126        137       2457        539 
## 0.19151148 0.19165604 0.19261704 0.19314177 0.19371408 0.19379773 
##       3311        439       3972       3191       1644       3690 
## 0.19418748 0.19433820 0.19465789 0.19626971 0.19637657 0.19644978 
##       2935       2072       1480       3507       2226       2447 
## 0.19790618 0.19827737 0.19883595 0.19985840 0.20092098 0.20175097 
##       1623       3457         57       1954         55       2701 
## 0.20573806 0.21026841 0.21063265 0.21239679 0.21581575 0.21729799 
##        614       3679       1569       1982        942         47 
## 0.21924412 0.22228474 0.22404744 0.22416946 0.22728475 0.22856576 
##       3673       3966       2347       2110       1165       1202 
## 0.22925063 0.23101550 0.23235170 0.23266799 0.23574156 0.23790915 
##        668       3192       1441       1608         40       1287 
## 0.24138956 0.24151676 0.24474332 0.24617920 0.24673473 0.24676285 
##       3553        602        958        691         60       2429 
## 0.24769923 0.24999327 0.25187127 0.25188453 0.25374341 0.25629614 
##        875       3435         20       3967       1609       1473 
## 0.25699839 0.25741369 0.26138785 0.26363419 0.26749556 0.26860436 
##       2675       1873       2359        870       2596         98 
## 0.26940503 0.26981336 0.27087264 0.27225821 0.27658640 0.27838685 
##       1631       2584       1422       1700       3915        943 
## 0.27967878 0.28491738 0.28683462 0.29409895 0.30353269 0.30597594 
##        390         56       1213       2590         87         70 
## 0.30801942 0.30924196 0.31277121 0.31523203 0.32477208 0.32899194 
##        864        726        955        853       3497        194 
## 0.35200130 0.35861403 0.35975626 0.36337988 0.37904522 0.40610645 
##        847       1365       1125         90 
## 0.46008411 0.48322861 0.50381494 0.53926222
4. Which records does your model predict to have a greater than 40% probability of responding to the Florence mailing? What are the Rcode, Fcode, and Mcode values for these particular records? (you can simply look at your validation data and inspect it manually – there won’t be very many rows to check here).

The records that have a greater 40% probability of responding are 194, 847, 1365, 1125 and 90 with the corresponding probabilities of 0.40610645, 0.46008411, 0.48322861, 0.50381494 and 0.53926222.

library(dplyr)
d2<-valid.df %>% select(Seq.,Rcode,Fcode,Mcode) %>% filter(Seq. %in% c(194,847,1365,1125,90))
d2
##   Seq. Rcode Fcode Mcode
## 1   90     1     3     5
## 2  194     3     3     5
## 3  847     4     3     5
## 4 1125     3     3     5
## 5 1365     3     3     5

II. Read the German Credit case (pp. 505-509 in the text)

A. Create a data partition. Again, for the data partition, use your unique seed value. Show the code that you used to do this.
g1<-read.csv("germancredit.csv") #importing the data
head(g1,10)
##    OBS. CHK_ACCT DURATION HISTORY NEW_CAR USED_CAR FURNITURE RADIO.TV
## 1     1        0        6       4       0        0         0        1
## 2     2        1       48       2       0        0         0        1
## 3     3        3       12       4       0        0         0        0
## 4     4        0       42       2       0        0         1        0
## 5     5        0       24       3       1        0         0        0
## 6     6        3       36       2       0        0         0        0
## 7     7        3       24       2       0        0         1        0
## 8     8        1       36       2       0        1         0        0
## 9     9        3       12       2       0        0         0        1
## 10   10        1       30       4       1        0         0        0
##    EDUCATION RETRAINING AMOUNT SAV_ACCT EMPLOYMENT INSTALL_RATE MALE_DIV
## 1          0          0   1169        4          4            4        0
## 2          0          0   5951        0          2            2        0
## 3          1          0   2096        0          3            2        0
## 4          0          0   7882        0          3            2        0
## 5          0          0   4870        0          2            3        0
## 6          1          0   9055        4          2            2        0
## 7          0          0   2835        2          4            3        0
## 8          0          0   6948        0          2            2        0
## 9          0          0   3059        3          3            2        1
## 10         0          0   5234        0          0            4        0
##    MALE_SINGLE MALE_MAR_or_WID CO.APPLICANT GUARANTOR PRESENT_RESIDENT
## 1            1               0            0         0                4
## 2            0               0            0         0                2
## 3            1               0            0         0                3
## 4            1               0            0         1                4
## 5            1               0            0         0                4
## 6            1               0            0         0                4
## 7            1               0            0         0                4
## 8            1               0            0         0                2
## 9            0               0            0         0                4
## 10           0               1            0         0                2
##    REAL_ESTATE PROP_UNKN_NONE AGE OTHER_INSTALL RENT OWN_RES NUM_CREDITS
## 1            1              0  67             0    0       1           2
## 2            1              0  22             0    0       1           1
## 3            1              0  49             0    0       1           1
## 4            0              0  45             0    0       0           1
## 5            0              1  53             0    0       0           2
## 6            0              1  35             0    0       0           1
## 7            0              0  53             0    0       1           1
## 8            0              0  35             0    1       0           1
## 9            1              0  61             0    0       1           1
## 10           0              0  28             0    0       1           2
##    JOB NUM_DEPENDENTS TELEPHONE FOREIGN RESPONSE
## 1    2              1         1       0        1
## 2    2              1         0       0        0
## 3    1              2         0       0        1
## 4    2              2         0       0        1
## 5    2              2         0       0        0
## 6    1              2         1       0        1
## 7    2              1         0       0        1
## 8    3              1         1       0        1
## 9    1              1         0       0        1
## 10   3              1         0       0        0
names(g1)
##  [1] "OBS."             "CHK_ACCT"         "DURATION"        
##  [4] "HISTORY"          "NEW_CAR"          "USED_CAR"        
##  [7] "FURNITURE"        "RADIO.TV"         "EDUCATION"       
## [10] "RETRAINING"       "AMOUNT"           "SAV_ACCT"        
## [13] "EMPLOYMENT"       "INSTALL_RATE"     "MALE_DIV"        
## [16] "MALE_SINGLE"      "MALE_MAR_or_WID"  "CO.APPLICANT"    
## [19] "GUARANTOR"        "PRESENT_RESIDENT" "REAL_ESTATE"     
## [22] "PROP_UNKN_NONE"   "AGE"              "OTHER_INSTALL"   
## [25] "RENT"             "OWN_RES"          "NUM_CREDITS"     
## [28] "JOB"              "NUM_DEPENDENTS"   "TELEPHONE"       
## [31] "FOREIGN"          "RESPONSE"
A.Create a data partition. Again, for the data partition, use your unique seed value. Show the code that you used to do this.

Create training and validation sets

set.seed(60) 
train.index2 <- sample(rownames(g1), dim(g1)[1]*0.6) 
train.df2<- g1[train.index,]
valid.index <- setdiff(rownames(g1), train.index)
valid.df2<- g1[valid.index, ]
B. Using your training data, build a classification tree model with RESPONSE as the outcome variable, and with the following input variables: CHK_ACCT, DURATION, HISTORY, EMPLOYMENT, REAL_ESTATE, and JOB.
C. Type the name of the variable that you created into the console to learn more about the model that you just created (for instance, if your model is named “tree”) type tree to learn about your splits and y-values. Show the result.
D. Use rpart.plot to get a visual depiction of your model, and show the result.
table(g1$RESPONSE)
## 
##   0   1 
## 300 700
g1$RESPONSE<-as.factor(g1$RESPONSE)

Build Classification Trees

library(adabag)
## Loading required package: rpart
## Loading required package: foreach
## Loading required package: doParallel
## Loading required package: iterators
## Loading required package: parallel
library(rpart)
library(caret)
library(rpart.plot)

class.tree<-rpart(RESPONSE~CHK_ACCT+DURATION+HISTORY+EMPLOYMENT+REAL_ESTATE+JOB,data=train.df2, method = "class") 
class.tree
## n=573 (1827 observations deleted due to missingness)
## 
## node), split, n, loss, yval, (yprob)
##       * denotes terminal node
## 
##  1) root 573 180 1 (0.31413613 0.68586387)  
##    2) CHK_ACCT< 1.5 311 145 1 (0.46623794 0.53376206)  
##      4) DURATION>=11.5 260 124 0 (0.52307692 0.47692308)  
##        8) DURATION>=22.5 135  55 0 (0.59259259 0.40740741)  
##         16) JOB< 2.5 108  40 0 (0.62962963 0.37037037)  
##           32) CHK_ACCT< 0.5 58  15 0 (0.74137931 0.25862069) *
##           33) CHK_ACCT>=0.5 50  25 0 (0.50000000 0.50000000)  
##             66) EMPLOYMENT< 2.5 31  12 0 (0.61290323 0.38709677) *
##             67) EMPLOYMENT>=2.5 19   6 1 (0.31578947 0.68421053) *
##         17) JOB>=2.5 27  12 1 (0.44444444 0.55555556)  
##           34) CHK_ACCT>=0.5 16   5 0 (0.68750000 0.31250000) *
##           35) CHK_ACCT< 0.5 11   1 1 (0.09090909 0.90909091) *
##        9) DURATION< 22.5 125  56 1 (0.44800000 0.55200000)  
##         18) HISTORY< 1.5 16   4 0 (0.75000000 0.25000000) *
##         19) HISTORY>=1.5 109  44 1 (0.40366972 0.59633028) *
##      5) DURATION< 11.5 51   9 1 (0.17647059 0.82352941) *
##    3) CHK_ACCT>=1.5 262  35 1 (0.13358779 0.86641221) *
prp(class.tree, type = 1, extra = 1, under = TRUE, split.font
= 1, varlen = -10, box.palette = c("green","yellow","light blue","pink"))

E. For any one terminal node on your tree, describe what it says, step-by-step, from top to bottom (For instance, with a different data set, you could say something like, “For a car with 6 or more cylinders, and horsepower of greater than 200cc, the model predicts that it will be labeled as a “muscle car.”)

For the pink terminal node in the middle of the bottom, the first split is on CHK_ACCT of 1.5, then the next split is on Duration for the Checking Account Status less than 1.5. The fowllowing split is on Duration greater than 22 months for the Duration of Credit in Months more than 12 months. The fourth split is on Job greater than or equal to 2.5 for the Duration of Credit in Months more than 22 months. Next, the slipt is on CHK_ACCT greater than 0.5 for the Nature of Job greater than or equal to 2.5. The pink terminal node will be interpreted as belonging to the group with CHK_ACCT less than 1.5, Duration greater than 12, Duration more than 22, Job greater or equal to 2.5 and CHK_ACCT less than 0.5 than Response = 1pd. The number 10 underneath the prink node means 10 people with Response of 1 (1:Credit Rating is Good). And the number 1 on the left means 1 person with Response of 0 (0:Credit Rating isn’t Good).