This package was set for the Credit Access studies. But it can be
used for the binary and multiple factor variables. First thing let’s see
the str of the sample_data with str(sample_data)
.
Since the dataset is huge, let’s take the first 500 rows and set the
study on it.
The following example run the
multinominal logistic model
in yvar
. The
function simplifies the 80/20 train test set using 10cv after scaled and
center it.
#> Loading required package: ggplot2
#> Loading required package: lattice
#> + Fold01: mtry= 2
#> - Fold01: mtry= 2
#> + Fold01: mtry= 7
#> - Fold01: mtry= 7
#> + Fold01: mtry=12
#> - Fold01: mtry=12
#> + Fold02: mtry= 2
#> - Fold02: mtry= 2
#> + Fold02: mtry= 7
#> - Fold02: mtry= 7
#> + Fold02: mtry=12
#> - Fold02: mtry=12
#> + Fold03: mtry= 2
#> - Fold03: mtry= 2
#> + Fold03: mtry= 7
#> - Fold03: mtry= 7
#> + Fold03: mtry=12
#> - Fold03: mtry=12
#> + Fold04: mtry= 2
#> - Fold04: mtry= 2
#> + Fold04: mtry= 7
#> - Fold04: mtry= 7
#> + Fold04: mtry=12
#> - Fold04: mtry=12
#> + Fold05: mtry= 2
#> - Fold05: mtry= 2
#> + Fold05: mtry= 7
#> - Fold05: mtry= 7
#> + Fold05: mtry=12
#> - Fold05: mtry=12
#> + Fold06: mtry= 2
#> - Fold06: mtry= 2
#> + Fold06: mtry= 7
#> - Fold06: mtry= 7
#> + Fold06: mtry=12
#> - Fold06: mtry=12
#> + Fold07: mtry= 2
#> - Fold07: mtry= 2
#> + Fold07: mtry= 7
#> - Fold07: mtry= 7
#> + Fold07: mtry=12
#> - Fold07: mtry=12
#> + Fold08: mtry= 2
#> - Fold08: mtry= 2
#> + Fold08: mtry= 7
#> - Fold08: mtry= 7
#> + Fold08: mtry=12
#> - Fold08: mtry=12
#> + Fold09: mtry= 2
#> - Fold09: mtry= 2
#> + Fold09: mtry= 7
#> - Fold09: mtry= 7
#> + Fold09: mtry=12
#> - Fold09: mtry=12
#> + Fold10: mtry= 2
#> - Fold10: mtry= 2
#> + Fold10: mtry= 7
#> - Fold10: mtry= 7
#> + Fold10: mtry=12
#> - Fold10: mtry=12
#> Aggregating results
#> Selecting tuning parameters
#> Fitting mtry = 2 on full training set
#> Multi-class area under the curve: 0.7275
Estimate_Models function considers exog
and
xadd
variables and set multiple models based on the
selected exog
and xadd
. On the one hand
exog
is subtract the selected vector from the dataset and
run the model for all the dataset and for the splits of the
exog
. On the other hand xadd
add the selected
vectors and run the model. Where the dnames
are the unique
values in exog
this is to save the model estimates by their
name.
sample_data <- sample_data[c(1:750),]
yvar <- c("Loan.Type")
xvar <- c("sex", "married", "age", "havejob", "educ", "political.afl",
"rural", "region", "fin.intermdiaries", "fin.knowldge", "income")
CCP.RF <- Estimate_Models(sample_data, yvar, xvec = xvar, exog = "political.afl",
xadd = c("networth", "networth_homequity", "liquid.assets"),
type = "RF", dnames = c("0","1"))
#> + Fold01: mtry= 2
#> - Fold01: mtry= 2
#> + Fold01: mtry= 6
#> - Fold01: mtry= 6
#> + Fold01: mtry=11
#> - Fold01: mtry=11
#> + Fold02: mtry= 2
#> - Fold02: mtry= 2
#> + Fold02: mtry= 6
#> - Fold02: mtry= 6
#> + Fold02: mtry=11
#> - Fold02: mtry=11
#> + Fold03: mtry= 2
#> - Fold03: mtry= 2
#> + Fold03: mtry= 6
#> - Fold03: mtry= 6
#> + Fold03: mtry=11
#> - Fold03: mtry=11
#> + Fold04: mtry= 2
#> - Fold04: mtry= 2
#> + Fold04: mtry= 6
#> - Fold04: mtry= 6
#> + Fold04: mtry=11
#> - Fold04: mtry=11
#> + Fold05: mtry= 2
#> - Fold05: mtry= 2
#> + Fold05: mtry= 6
#> - Fold05: mtry= 6
#> + Fold05: mtry=11
#> - Fold05: mtry=11
#> + Fold06: mtry= 2
#> - Fold06: mtry= 2
#> + Fold06: mtry= 6
#> - Fold06: mtry= 6
#> + Fold06: mtry=11
#> - Fold06: mtry=11
#> + Fold07: mtry= 2
#> - Fold07: mtry= 2
#> + Fold07: mtry= 6
#> - Fold07: mtry= 6
#> + Fold07: mtry=11
#> - Fold07: mtry=11
#> + Fold08: mtry= 2
#> - Fold08: mtry= 2
#> + Fold08: mtry= 6
#> - Fold08: mtry= 6
#> + Fold08: mtry=11
#> - Fold08: mtry=11
#> + Fold09: mtry= 2
#> - Fold09: mtry= 2
#> + Fold09: mtry= 6
#> - Fold09: mtry= 6
#> + Fold09: mtry=11
#> - Fold09: mtry=11
#> + Fold10: mtry= 2
#> - Fold10: mtry= 2
#> + Fold10: mtry= 6
#> - Fold10: mtry= 6
#> + Fold10: mtry=11
#> - Fold10: mtry=11
#> Aggregating results
#> Selecting tuning parameters
#> Fitting mtry = 2 on full training set
#> + Fold01: mtry= 2
#> - Fold01: mtry= 2
#> + Fold01: mtry= 6
#> - Fold01: mtry= 6
#> + Fold01: mtry=11
#> - Fold01: mtry=11
#> + Fold02: mtry= 2
#> - Fold02: mtry= 2
#> + Fold02: mtry= 6
#> - Fold02: mtry= 6
#> + Fold02: mtry=11
#> - Fold02: mtry=11
#> + Fold03: mtry= 2
#> - Fold03: mtry= 2
#> + Fold03: mtry= 6
#> - Fold03: mtry= 6
#> + Fold03: mtry=11
#> - Fold03: mtry=11
#> + Fold04: mtry= 2
#> - Fold04: mtry= 2
#> + Fold04: mtry= 6
#> - Fold04: mtry= 6
#> + Fold04: mtry=11
#> - Fold04: mtry=11
#> + Fold05: mtry= 2
#> - Fold05: mtry= 2
#> + Fold05: mtry= 6
#> - Fold05: mtry= 6
#> + Fold05: mtry=11
#> - Fold05: mtry=11
#> + Fold06: mtry= 2
#> - Fold06: mtry= 2
#> + Fold06: mtry= 6
#> - Fold06: mtry= 6
#> + Fold06: mtry=11
#> - Fold06: mtry=11
#> + Fold07: mtry= 2
#> - Fold07: mtry= 2
#> + Fold07: mtry= 6
#> - Fold07: mtry= 6
#> + Fold07: mtry=11
#> - Fold07: mtry=11
#> + Fold08: mtry= 2
#> - Fold08: mtry= 2
#> + Fold08: mtry= 6
#> - Fold08: mtry= 6
#> + Fold08: mtry=11
#> - Fold08: mtry=11
#> + Fold09: mtry= 2
#> - Fold09: mtry= 2
#> + Fold09: mtry= 6
#> - Fold09: mtry= 6
#> + Fold09: mtry=11
#> - Fold09: mtry=11
#> + Fold10: mtry= 2
#> - Fold10: mtry= 2
#> + Fold10: mtry= 6
#> - Fold10: mtry= 6
#> + Fold10: mtry=11
#> - Fold10: mtry=11
#> Aggregating results
#> Selecting tuning parameters
#> Fitting mtry = 2 on full training set
#> + Fold01: mtry= 2
#> - Fold01: mtry= 2
#> + Fold01: mtry= 6
#> - Fold01: mtry= 6
#> + Fold01: mtry=11
#> - Fold01: mtry=11
#> + Fold02: mtry= 2
#> - Fold02: mtry= 2
#> + Fold02: mtry= 6
#> - Fold02: mtry= 6
#> + Fold02: mtry=11
#> - Fold02: mtry=11
#> + Fold03: mtry= 2
#> - Fold03: mtry= 2
#> + Fold03: mtry= 6
#> - Fold03: mtry= 6
#> + Fold03: mtry=11
#> - Fold03: mtry=11
#> + Fold04: mtry= 2
#> - Fold04: mtry= 2
#> + Fold04: mtry= 6
#> - Fold04: mtry= 6
#> + Fold04: mtry=11
#> - Fold04: mtry=11
#> + Fold05: mtry= 2
#> - Fold05: mtry= 2
#> + Fold05: mtry= 6
#> - Fold05: mtry= 6
#> + Fold05: mtry=11
#> - Fold05: mtry=11
#> + Fold06: mtry= 2
#> - Fold06: mtry= 2
#> + Fold06: mtry= 6
#> - Fold06: mtry= 6
#> + Fold06: mtry=11
#> - Fold06: mtry=11
#> + Fold07: mtry= 2
#> - Fold07: mtry= 2
#> + Fold07: mtry= 6
#> - Fold07: mtry= 6
#> + Fold07: mtry=11
#> - Fold07: mtry=11
#> + Fold08: mtry= 2
#> - Fold08: mtry= 2
#> + Fold08: mtry= 6
#> - Fold08: mtry= 6
#> + Fold08: mtry=11
#> - Fold08: mtry=11
#> + Fold09: mtry= 2
#> - Fold09: mtry= 2
#> + Fold09: mtry= 6
#> - Fold09: mtry= 6
#> + Fold09: mtry=11
#> - Fold09: mtry=11
#> + Fold10: mtry= 2
#> - Fold10: mtry= 2
#> + Fold10: mtry= 6
#> - Fold10: mtry= 6
#> + Fold10: mtry=11
#> - Fold10: mtry=11
#> Aggregating results
#> Selecting tuning parameters
#> Fitting mtry = 2 on full training set
#> + Fold01: mtry= 2
#> - Fold01: mtry= 2
#> + Fold01: mtry= 6
#> - Fold01: mtry= 6
#> + Fold01: mtry=11
#> - Fold01: mtry=11
#> + Fold02: mtry= 2
#> - Fold02: mtry= 2
#> + Fold02: mtry= 6
#> - Fold02: mtry= 6
#> + Fold02: mtry=11
#> - Fold02: mtry=11
#> + Fold03: mtry= 2
#> - Fold03: mtry= 2
#> + Fold03: mtry= 6
#> - Fold03: mtry= 6
#> + Fold03: mtry=11
#> - Fold03: mtry=11
#> + Fold04: mtry= 2
#> - Fold04: mtry= 2
#> + Fold04: mtry= 6
#> - Fold04: mtry= 6
#> + Fold04: mtry=11
#> - Fold04: mtry=11
#> + Fold05: mtry= 2
#> - Fold05: mtry= 2
#> + Fold05: mtry= 6
#> - Fold05: mtry= 6
#> + Fold05: mtry=11
#> - Fold05: mtry=11
#> + Fold06: mtry= 2
#> - Fold06: mtry= 2
#> + Fold06: mtry= 6
#> - Fold06: mtry= 6
#> + Fold06: mtry=11
#> - Fold06: mtry=11
#> + Fold07: mtry= 2
#> - Fold07: mtry= 2
#> + Fold07: mtry= 6
#> - Fold07: mtry= 6
#> + Fold07: mtry=11
#> - Fold07: mtry=11
#> + Fold08: mtry= 2
#> - Fold08: mtry= 2
#> + Fold08: mtry= 6
#> - Fold08: mtry= 6
#> + Fold08: mtry=11
#> - Fold08: mtry=11
#> + Fold09: mtry= 2
#> - Fold09: mtry= 2
#> + Fold09: mtry= 6
#> - Fold09: mtry= 6
#> + Fold09: mtry=11
#> - Fold09: mtry=11
#> + Fold10: mtry= 2
#> - Fold10: mtry= 2
#> + Fold10: mtry= 6
#> - Fold10: mtry= 6
#> + Fold10: mtry=11
#> - Fold10: mtry=11
#> Aggregating results
#> Selecting tuning parameters
#> Fitting mtry = 2 on full training set
#> + Fold01: mtry= 2
#> - Fold01: mtry= 2
#> + Fold01: mtry= 6
#> - Fold01: mtry= 6
#> + Fold01: mtry=11
#> - Fold01: mtry=11
#> + Fold02: mtry= 2
#> - Fold02: mtry= 2
#> + Fold02: mtry= 6
#> - Fold02: mtry= 6
#> + Fold02: mtry=11
#> - Fold02: mtry=11
#> + Fold03: mtry= 2
#> - Fold03: mtry= 2
#> + Fold03: mtry= 6
#> - Fold03: mtry= 6
#> + Fold03: mtry=11
#> - Fold03: mtry=11
#> + Fold04: mtry= 2
#> - Fold04: mtry= 2
#> + Fold04: mtry= 6
#> - Fold04: mtry= 6
#> + Fold04: mtry=11
#> - Fold04: mtry=11
#> + Fold05: mtry= 2
#> - Fold05: mtry= 2
#> + Fold05: mtry= 6
#> - Fold05: mtry= 6
#> + Fold05: mtry=11
#> - Fold05: mtry=11
#> + Fold06: mtry= 2
#> - Fold06: mtry= 2
#> + Fold06: mtry= 6
#> - Fold06: mtry= 6
#> + Fold06: mtry=11
#> - Fold06: mtry=11
#> + Fold07: mtry= 2
#> - Fold07: mtry= 2
#> + Fold07: mtry= 6
#> - Fold07: mtry= 6
#> + Fold07: mtry=11
#> - Fold07: mtry=11
#> + Fold08: mtry= 2
#> - Fold08: mtry= 2
#> + Fold08: mtry= 6
#> - Fold08: mtry= 6
#> + Fold08: mtry=11
#> - Fold08: mtry=11
#> + Fold09: mtry= 2
#> - Fold09: mtry= 2
#> + Fold09: mtry= 6
#> - Fold09: mtry= 6
#> + Fold09: mtry=11
#> - Fold09: mtry=11
#> + Fold10: mtry= 2
#> - Fold10: mtry= 2
#> + Fold10: mtry= 6
#> - Fold10: mtry= 6
#> + Fold10: mtry=11
#> - Fold10: mtry=11
#> Aggregating results
#> Selecting tuning parameters
#> Fitting mtry = 6 on full training set
#> + Fold01: mtry= 2
#> - Fold01: mtry= 2
#> + Fold01: mtry= 6
#> - Fold01: mtry= 6
#> + Fold01: mtry=11
#> - Fold01: mtry=11
#> + Fold02: mtry= 2
#> - Fold02: mtry= 2
#> + Fold02: mtry= 6
#> - Fold02: mtry= 6
#> + Fold02: mtry=11
#> - Fold02: mtry=11
#> + Fold03: mtry= 2
#> - Fold03: mtry= 2
#> + Fold03: mtry= 6
#> - Fold03: mtry= 6
#> + Fold03: mtry=11
#> - Fold03: mtry=11
#> + Fold04: mtry= 2
#> - Fold04: mtry= 2
#> + Fold04: mtry= 6
#> - Fold04: mtry= 6
#> + Fold04: mtry=11
#> - Fold04: mtry=11
#> + Fold05: mtry= 2
#> - Fold05: mtry= 2
#> + Fold05: mtry= 6
#> - Fold05: mtry= 6
#> + Fold05: mtry=11
#> - Fold05: mtry=11
#> + Fold06: mtry= 2
#> - Fold06: mtry= 2
#> + Fold06: mtry= 6
#> - Fold06: mtry= 6
#> + Fold06: mtry=11
#> - Fold06: mtry=11
#> + Fold07: mtry= 2
#> - Fold07: mtry= 2
#> + Fold07: mtry= 6
#> - Fold07: mtry= 6
#> + Fold07: mtry=11
#> - Fold07: mtry=11
#> + Fold08: mtry= 2
#> - Fold08: mtry= 2
#> + Fold08: mtry= 6
#> - Fold08: mtry= 6
#> + Fold08: mtry=11
#> - Fold08: mtry=11
#> + Fold09: mtry= 2
#> - Fold09: mtry= 2
#> + Fold09: mtry= 6
#> - Fold09: mtry= 6
#> + Fold09: mtry=11
#> - Fold09: mtry=11
#> + Fold10: mtry= 2
#> - Fold10: mtry= 2
#> + Fold10: mtry= 6
#> - Fold10: mtry= 6
#> + Fold10: mtry=11
#> - Fold10: mtry=11
#> Aggregating results
#> Selecting tuning parameters
#> Fitting mtry = 2 on full training set
#> + Fold01: mtry= 2
#> - Fold01: mtry= 2
#> + Fold01: mtry= 6
#> - Fold01: mtry= 6
#> + Fold01: mtry=11
#> - Fold01: mtry=11
#> + Fold02: mtry= 2
#> - Fold02: mtry= 2
#> + Fold02: mtry= 6
#> - Fold02: mtry= 6
#> + Fold02: mtry=11
#> - Fold02: mtry=11
#> + Fold03: mtry= 2
#> - Fold03: mtry= 2
#> + Fold03: mtry= 6
#> - Fold03: mtry= 6
#> + Fold03: mtry=11
#> - Fold03: mtry=11
#> + Fold04: mtry= 2
#> - Fold04: mtry= 2
#> + Fold04: mtry= 6
#> - Fold04: mtry= 6
#> + Fold04: mtry=11
#> - Fold04: mtry=11
#> + Fold05: mtry= 2
#> - Fold05: mtry= 2
#> + Fold05: mtry= 6
#> - Fold05: mtry= 6
#> + Fold05: mtry=11
#> - Fold05: mtry=11
#> + Fold06: mtry= 2
#> - Fold06: mtry= 2
#> + Fold06: mtry= 6
#> - Fold06: mtry= 6
#> + Fold06: mtry=11
#> - Fold06: mtry=11
#> + Fold07: mtry= 2
#> - Fold07: mtry= 2
#> + Fold07: mtry= 6
#> - Fold07: mtry= 6
#> + Fold07: mtry=11
#> - Fold07: mtry=11
#> + Fold08: mtry= 2
#> - Fold08: mtry= 2
#> + Fold08: mtry= 6
#> - Fold08: mtry= 6
#> + Fold08: mtry=11
#> - Fold08: mtry=11
#> + Fold09: mtry= 2
#> - Fold09: mtry= 2
#> + Fold09: mtry= 6
#> - Fold09: mtry= 6
#> + Fold09: mtry=11
#> - Fold09: mtry=11
#> + Fold10: mtry= 2
#> - Fold10: mtry= 2
#> + Fold10: mtry= 6
#> - Fold10: mtry= 6
#> + Fold10: mtry=11
#> - Fold10: mtry=11
#> Aggregating results
#> Selecting tuning parameters
#> Fitting mtry = 2 on full training set
#> + Fold01: mtry= 2
#> - Fold01: mtry= 2
#> + Fold01: mtry= 6
#> - Fold01: mtry= 6
#> + Fold01: mtry=11
#> - Fold01: mtry=11
#> + Fold02: mtry= 2
#> - Fold02: mtry= 2
#> + Fold02: mtry= 6
#> - Fold02: mtry= 6
#> + Fold02: mtry=11
#> - Fold02: mtry=11
#> + Fold03: mtry= 2
#> - Fold03: mtry= 2
#> + Fold03: mtry= 6
#> - Fold03: mtry= 6
#> + Fold03: mtry=11
#> - Fold03: mtry=11
#> + Fold04: mtry= 2
#> - Fold04: mtry= 2
#> + Fold04: mtry= 6
#> - Fold04: mtry= 6
#> + Fold04: mtry=11
#> - Fold04: mtry=11
#> + Fold05: mtry= 2
#> - Fold05: mtry= 2
#> + Fold05: mtry= 6
#> - Fold05: mtry= 6
#> + Fold05: mtry=11
#> - Fold05: mtry=11
#> + Fold06: mtry= 2
#> - Fold06: mtry= 2
#> + Fold06: mtry= 6
#> - Fold06: mtry= 6
#> + Fold06: mtry=11
#> - Fold06: mtry=11
#> + Fold07: mtry= 2
#> - Fold07: mtry= 2
#> + Fold07: mtry= 6
#> - Fold07: mtry= 6
#> + Fold07: mtry=11
#> - Fold07: mtry=11
#> + Fold08: mtry= 2
#> - Fold08: mtry= 2
#> + Fold08: mtry= 6
#> - Fold08: mtry= 6
#> + Fold08: mtry=11
#> - Fold08: mtry=11
#> + Fold09: mtry= 2
#> - Fold09: mtry= 2
#> + Fold09: mtry= 6
#> - Fold09: mtry= 6
#> + Fold09: mtry=11
#> - Fold09: mtry=11
#> + Fold10: mtry= 2
#> - Fold10: mtry= 2
#> + Fold10: mtry= 6
#> - Fold10: mtry= 6
#> + Fold10: mtry=11
#> - Fold10: mtry=11
#> Aggregating results
#> Selecting tuning parameters
#> Fitting mtry = 2 on full training set
#> + Fold01: mtry= 2
#> - Fold01: mtry= 2
#> + Fold01: mtry= 6
#> - Fold01: mtry= 6
#> + Fold01: mtry=11
#> - Fold01: mtry=11
#> + Fold02: mtry= 2
#> - Fold02: mtry= 2
#> + Fold02: mtry= 6
#> - Fold02: mtry= 6
#> + Fold02: mtry=11
#> - Fold02: mtry=11
#> + Fold03: mtry= 2
#> - Fold03: mtry= 2
#> + Fold03: mtry= 6
#> - Fold03: mtry= 6
#> + Fold03: mtry=11
#> - Fold03: mtry=11
#> + Fold04: mtry= 2
#> - Fold04: mtry= 2
#> + Fold04: mtry= 6
#> - Fold04: mtry= 6
#> + Fold04: mtry=11
#> - Fold04: mtry=11
#> + Fold05: mtry= 2
#> - Fold05: mtry= 2
#> + Fold05: mtry= 6
#> - Fold05: mtry= 6
#> + Fold05: mtry=11
#> - Fold05: mtry=11
#> + Fold06: mtry= 2
#> - Fold06: mtry= 2
#> + Fold06: mtry= 6
#> - Fold06: mtry= 6
#> + Fold06: mtry=11
#> - Fold06: mtry=11
#> + Fold07: mtry= 2
#> - Fold07: mtry= 2
#> + Fold07: mtry= 6
#> - Fold07: mtry= 6
#> + Fold07: mtry=11
#> - Fold07: mtry=11
#> + Fold08: mtry= 2
#> - Fold08: mtry= 2
#> + Fold08: mtry= 6
#> - Fold08: mtry= 6
#> + Fold08: mtry=11
#> - Fold08: mtry=11
#> + Fold09: mtry= 2
#> - Fold09: mtry= 2
#> + Fold09: mtry= 6
#> - Fold09: mtry= 6
#> + Fold09: mtry=11
#> - Fold09: mtry=11
#> + Fold10: mtry= 2
#> - Fold10: mtry= 2
#> + Fold10: mtry= 6
#> - Fold10: mtry= 6
#> + Fold10: mtry=11
#> - Fold10: mtry=11
#> Aggregating results
#> Selecting tuning parameters
#> Fitting mtry = 2 on full training set
Estimate_Models gives the results based on the splits of the
exog
. Combined_Performance prints out the total performance
of these splits.