Quantitative Analysis of “Prostate Cancer” Dataset Using R-Programming

Dr. O. Aly
Computer Science

Introduction

The purpose of this discussion is to use the prostate cancer dataset available in R, in which biopsy results are given for 97 men.  This goal is to predict tumor spread, which is the log volume in this dataset of 97 men who had undergone a biopsy. The measures which are used for prediction are BPH, PSA, Gleason Score, CP, and size of the prostate.  The predicted tumor size affects the treatment options for the patients, which can include chemotherapy, radiation treatment, and surgical removal of the prostate.  

The dataset “prostate.cancer.csv” is downloaded from the CTU course learning materials.  The dataset has 97 observations or patients on six variables. The response variable is the log volume (lcavol).  This assignment is to predict this variable (lcavol) from five covariates (age, logarithms of bph, cp, and PSA, and Gleason score) using the decision tree.  The response variable is a continuous measurement variable. The sum of squared residuals as the impurity (fitting) criterion is used in this analysis.

This assignment discusses and addresses fourteen Tasks as shown below:

Various resources were utilized to develop the required code using R. These resources include (Ahlemeyer-Stubbe & Coleman, 2014; Fischetti, Mayor, & Forte, 2017; Ledolter, 2013; r-project.org, 2018)

Task-1:  Understand the Variables of the Data Sets

The purpose of this task is to understand the variables of the dataset. The dataset has 97 observations or patients with six variables. The response variable for prediction is (lcavol), and the five covariates (age, logarithms of bph, cp, and PSA, and Gleason score) will be used for this prediction using the decision tree.  The response variable is a continuous measurement variable.  Table 1 summarizes these variables including the response variable of (lcavol).

Table 1:  Prostate Cancer Variables.

Task-2:  Load and Review the Dataset using names(), heads(), dim() functions

  • pc <- read.csv(“C:/CS871/prostate.cancer.csv”)
  • pc
  • dim(pc)
  • names(pc)
  • head(pc)
  • pc <- data.frame(pc)
  • head(pc)
  • str(pc)
  • pc <-data.frame(pc)
  • summary(pc)
  • plot(pc, col=”blue”, main=”Plot of Prostate Cancer”)

Figure 1. Plot of Prostate Variables.

Task-3:  Distribution of Prostate Cancer Variables.

  • #### Distribution of Prostate Cancel Variables
  • ### These are the variables names
  • colnames(pc)
  • ##Setup grid, margins.
  • par(mfrow=c(3,3), mar=c(4,4,2,0.5))
  • for (j in 1:ncol(pc))
  • {
  • hist(pc[,j], xlab=colnames(pc)[j],
  • main=paste(“Histogram of”, colnames(pc)[j]),
  • col=”blue”, breaks=20)
  • }
  • hist(pc$lcavol,col=”orange”)
  • hist(pc$age,col=”orange”)
  • hist(pc$lbph,col=”orange”)
  • hist(pc$lcp,col=”orange”)
  • hist(pc$gleason,col=”orange”)
  • hist(pc$lpsa,col=”orange”)

Figure 2.  Distribution of Prostate Cancer Variables.

Task-4:  Correlation Among Prostate Variables

  • ##Correlations between prostate cancer variables
  • pc.cor = cor(pc)
  • pc.cor <- round(pc.cor, 3)
  • summary(pc)
  • pc.cor[lower.tri(pc.cor,diag=TRUE)] = 0
  • pc.cor.sorted = sort(abs(pc.cor),decreasing=T)
  • pc.cor.sorted[1]
  • ##[1] 0.871
  • # Use arrayInd()
  • vars.big.cor = arrayInd(which(abs(pc.cor)==pc.cor.sorted[1]), dim(pc.cor))
  • colnames(pc)[vars.big.cor]
  • ##[1] “lcp”     “gleason”
  • pc.cor.sorted[2]
  • ## [[1] 0.812
  • vars.big.cor = arrayInd(which(abs(pc.cor)==pc.cor.sorted[2]), dim(pc.cor))
  • colnames(pc)[vars.big.cor]
  • ## [1] “lbph” “lcp”

Task-5:  Visualization of the Relationship and Correlation between the Cancer Spread (lcavol) and other Variables.

  • ## Visualizing relationships among varibles
  • plot(lcavol~age, data=pc, col=”red”, main=”Relationship of Age on the Cancer Volume (lcvol)”)
  • plot(lcavol~lbph, data=pc, col=”red”, main=”Relationship of Amount of Benign Prostatic Hyperplasia (lbph) on the Cancer Volume (lcavol)”)
  • plot(lcavol~lcp, data=pc, col=”red”, main=”Relationship of Capsular Penetration (lcp) on the Cancer Volume (lcvol)”)
  • plot(lcavol~gleason, data=pc, col=”red”, main=”Relationship of Gleason System (gleason) on the Cancer Volume (lcvol)”)
  • plot(lcavol~lpsa, data=pc, col=”red”,main=”Relationship of Prostate Specific Anitgen (lpsa) on the Cancer Volume (lcvol)”)

Figure 3.  Plot of Correlation Among Prostate Variables Using plot() Function.

  • ## Correlation among the variables using corrplot() function
  • install.packages(“ElemStatLearn”)
  • library(ElemStatLearn)           ## it contains the data
  • install.packages(“car”)
  • library(car)                   ## package to calculate variance inflation factor
  • install.packages(“corrplot”)
  • library(corrplot)                       ## correlation plots
  • install.packages(“leaps”)
  • library(leaps)               ## best subsets regression
  • install.packages(“glmnet”)
  • library(glmnet)                        ##allows ridge regression, LASSO and elastic net.
  • install.packages(“caret”)
  • library(caret)                ##parameter tuning
  • pc.cor=cor(pc)
  • corrplot.mixed(pc.cor)

Figure 4.  Plot of Correlation Among Prostate Variables Using corplot() Function.

Task-6:  Build a Decision Tree for Prediction

  • ##Building a Decision Tree for Prediction
  • install.packages(“tree”)
  • library(tree)
  • ##Construct the tree
  • pctree <- tree(lcavol ~., data=pc, mindev=0.1, mincut=1)
  • pctree <- tree(lcavol ~., data=pc,mincut=1)
  • pctree
  • plot(pctree, col=4)
  • text(pctree, digits=2)
  • pccut <- prune.tree(pctree, k=1.7)
  • plot(pccut, col=”red”, main=”Pruning Using k=1.7″)
  • pccut
  • text(pccut, digits=2)
  • pccut <- prune.tree(pccut, k=2.05)
  • plot(pccut, col=”darkgreen”, main=”Pruning Using k=2.05″)
  • pccut
  • text(pccut,digits=2)
  • pccut <- prune.tree(pctree,k=3)
  • plot(pccut, col=”orange”, main=”Pruning Using k=3″)
  • pccut
  • text(pccut,digits=2)
  • pccut <- prune.tree(pctree)
  • pccut
  • plot(pccut, col=”blue”, main=”Decision Tree Pruning”)
  • pccut <- prune.tree(pctree,best=3)
  • pccut
  • plot(pccut, col=”orange”, main=”Pruning Using best=3″)
  • text(pccut, digits=2)

Figure 5:  Initial Tree Development.

Figure 6:  First Pruning with α=1.7.

Figure 7:  Second Pruning with α=2.05.

Figure 8:  Third Pruning with α=3.

Figure 9:  Plot of the Decision Tree Pruning.

Figure 10.  Plot of the Final Tree.

Task-7:  Cross-Validation

  • ## Use cross-validation to prune the tree
  • set.seed(2)
  • cvpc <- cv.tree(pctree, k=10)
  • cvpc$size
  • cvpc$dev
  • plot(cvpc, pch=21, bg=8, type=”p”, cex=1.5, ylim=c(65,100), col=”blue”)
  • pccut <- prune.tree(pctree, best=3)
  • pccut
  • plot(pccut, col=”red”)
  • text(pccut)
  • ## Final Plot
  • plot(pc[,c(“lcp”,”lpsa”)],col=”red”,cex=0.2*exp(pc$lcavol))
  • abline(v=.261624, col=4, lwd=2)
  • lines(x=c(-2,.261624), y=c(2.30257,2.30257), col=4, lwd=2)

Figure 13.  Plot of the Cross-Validation Deviance.

Figure 14.  Plot of the Final Classification Tree.

Figure 15.  Plots of Cross-Validation.

Task-8:  Discussion and Analysis

The classification and regression tree (CART) represents a nonparametric technique which generalizes parametric regression models (Ledolter, 2013).  It allows for non-linearity and variables interactions with no need to specify the structure in advance. Furthermore, the violation of constant variance which represents a critical assumption in the regression model is not critical in this technique (Ledolter, 2013).

The descriptive statistics result shows that lcavol has a mean of 1.35 which is less than the median of 1.45 indicating a negatively skewed distribution, with a minimum of -1.35 and a maximum of 2.8. The age of the prostate cancer patients has an average of 64 years, with a minimum of 41 and a maximum of 79 years old.  The lbph has an average of 0.1004 which is less than the median of 0.300 indicating the same negatively skewed distribution with a minimum of -1.39 and maximum of 2.33.  The lcp has an average of -0.18 which is higher than the median of -0.79 indicating a positive skewed distribution with a minimum of -1.39 and a maximum of 2.9.  The Gleason measure has a mean of 6.8 which is a little less than the median of 7 indicating a little negative skewed distribution with a minimum of 6 and maximum of 9.  The last variable of lpsa has an average of 2.48 which is a little less than the median of 2.59 indicating a little negatively skewed distribution with a minimum of -0.43 and maximum of 5.58. The result shows that there is a positive correlation between lpsa and lcavol, and between lcp and lcavol as well.  The result also shows that the age between 60 and 70 the lcavol gets increased.

Furthermore, the result also shows that the Gleason result takes integer values of 6 and larger. The result of the lspa shows that the log PSA score, is close to the normally distributed dataset.  The result in Task-4 of the correlation among prostate variables is not surprising as it shows that if their Gleason score is high now, then they likely had a bad history of Gleason scores, which is known for such high Gleason.  The result also shows that lcavol as a predictor should be included for any prediction of the lpsa.

As illustrated in Figure 4, the result shows that PSA is highly correlated with the log of cancer volume (lcavol); it appeared to have a highly linear relationship.  The result also shows that multicollinearity may become an issue; for example, cancer volume is also correlated with capsular penetration, and this is correlated with the seminal vesicle invasion.

For the implementation of the Tree, the initial tree has 12 leave nodes, and the size of the tree is thus 12 as illustrated in Figure 5.  The root shows the 97 cases with deviance of 133.4. Node 1 is the root; Node 2 has a value of lcp < 0.26 with 63 patients and deviance of 64.11.  Node 3 has the value of lcp > 0.26 with 34 cases and deviance of 13.39.  Node 4 has the lpsa < 2.30 with 35 cases and deviance of 24.72. Node 5 has lpsa > 2.30 with 28 cases and 18.6 deviance. Node 6 has lcp < 2.14 with 25 cases and deviance of 6.662.  Node 7 has lcp > 2.139 with 9 cases and deviance of 1.48. Node 8 has lpsa < 0.11 with 4 cases and deviance of 0.3311, while Node 9 has lpsa > 0.11 with 31 cases and deviance of 18.92, and age of < 52 with deviance of 0.12 and age o > 52 with deviance of 13.88. Node 10 has lpsa < 3.25 with 23 cases and deviance of 11.61. while Node 11 has lcp > 3.25 with 5 cases and deviance of 1.76.  Node 12 is for age < 62 with 7 cases and deviance of 0.73.

The first pruning process using α=1.7 did not result in any different from the initial tree.  It resulted in the 12 nodes.  The second pruning with α=2.05 improved the tree with eight nodes.  The root shows the same result of 97 cases with deviance of 133.4.  Node 1 has lcp < 0.26 with deviance of 64.11 while Node 2 has lcp > 0.26 with deviance of 13.39.  The third pruning using α=3 has further improved the tree as shown in Figure 8.  The final Tree has the root with four nodes: Node 1 for lcp < 0.26 and Node 2 for lcp > 0.26.  Node 3 has lpsa < 2.30, while Node 4 reflects lpsa > 2.30.  With regard to the prediction, the patient with lcp=0.20, which is categorized in Node 2, and lpsa of 2.40 which is categorized in Node 4, can be predicted to have a log volume of (lcavol) of 1.20.

The biggest challenge for the CART model which is described as flexible, in comparison to the regression models, is the overfitting (Giudici, 2005; Ledolter, 2013).  If the splitting algorithm is not stopped, the tree algorithm can ultimately extract all information from the data, including information which is not and cannot be predicted in the population with the current set of prediction causing random or noise variation (Ledolter, 2013).   However, when the subsequent splits add minimal improvement of the prediction, the stop of generating new split nodes, in this case, can be used as a defense against the overfitting issue.  Thus, if 90% of all cases can be predicted correctly from 10 splits, and 90.1% of all cases from 11 splits, then, there is no need to add the 11th split to the tree, as it does not add much value only .1%. There are various techniques to stop the split process.  The basic constraints (mincut, mindev) lead to a full tree fit with a certain number of terminal nodes.  In this case of the prostate analysis, the mincut=1 is used which is a minimum number of observations to include in a child node and obtained a tree of size 12.

Since the three-building is stopped as illustrated in Figure 10, the cross-validation is used to evaluate the quality of the prediction of the current tree.  The cross-validation subjects the tree computed from one set of observation (the training sample) to another independent set of observation (the test sample). If most or all of the splits determined by the analysis of the training sample are based on random noise, then the prediction for the test sample is described to be poor.  The cross-validation cost or CV cost is the averaged error rate for particular tree size.  The tree size which produces the minimum CV cost is found.  The reference tree is then pruned back to the number of nodes matching the size which produces the minimum CV cost.  Pruning was implemented in a stepwise bottom-up manner, by removing the least important nodes during each pruning cycle. The v-fold CV is implemented with the R command (cv.tree). The graph in Figure 13 of the CV Deviance indicates that, for the prostate example, a tree of size 3 is appropriate.  Thus, the reference tree which was obtained from all the data is being pruned back to size 3. CV chooses the capsular penetration and PSA as the decision variable.  The effect of capsular penetration on the response of log volume (lcavol) depends on PSA. The final graph of Figure 15 shows that the CAR divides up the space of the explanatory variables into rectangles, with each rectangle leading to a different prediction. The size of the circles of the data points in the respective rectangles reflects the magnitude of the response.  Figure 15 confirms that the tree splits are quite reasonable.

References

Ahlemeyer-Stubbe, A., & Coleman, S. (2014). A practical guide to data mining for business and industry: John Wiley & Sons.

Fischetti, T., Mayor, E., & Forte, R. M. (2017). R: Predictive Analysis: Packt Publishing.

Giudici, P. (2005). Applied data mining: statistical methods for business and industry: John Wiley & Sons.

Ledolter, J. (2013). Data mining and business analytics with R: John Wiley & Sons.

r-project.org. (2018). R: A Language and Environment for Statistical Computing. Retrieved from https://cran.r-project.org/doc/manuals/r-release/fullrefman.pdf.

Analysis of Ensembles

Dr. O. Aly
Computer Science

Introduction

The purpose of this discussion is to discuss and analyze creating ensembles from different methods such as logistic regression, nearest neighbor methods, classification trees, Bayesian, or discriminant analysis. This discussion also addresses the use of the Random Forest to do the analysis.

Ensembles

There are two useful techniques which combine methods for improving predictive power: ensembles and uplift modeling.  Ensembles are the focus of this discussion. Thus, uplift modeling is not discussed in this discussion.  An ensemble combines multiple “supervised” models into a “super-model” (Shmueli, Bruce, Patel, Yahav, & Lichtendahl Jr, 2017)).  An ensemble is based on the dominant notion of combining models (EMC, 2015; Shmueli et al., 2017). Thus, several models can be combined to achieve improved predictive accuracy (Shmueli et al., 2017). 

Ensembles played a significant role in the million-dollar Netflix Prize contest which started in 2006 to improve their movie recommendation system (Shmueli et al., 2017).  The principle of combining methods is known for reducing risk because the variation is smaller than each of the individual components (Shmueli et al., 2017).  The risk is equivalent to a variation in prediction error in predictive modeling.  The more the prediction errors vary, the more volatile the predictive model (Shmueli et al., 2017).  Using an average of two predictions can potentially result in smaller error variance, and therefore, better predictive power (Shmueli et al., 2017).  Thus, results can be combined from multiple prediction methods or classifiers (Shmueli et al., 2017).  The combination can be implemented for predictions, classifications, and propensities as discussed below. 

Ensembles Combining Prediction Using Average Method

When combining prediction, the predictions can be combined with different methods by taking an average.  One alternative to a simple average is taking the median prediction, which would be less affected by extreme predictions (Shmueli et al., 2017). Computing a weighted average is another possibility where the weights are proportional to a quantity of interest such as quality or accuracy (Shmueli et al., 2017).  Ensembles for prediction are useful not only in cross-sectional prediction but also in time series forecasting (Shmueli et al., 2017).

Ensembles Combining Classification Using Voting Method

When combining classification, combining the results from multiple classifiers can be implemented using “voting,” for each record, multiple classifications are available.  A simple rule would be to choose the most popular class among these classifications (Shmueli et al., 2017). For instance, Classification Tree, a Naïve Bayes classifier, and discriminant analysis can be used for classifying a binary outcome (Shmueli et al., 2017).  For each record, three predicted classes are generated (Shmueli et al., 2017). Simple voting would choose the most common class of the three (Shmueli et al., 2017). Similar to the prediction, heavier weights can be assigned to scores from some models, based on considerations such as model accuracy or data quality, which can be implemented by setting a “majority rule” which is different from 50% (Shmueli et al., 2017).   Concerning the nearest neighbor (K-NN), an ensemble learning such as bagging can be performed with K-NN (Dubitzky, 2008). The individual decisions are combined to classify new examples.  Combining of individual results is performed by weighted or unweighted voting (Dubitzky, 2008).

Ensembles Combining Propensities Using Average Method

Similar to prediction, propensities can be combined by taking a simple or weighted average.  Some algorithms such as Naïve Bayes produce biased propensities and should not, therefore, be averaged with propensities from other methods (Shmueli et al., 2017).

Other Forms of Ensembles

Various methods are commonly used for classification, including bagging, boosting, random forest, and support vector machines (SVM).  The bagging, boosting, and random forest is all examples of ensemble methods which use multiple models to obtain better predictive performance than can be obtained from any of the constituent models (EMC, 2015; Ledolter, 2013; Shmueli et al., 2017).

  • Bagging: It is short for “bootstrap aggregating” (Ledolter, 2013; Shmueli et al., 2017). It was proposed by Leo Breiman in 1994, which is a model aggregation technique to reduce model variance (Swamynathan, 2017).  It is another form of Ensembles which is based on averaging across multiple random data samples (Shmueli et al., 2017).  There are two steps to implement bagging.  Figure 1illustrates the bagging process flow.
    • Generate multiple random samples by sampling “with replacement from the original data.”  This method is called “bootstrap sampling.”
    • Running an algorithm on each sample and producing scores (Shmueli et al., 2017).

Figure 1.  Bagging Process Flow (Swamynathan, 2017).

Bagging improves the performance stability of a model and helps avoid overfitting by separately modeling different data samples and then combining the result.  Thus, it is especially useful for algorithms such as Trees and Neural Networks.  Figure 2 illustrates an example of the bootstrap sample that has the same size as the original sample size, with ¾ of the original values plus replacement result in repetition of values.

Figure 2:  Bagging Example (Swamynathan, 2017).

Boosting: It is a slightly different method of creating ensembles.  It was introduced by Freud and Schapire in 1995 using the well-known AdaBoost algorithm (adaptive boosting) (Swamynathan, 2017).  The underlying concept of boosting is that rather than an independent individual hypothesis, combining hypotheses in a sequential order increases the accuracy (Swamynathan, 2017).  The boosting algorithms convert the “weak learners” into “strong learners” (Swamynathan, 2017).  Boosting algorithms are well designed to address the bias problems (Swamynathan, 2017). Boosting tends to increase the accuracy (Ledolter, 2013). The “AdaBoosting” process involves three steps. Figure 3 illustrates the “AdaBoosting” process:

  1. Assign uniform weight for all data points W0(x)=1/N, where N is the total number of training data points.
    1. At each iteration fit a classifier ym(xn) to the training data and update weights to minimize the weighted error function.
  • The final model is given by the following equation:

Figure 3.  “AdaBoosting” Process (Swamynathan, 2017).

            As an example illustration of AdaBoost, there is a sample dataset with 10 data points, with an assumption that all data points will have equal weights giving by, 1/10 as illustrated in Figure 4. 

Figure 4.  An Example Illustration of AdaBoost. Final Model After Three Iteration (Swamynathan, 2017).

  • Random Forest: It is another class of ensemble method using decision tree classifiers.  It is a combination of tree predictors such that each tree depends on the values of a random vector sampled independently and with the same distribution for all trees in the forest. A particular case of random forest uses bagging on decision trees, where samples are randomly chosen with replacement from the original training set (EMC, 2015).
  • SVM: Itis another common classification method which combines linear models with instance-based learning techniques. The SVM select a small number of critical boundary instances called support vectors from each class and build a linear decision function which separates them as widely as possible.  SVM can efficiently perform, by default linear classifications and can also be configured to perform non-linear classifications (EMC, 2015).

Advantages and Limitations of Ensembles

Combining scores from multiple models is aimed at generating more precise predictions by lowering the prediction error variance (Shmueli et al., 2017).  The ensemble method is most useful when the combined models generate prediction error which is negatively associated or correlated, but it can also be useful when the correlation is low (Ledolter, 2013; Shmueli et al., 2017).  Ensembles can use simple averaging, weighted averaging, voting, and median (Ledolter, 2013; Shmueli et al., 2017).  Models can be based on the same algorithm or different algorithms, using the same sample or different sample (Ledolter, 2013; Shmueli et al., 2017).  Ensembles have become an important strategy for participants in data mining contests, where the goal is to optimize some predictive measure (Ledolter, 2013; Shmueli et al., 2017).  Ensembles which are based on different data samples help avoid overfitting. However, overfit can also happen with an ensemble in instances such as the choice of best weights when using a weighted average (Shmueli et al., 2017).   

The primary limitation of the ensemble is the resources which it requires such as computationally, and the skills and time investments (Shmueli et al., 2017).  Ensembles which combine results from different algorithms require the development of each model and their evaluation.  The boosting-type ensembles and bagging-type ensembles do not require much effort. However, they do have a computational cost.  Furthermore, ensembles which rely on multiple data sources require the collection and the maintenance of the multiple data sources (Shmueli et al., 2017).  Ensembles are regarded to be “black box” methods, where the relationship between the predictors and the outcome variable usually becomes non-transparent (Shmueli et al., 2017). 

The Use of Random Forests for Analysis

The decision tree is based on a set of True/False decision rules. The prediction is based on the tree rules for each terminal node.  A decision tree for a small set of sample training data encounters the overfitting problem. Random forest model, in contrast, is well suited to handle small sample size problems.  The random forest contains multiple decision trees as the more trees, the better.  Randomness is in selecting the random training subset from the training dataset, using bootstrap aggregating or bagging method to reduce the overfitting by stabilizing the predictions. This method is utilized in many other machine-learning algorithms, not only in the Random Forests (Hodeghatta & Nayak, 2016). There is another type of randomness which occurs when selecting variables randomly from the set of variables, resulting in different trees which are based on different sets of variables.  In a forest, all the trees would still influence the overall prediction by the random forest (Hodeghatta & Nayak, 2016).

The programming logic for Random Forest includes seven steps as follows (Azhad & Rao, 2011).

  1. Input the number of training set N.
  2. Compute the number of attributes M.
  3. For (m) input attributes used to form the decision at a node m<M.
  4. Choose training set by sampling with replacement.
  5. For each node of the tree, use one of the (m) variables as the decision node.
  6. Grow each tree without pruning.
  7. Select the classification with maximum votes.

Random Forests have a low bias (Hodeghatta & Nayak, 2016).  The variance is reduced, and thus, overfitting, by adding more trees, which is one of the advantages of the Random Forests, and hence gaining popularity.  The models of Random Forests are relatively robust to the set of input variables and often do not care about pre-processing of data.  Random Forests are described to be more efficient to build than other models such as SVM (Hodeghatta & Nayak, 2016).  Table 1 summarizes the Advantages and Disadvantages of Random Forests in a comparison with other Classification Algorithms such as Naïve Bayes, Decision Tree, Nearest Neighbor. 

Table 1.  Advantages and Disadvantages of Random Forest in comparison with other Classification Algorithms. Adapted from (Hodeghatta & Nayak, 2016).

References

Azhad, S., & Rao, M. S. (2011). Ensuring data storage security in cloud computing.

Dubitzky, W. (2008). Data Mining in Grid Computing Environments: John Wiley & Sons.

EMC. (2015). Data Science and Big Data Analytics: Discovering, Analyzing, Visualizing and Presenting Data. (1st ed.): Wiley.

Hodeghatta, U. R., & Nayak, U. (2016). Business Analytics Using R-A Practical Approach: Springer.

Ledolter, J. (2013). Data mining and business analytics with R: John Wiley & Sons.

Shmueli, G., Bruce, P. C., Patel, N. R., Yahav, I., & Lichtendahl Jr, K. C. (2017). Data mining for business analytics: concepts, techniques, and applications in R: John Wiley & Sons.

Swamynathan, M. (2017). Mastering Machine Learning with Python in Six Steps: A Practical Implementation Guide to Predictive Data Analytics Using Python: Apress.

Decision Trees with a Comparison of Classification and Regression Decision Tree (CART)

Dr. O. Aly
Computer Science

Introduction

The purpose of this discussion is to discuss and analyze Decision Trees, with a comparison of Classification and Regression Decision Trees.  The discussion also addresses the advantages and disadvantages of the Decision Trees.  The focus of this discussion is on the Classification and Regression Tree (CART) algorithm as one of the statistical criteria. The discussion begins with a brief overview of the Classification, followed by additional related topics.  It will end with a sample Decision Tree for a decision whether or not to take an umbrella.

Classification

Classification is a fundamental data mining technique (EMC, 2015).  Most classification methods are supervised, in which they start with a training set of pre-labeled observations to learn how likely the attributes of these observations may contribute to the classification of future unlabeled observations (EMC, 2015).  For instance, marketing, sales, and customer demographic data can be used to develop a classifier to assign a “purchase” or “no purchase” label to potential future customers (EMC, 2015).  Classification is widely used for prediction purposes (EMC, 2015).  Logistic Regression is one of the popular classification methods (EMC, 2015).  Classification can be used for health care professionals to diagnose diseases such as heart disease (EMC, 2015).   There are two fundamental classification methods:  Decision Trees and Naïve Bayes.  In this discussion, the focus is on the Decision Trees. 

The Tree Models vs. Linear & Logistic Regression Models

The tree models are distinguished from the Linear and Logistic Regression models.  The tree models produce a classification of observations into groups first and then obtain a score for each group, while the Linear and Logistic Regression methods produce a score and then possibly a classification based on a discriminant rule (Giudici, 2005). 

Regression Trees vs. Classification Trees

The tree models are divided into regression trees and classification trees (Giudici, 2005).  The regression trees are used when the response variable is continuous, while the classification trees are used when the response variable is quantitative discrete or qualitative (categorical) (Giudici, 2005).  The tree models can be defined as a recursive process, through which a set of (n) statistical units are divided into groups progressively, based on a division rule aiming to increase a homogeneity or purity measure of the response variable in each of the obtained group (Giudici, 2005). An explanatory variable specifies a division rule at each step of the procedure, to split and establish splitting rules to partition the observations (Giudici, 2005). The final partition of the observation is the main result of a tree model (Giudici, 2005).  It is critical to specify a “stopping criteria” for the division process to achieve such a result (Giudici, 2005). 

Concerning the classification tree, fitted values are given regarding the fitted probabilities of affiliation to a single group (Giudici, 2005). A discriminant rule for the classification trees can be derived at each leaf of the tree (Giudici, 2005).  The classification of all observations belonging to a terminal node in the class corresponding to the most frequent level is a commonly used rule, called “majority rule” (Giudici, 2005).  While other “voting” schemes can also be implemented, in the absence of other consideration, this rule is the most reasonable (Giudici, 2005).  Thus, each of the leaves points out a clear allocation rule of the observation, which is read using the path that connects the initial node to each of them.  Therefore, every path in the tree model represents a classification rule (Giudici, 2005).  

With comparison to other discriminant models, the tree models produce rules which are less explicit analytically, and easier to understand graphically (Giudici, 2005). The tree models can be regarded as nonparametric predictive models as they do not require assumptions about the probability distribution of the response variable (Giudici, 2005).  This flexibility indicates that the tree models are generally applicable, whatever the nature of the dependent variable and the explanatory variables  (Giudici, 2005).  However, the disadvantages of this flexibility of a higher demand of computational resources, and their sequential nature and the complexity of their algorithm can make them dependent on the observed data, and even a small change might alter the structure of the tree  (Giudici, 2005). Thus, it is difficult to take a tree structure designed for one context and generalize it to other contexts  (Giudici, 2005).

The Classification Tree Analysis vs. The Hierarchical Cluster Analysis

The classification tree analysis is distinguished from the hierarchical cluster analysis despite their graphical similarities  (Giudici, 2005).  The classification trees are predictive rather than descriptive. While the hierarchical cluster analysis performs an unsupervised classification of the observations based on all available variables, the classification trees perform a classification of the observations based on all explanatory variables and supervised by the presence of the response variable (target variable) (Giudici, 2005).  The second critical difference between the hierarchical cluster analysis and the classification tree analysis is related to the partition rule.  While in the classification trees the segmentation is typically carried out using only one explanatory variable at a time, in the hierarchical clustering the divisive or agglomerative rule between groups is established based on the considerations on the distance between them, calculated using all the available variables  (Giudici, 2005).

Decision Trees Algorithms

The goal of Decision Trees is to extract from the training data the succession of decisions about the attributes that explain the best class, that is, group membership (Fischetti, Mayor, & Forte, 2017).  Decision Trees have a root, which is the best attribute to split the data upon, about the outcome (Fischetti et al., 2017).  The dataset is partitioned into branches by this attribute (Fischetti et al., 2017).  The branches lead to other nodes which correspond to the next best partition for the considered branch (Fischetti et al., 2017).  The process continues until the terminal nodes are reached, where no more partitioning is required (Fischetti et al., 2017).   Decision Trees allow class predictions (group membership) of previously unseen observations (testing datasets or prediction datasets) using statistical criteria applied on the seen data (training dataset) (Fischetti et al., 2017).  There are six statistical criteria of six algorithms:

  • ID3
  • C4.5
  • Random Forest.
  • Conditional Inference Trees.
  • Classification and Regress Trees (CART)

The most used algorithm in the statistical community is the CART algorithm, while C4.5 and its latest version C5.0 are widely used by computer scientists (Giudici, 2005).  The first versions of C4.5 and 5.0 were limited to categorical predictors, but the most recent versions are similar to CART (Giudici, 2005).  

Classification and Regression Trees (CART)

CART is often used as a generic acronym for the decision tree, although it is a specific implementation of tree models (EMC, 2015).  CART, similar to C4.5, can handle continuous attributes (EMC, 2015).  While C4.5 uses entropy-based criteria to rank tests, CART uses the Gini diversity index defined in equation (1) (EMC, 2015; Fischetti et al., 2017).

Moreover, while C4.5 uses stopping rules, CART construct a sequence of subtrees, uses cross-validation to estimate the misclassification cost of each subtree, and chooses the one with the lowest cost, (EMC, 2015; Hand, Mannila, & Smyth, 2001). CART represents a powerful nonparametric technique which generalizes parametric regression models (Ledolter, 2013).  It allows nonlinearity and variable interactions without having to specify the structure in advance (Ledolter, 2013).  It operates by choosing the best variable for splitting the data into two groups at the root node (Hand et al., 2001).  It builds the tree using a single variable at a time, and can readily deal with large numbers of variables (Hand et al., 2001).  It uses different statistical criteria to decide on tree splits (Fischetti et al., 2017).  There are some differences between CART used for classification and the family of algorithms.  In CART, the attribute to be partition is selected with the Gini index as a decision criterion (Fischetti et al., 2017).  This method is described as more efficient compared to the information gain and information ratio (Fischetti et al., 2017).  CART implements the necessary partitioning on the modalities of the attribute and merges modalities for the partition, such as modality A versus modalities B and C (Fischetti et al., 2017).  The CART can predict a numeric outcome (Fischetti et al., 2017).  In the case of regression trees, CART performs regression and builds the tree in a way which minimizes the squared residuals (Fischetti et al., 2017). 

CART Algorithms of Division Criteria and Pruning

There are two critical aspects of the CART algorithm:  Division Criteria, and Pruning, which can be employed to reduce the complexity of a tree (Giudici, 2005).  Concerning the division criteria algorithm, the primary essential element of a tree model is to choose the division rule for the units belonging to a group, corresponding to a node of the tree (Giudici, 2005).  The decision rule selection means a predictor selection from those available, and the selection of the best partition of its levels (Giudici, 2005).  The selection is generally made using a goodness measure of the corresponding division rule, which allows the determination of the rule to maximize the goodness measure at each stage of the procedure (Giudici, 2005). 

The impurity concept refers to a measure of variability of the response values of the observations (Giudici, 2005).  In a regression tree, a node will be pure if it has null variance as all observations are equal, and it will be impure if the variance of the observation is high (Giudici, 2005).  For the regression trees, the impurity corresponds to the variance, while for the classification trees alternative measures for the impurity are considered such as Misclassification impurity, Gini impurity, Entropy impurity, and Tree assessments (Giudici, 2005).  

When there is no “stopping criterion,” a tree model can grow until each node contains identical observation regarding the values or levels of the dependent variable  (Giudici, 2005). This approach does not contain a parsimonious segmentation  (Giudici, 2005). Thus, it is critical to stop the growth of the tree at a reasonable dimension  (Giudici, 2005). The tree configuration becomes ideal when it is parsimonious and accurate  (Giudici, 2005). The parsimonious attribute indicates that the tree has a small number of leaves, and therefore, the predictive rule can be easily interpreted  (Giudici, 2005). The accurate attribute indicates a large number of leaves which are pure to a maximum extent  (Giudici, 2005). There are two opposing techniques for the final choice which tree algorithms can employ. The first technique uses stopping rules based on the thresholds on the number of the leaves, or on the maximum number of steps in the process, whereas the other algorithm technique introduces probabilistic assumptions on the variables, allowing the use of suitable statistical tests  (Giudici, 2005). The growth is stopped when the decrease in impurity is too small, in the absence of the probabilistic assumptions  (Giudici, 2005). The result of a tree model can be influenced by the choice of the stopping rule (Giudici, 2005). 

The CART method utilizes a strategy different from the stepwise stopping criteria. The method is based on the pruning concept.  The tree, first, is built to its greatest size, and it then gets “trimmed” or “pruned” according to a cost-complexity criterion  (Giudici, 2005). The concept of pruning is to find a subtree optimally, to minimize a loss function, which is used by CART algorithm and depends on the total impurity of the tree and the tree complexity  (Giudici, 2005). The misclassification impurity is usually chosen to be used for the pruning, although the other impurity methods can also be used.  The minimization of the loss function results in a compromise between choosing a complex model with low impurity but high complexity cost and choosing a simple model with a high impurity with low complexity cost  (Giudici, 2005).   The loss function is assessed by measuring the complexity of the model fitted on the training dataset, whose misclassification errors are measured in the validation data set  (Giudici, 2005).  This method partitions the training data into a subset for building the tree and then estimates the misclassification rate on the remaining validation subset (Hand et al., 2001).

The CART has been widely used for several years by marketing applications and others (Hodeghatta & Nayak, 2016).   The CART is described as a flexible model as the violations of constant variance which is very critical in regression, is permissible in the CART (Ledolter, 2013).  However, the biggest challenge in the CART is the avoidance of the “overfitting” (Ledolter, 2013).

Advantages and Disadvantages of the Trees

Decision trees for regression and classification have advantages and disadvantages.  Trees are regarded to be easier than linear regression and can be displayed graphically and interpreted easily (Cristina, 2010; Tibshirani, James, Witten, & Hastie, 2013).  Decision trees are self-explanatory and easy to understand even for non-technical users (Cristina, 2010; Tibshirani et al., 2013). They can handle qualitative predictors without the need to create dummy variables (Tibshirani et al., 2013).  Decision trees are efficient. Complex alternatives can be expressed quickly and precisely. A decision tree can easily be modified as new information becomes available.  Standard decision tree notation is easy to adopt (Cristina, 2010).  They can be used in conjunction with other management tools.  Decision trees can handle both nominal and numerical attributes (Cristina, 2010).  They are capable of handling datasets which may have errors or missing values.  Decision trees are considered to be a non-parametric method, which means that they have no assumption about the spatial distribution and the classifier structure.  Their representations are rich enough to represent any discrete-value classifier.

However, trees have limitations as well.  They do not have the same level of predictive accuracy as some of the other regression and classification models (Tibshirani et al., 2013). Most of the algorithms, like ID3 and C4.5, require that the target attribute will have only discrete values. Decision trees are over-sensitive to the training set, to irrelevant attributes and noise. Decision trees tend to perform less if many complex interactions are present, and well if a few highly relevant attributes exist as they use the “divide and conquer” method (Cristina, 2010).  Table 1 summarizes the advantages and disadvantages of the trees.

Table 1.  Summary of the Advantages and Disadvantages of Trees.
Note:  Constructed by the researcher based on the literature.

Take an Umbrella Decision Tree Example:

  • If input field value < n
    • Then target = Y%
  • If input field value > n
    • Then target = X%

Figure 1.  Decision Tree for Taking an Umbrella

  • The decision depends on the weather, on the predicted rain probability, and whether it is sunny or cloudy.
  • The forecast predicts rain with a probability between 70% and 30%.
    • If it is >70% rain probability, take an umbrella, else use >30% and <30% probability for further predictions.
    • If it is >30% rain probability and cloudy, take an umbrella, else no umbrella.
    • If it is <30% rain probability, no umbrella.

References

Cristina, P. (2010). Decision Trees. Retrieved from http://www.cs.ubbcluj.ro/~gabis/DocDiplome/DT/DecisionTrees.pdf.

EMC. (2015). Data Science and Big Data Analytics: Discovering, Analyzing, Visualizing and Presenting Data. (1st ed.): Wiley.

Fischetti, T., Mayor, E., & Forte, R. M. (2017). R: Predictive Analysis: Packt Publishing.

Giudici, P. (2005). Applied data mining: statistical methods for business and industry: John Wiley & Sons.

Hand, D. J., Mannila, H., & Smyth, P. (2001). Principles of data mining.

Hodeghatta, U. R., & Nayak, U. (2016). Business Analytics Using R-A Practical Approach: Springer.

Ledolter, J. (2013). Data mining and business analytics with R: John Wiley & Sons.

Tibshirani, R., James, G., Witten, D., & Hastie, T. (2013). An introduction to statistical learning-with applications in R: New York, NY: Springer.

Quantitative Analysis of the “Flight-Delays” Dataset Using R-Programming

Dr. O. Aly
Computer Science

Abstract

The purpose of this project is to analyze the flight delays Dataset. The project is divided into two main Parts.  Part-I evaluates and examines the Dataset for understanding the Dataset using the RStudio.  Part-I involves five major tasks to review and understand the Dataset variables.  Part-II discusses the Pre-Data Analysis, by converting the Dataset to Data Frame, involving three major tasks to analyze the Data Frame using logistic regression first, followed by the naïve Bayesian method.   The naïve Bayesian method used probabilities from the training set consisting of 60% randomly selected flights, and the remaining 40% of the 2201 flights serve as the holdout period.  The misclassification proportion of the naïve Bayesian method shows 19.52%, which is a little higher than the logistic regression. The prediction has 30 delayed flight out of the 167 correctly but fails to identify 137/(137+30), or 73% of the delayed flights.  Moreover, the 35/(35+679), or 4.9% of on-time flights are predicted as delayed as illustrated in Task-2 of Part-II and Figure-19.

Keywords: Flight-Delays Dataset; Naïve Bays Prediction Analysis Using R.

Introduction

This project examines and analyzes the Dataset of (flight.delays.csv).  The Dataset is downloaded from CTU course materials.  There have been a couple of attempts to download the Dataset from the following link https://www.transtats.bts.gov/.  However, the attempts failed to continue with the Dataset analysis due to the size of the downloaded Datasets from that link and the limited resources of the student’s machine.  Thus, this project utilized the version of flight.delays.csv which is provided by the course in the course material.  The Dataset of (flight.delays.cvs) has 2201 observations on 14 variables.  The focus of this analysis is Naïve Bayes.  However, for a better understanding of the prediction and a comparison using two different models, the researcher has also implemented the Logistic Regression first, followed by the Naïve Bayesian Approach on the same Dataset of flight.delays.csv.  This project addresses two major Parts.  Part-I covers the following key Tasks to understand and examine the Dataset of “flight.delays.csv.” 

  • Task-1:  Review the Variables of the Dataset.
  • Task-2:  Load and Understand the Dataset Using names(), head(), dim() Functions.
  • Task-3:  Examine the Dataset, Install the Required Packages, and Summary of the Descriptive Statistics.
  • Task-4:  Create Data Frame and Histogram of the Delay (Response)
  • Task-5:  Visualization of the Desired Variables Using Plot() Function.

Part-II covers the following three primary key Tasks to the plot, discuss and analyze the result.

  • Task-1:  Logistic Regression Model for Flight Delays Prediction
  • Task-2:  Naïve Bayesian Model for Flight Delays Prediction.
  • Task-3:  Discussion and Analysis.

Various resources were utilized to develop the required code using R. These resources include (Ahlemeyer-Stubbe & Coleman, 2014; Fischetti, Mayor, & Forte, 2017; Ledolter, 2013; r-project.org, 2018).

Part-I:  Understand and Examine the Dataset “flight.delays.csv”

Task-1:  Review the Variables of the Dataset

The purpose of this task is to understand the variables of the Dataset.  The Dataset is “flight. Delays” Dataset.  The Dataset describes the clients who can default on a loan.  There are 14 variables.  Table 1 summarizes the selected variables for this project.  

Table 1:  Flight Delays Variables

Task-2:  Load and Understand the Dataset Using names(), head(), dim() Functions.

            The purpose of this task is to load and understand the Dataset using names(), head(), dim() function.  The task also displays the first three observations.

  • ## reading the data
  • fd <-read.csv(“C:/CS871/Data/flight.delays.csv”)
  • names(fd[1:5,])
  • head(fd)
  • dim(fd)
  • fd[1:3,]

Task-3:  Examine the Dataset, Install the Required Packages, and Summary of the Descriptive Statistics.

            The purpose of this task is to examine the dawta set, install the requried package (car).  This task also displays the descriptive statistics for analysis.

  • ### set seed
  • set.seed(1)
  • ##Required Library(car) to recode a variable
  • install.packages(“car”)
  • library(car)
  • summary(fd)
  • plot(fd, col=”blue”)

Figure 1. The plot of the Identified Variables for the Flight Delays Dataset.

Task-5:  Visualization of the Desired Variables Using Plot() Function.

            The purpose of this task is to visualize the selected variables using the Plot() Function for a good understanding of these variables and the current trend for each variable.

  • plot(fd$schedf, col=”blue”, main=”Histogram of the Scheduled Time”)
  • plot(fd$carrier, col=”blue”, main=”Histogram of the Carrier”)
  • plot(fd$dest, col=”blue”, main=”Histogram of the Destination”)
  • plot(fd$origin, col=”blue”, main=”Histogram of the  Origin”)
  • plot(fd$weather, col=”blue”, main=”Histogram of the Weather”)
  • plot(fd$dayweek, col=”blue”, main=”Histogram of the Day of Week”)

Figure 2.  Histogram of the Schedule Time and Carrier.

Figure 3.  Histogram of the Destination and Origin.

Figure 4.  Histogram of the Weather and Day of Week.

Part-II:  Plot, Discuss and Analyze

 Task-1: Logistic Regression Model for Flight Delays

The purpose of this task is to first use the logistic regression model for predicting the on-time and delayed flights more than 15 minutes. The Dataset consists of 2201 flights for the year of 2004 from Washington DC into the NYC.  The characteristic of the response is whether or not a flight has been delayed by more than 15 minutes and coded as 0=no delay, and 1=delay by more than 15 minutes.  The explanatory variables include:

  • Three arrival airports (Kennedy, Newark, and LaGuardia).
  • Three different departure airports (Reagan, Dulles, and Baltimore.
  • Eight carriers a categorical variable for 16 different hours of departure (6:00 AM to 10:00 PM).
  • Weather conditions (0=good, 1=bad).
  • Day of week (1 for Sunday and Monday; and 0 for all other days).

The code of R is shown below for the logistic regression model.

  • ## Create a Data Frame and Understand the Dataset.
  • fd <-data.frame(fd)
  • names(fd)
  • head(fd)
  • fd[1:5,]
  • dim(fd)
  • summary(fd)
  • plot(fd, co=”blue”)
  • ## library car is needed to recode variables
  • library(car)
  • ##Define hours of Departure
  • fd$sched=factor(floor(fd$schedtime/100))
  • table(fd$sched)
  • table(fd$carrier)
  • table(fd$dest)
  • table(fd$origin)
  • table(fd$weather)
  • table(fd$dayweek)
  • table(fd$daymonth)
  • table(fd$delay)
  • fd$delay=recode(fd$delay,”‘delayed’=1;else=0″)
  • fd$delay=as.numeric(levels(fd$delay)[fd$delay])
  • table(fd$delay)
  • ## Summary of the Major Variables
  • summary(fd$sched)
  • summary(fd$carrier)
  • summary(fd$dest)
  • summary(fd$origin)
  • summary(fd$weather)
  • summary(fd$dayweek)
  • summary(fd$daymonth)
  • summary(fd$delay)
  • ## Plots and Histograms of the Major Variables
  • plot(fd$sched, col=”blue”, main=”Schedule Departure Time”)
  • plot(fd$carrier, col=”darkblue”, main=”Flight Carriers”)
  • plot(fd$dest, col=”darkred”, main=”Destination of Flights”)
  • plot(fd$origin, col=”green”, main=”Origin of Flights”)
  • plot(fd$weather, col=”darkgreen”, main=”Weather During Flight Days”)
  • hist(fd$dayweek, col=”darkblue”, main=”Flights Day of the Week”, xlab=”Day of Week”)
  • hist(fd$daymonth, col=”yellow”, main=”Flights Day of the Month”)
  • plot(fd$delay, col=”red”, main=”Plot of the Delay”)
  • hist(fd$delay, col=”red”, main=”Histogram of the Delay”)
  • ## Delay: 1=Monday and 7=Sunday coded as 1, else 0.
  • fd$dayweek=recode(fd$dayweek,”c(1,7)=1;else=0″)
  • table(fd$dayweek)
  • summary(fd$dayweek)
  • hist(fd$dayweek, col=”darkblue”, main=”Flights Day of the Week”, xlab=”Day of Week”)
  • ## Omit unused variables
  • fd=fd[,c(-1,-3,-5,-6,-7,-11,-12)]
  • fd[1:5,]
  • ## Create Sample Dataset
  • delay.length=length(fd$delay)
  • delay.length
  • delay.length1=floor(delay.length*(0.6))
  • delay.length1
  • delay.length2=delay.length-delay.length1
  • delay.length2
  • train=sample(1:delay.length, delay.length1)
  • train
  • plot(train, col=”red”)
  • ## Estimation of Logistic Regression Model
  • ##Explanatory Variables: carrier, destination, origin, weather, day of week,
  • ##(weekday/weekend), scheduled hour of departure.
  • ## Create design matrix; indicators for categorical variables (factors)
  • Xfd <- model.matrix(delay~., data=fd) [,-1]
  • Xfd[1:5,]
  • xtrain <- Xfd[train,]
  • xtrain[1:2,]
  • xtest <- Xfd[-train,]
  • xtest[1:2,]
  • ytrain <- fd$delay[train]
  • ytrain[1:5]
  • ytest <- fd$delay[-train]
  • ytest[1:5]
  • model1 = glm(delay~., family=binomial, data=data.frame(delay=ytrain,xtrain))
  • summary(model1)
  • ## Prediction: predicted default probabilities for cases in test set
  • probability.test <- predict(model1, newdata=data.frame(xtest), type=”response”)
  • data.frame(ytest,probability.test)[1:10,]
  • ## The first column in list represents the case number of the test element
  • plot(ytest~probability.test, col=”blue”)
  • ## Coding as 1 if probability 0.5 larger
  • ### using floor function
  • probability.fifty = floor(probability.test+0.5)
  • table.ytest = table(ytest,probability.fifty)
  • table.ytest
  • error = ((table.ytest[1,2]+table.ytest[2,1])/delay.length2)
  • error

Figure 5.  The probability of the Delay Using Logistic Regression.

Task-2:  Naïve Bayesian Model for Predicting Delays and Ontime Flights

The purpose of this task is to use the Naïve Bayesian model for predicting a categorical response from most categorical predictor variables.  The Dataset consists of 2201 flights in 2004 from Washington, DC into NYC.  The characteristic of the response is whether or not a flight has been delayed by more than 15 minutes (0=no delay, 1=delay).  The explanatory variables include the following:

  • Three arrival airports (Kennedy, Newark, and LaGuardia).
  • Three different departure airports (Reagan, Dulles, and Baltimore.
  • Eight carriers.
  • A categorical variable for 16 different hours of departure (6:00 AM to 10:00 PM).
  • Weather conditions (0=good, 1=bad).
  • Day of week (7 days with Monday=1, …, Sunday=7).

The code of R is shown below for the logistic regression model, followed by the result of each code.

  • fd=data.frame(fd)
  • fd$schedf=factor(floor(fd$schedtime/100))
  • fd$delay=recode(fd$delay,”‘delayed’=1;else=0″)
  • response=as.numeric(levels(fd$delay)[fd$delay])
  • hist(response, col=”orange”)
  • fd.mean.response=mean(response)
  • fd.mean.response
  • ## Create Train Dataset 60/40
  • n=length(fd$dayweek)
  • n
  • n1=floor(n*(0.6))
  • n1
  • n2=n-n1
  • n2
  • train=sample(1:n,n1)
  • train
  • plot(train, col=”blue”, main=”Train Data Plot”)
  • ## Determine Marginal Probabilities
  • td=cbind(fd$schedf[train],fd$carrier[train],fd$dest[train],fd$origin[train],fd$weather[train],fd$dayweek[train],response[train])
  • td
  • tdtrain0=td[td[,7]<0.5,]
  • tdtrain1=td[td[,7]>0.5,]
  • tdtrain0[1:3]
  • tdtrain1[1:3]
  • plot(td, col=”blue”, main=”Train Data”)
  • plot(tdtrain0, col=”blue”, main=”Marginal Probability <0.5″ )
  • plot(tdtrain1, col=”blue”, main=”Marginal Probability > 0.5″)
  • ## Prior Probabilities for Delay for P( y = 0 ) and P(y = 1)
  • tdel=table(response[train])
  • tdel=tdel/sum(tdel)
  • tdel
  • ## P( y = 0)       P( y = 1)         1
  • ##0.8022727    0.1977273
  • ## Probabilities for Scheduled Time
  • ### Probabilities for (y=0) for Scheduled Time
  • ts0=table(tttrain0[,1])
  • ts0=ts0/sum(ts0)
  • ts0
  • ### Probabilities for (y = 1) for Scheduled Time
  • ts1=table(tttrain1[,1])
  • ts1=ts1/sum(ts1)
  • ts1
  • ## Probabilities for Carrier
  • ## Probabilities for (y = 0) for Carrier
  • tc0=table(tttrain0[,2])
  • tc0=tc0/sum(tc0)
  • tc0
  • tc1=table(tttrain1[,2])
  • tc1=tc1/sum(tc1)
  • tc1
  • ## Probabilities for Destination
  • ##Probabilities for (y=0) for Destination
  • td0=table(tttrain0[,3])
  • td0=td0/sum(td0)
  • td0
  • ##Probabilities for (y=1) for Destination
  • td1=table(tttrain1[,3])
  • td1=td1/sum(td1)
  • td1
  • ## Probabilities for Origin
  • ##Probabilities for (y=0) for Origin
  • to0=table(tttrain0[,4])
  • to0=to0/sum(to0)
  • to0
  • ##Probabilities for (y=1) for Origin
  • to1=table(tttrain1[,4])
  • to1=to1/sum(to1)
  • to1
  • ## Probabilities for Weather
  • ##Probabilities for (y=0) for Origin
  • tw0=table(tttrain0[,5])
  • tw0=tw0/sum(tw0)
  • tw0
  • ## bandaid as no observation in a cell
  • tw0=tw1
  • tw0[1]=1
  • tw0[2]=0
  • ##Probabilities for (y=1) for Weather
  • tw1=table(tttrain1[,5])
  • tw1=tw1/sum(tw1)
  • tw1
  • ## Probabilities for Day of Week
  • #### Probabilities for (y-0) for Day of Week
  • tdw0=table(tttrain0[,6])
  • tdw0=tdw0/sum(tdw0)
  • tdw0
  • #### Probabilities for (y-1) for Day of Week
  • tdw1=table(tttrain1[,6])
  • tdw1=tdw1/sum(tdw1)
  • tdw1
  • ### Create Test Data
  • testdata=cbind(fd$schedf[-train],fd$carrier[-train],fd$dest[-train],fd$origin[-train],fd$weather[-train],fd$dayweek[-train],response[-train])
  • testdata[1:3]
  • ## With these estimates, the following probabilities can be determined.
  • ##P(y = 1|Carrier = 7,DOW = 7,DepTime = 9 AM−10 AM,Dest = LGA,Origin = DCA,Weather = 0)
  • =[(0.015)(0.172)(0.027)(0.402)(0.490)(0.920)](0.198)
  • [(0.015)(0.172)(0.027)(0.402)(0.490)(0.920)](0.198)
  • +[(0.015)(0.099)(0.059)(0.545)(0.653)(1)](0.802)
  • = 0.09.
  • ## Creating Predictions, stored in prediction
  • p0=ts0[tt[,1]]*tc0[tt[,2]]*td0[tt[,3]]*to0[tt[,4]]*tw0[tt[,5]+1]*tdw0[tt[,6]]
  • p1=ts1[tt[,1]]*tc1[tt[,2]]*td1[tt[,3]]*to1[tt[,4]]*tw1[tt[,5]+1]*tdw1[tt[,6]]
  • prediction=(p1*tdel[2])/(p1*tdel[2]+p0*tdel[1])
  • hist(prediction, col=”blue”, main=”Histogram of Predictions”)
  • plot(response[-train], prediction,col=”blue”)
  • ###Coding as 1 if probability >=0.5 
  • ## Calculate the Probability for at least 0.5 or more
  • prob1=floor(prediction+0.5)
  • tr=table(response[-train],prob1)
  • tr
  • error=(tr[1,2]+tr[2,1])/n2
  • error
  • ## Calculate the Probability for at least 0.3 or more
  • prob2=floor(prediction+0.3)
  • tr2=table(response[-train],prob2)
  • tr2
  • error=(tr[1,2]+tr[2,1])/n2
  • error
  • ## calculating the lift, cumulative, sorted by predicted values and average success.
  • ## cumulative 1’s sorted by predicted values
  • ## cumulative 1’s using the average success prob from training set
  • axis=dim(n2)
  • ax=dim(n2)
  • ay=dim(n2)
  • axis[1]=1
  • ax[1]=xbar
  • ay[1]=bb1[1,2]
  • for (i in 2:n2) {
  • axis[i]=i
  • ax[i]=xbar*i
  • ay[i]=ay[i-1]+bb1[i,2]
  • }
  • aaa=cbind(bb1[,1],bb1[,2],ay,ax)
  • aaa[1:100,]
  • plot(axis,ay,xlab=”Number of Cases”,ylab=”Number of Successes”,main=”Lift: Cum Successes Sorted Predicted Values Using Average Success Probabilitis”, col=”red”)
  • points(axis,ax,type=”l”)

Figure 6. Pre and Post Factor and Level of History Categorical Variable.

Figure 7: Train Dataset Plot.

Figure 8.  Train Data, Marginal Probability of <0.5 and >0.5.

Figure 9.  Prior Probability for Delay (y=0) and (y-1).

Figure 10.  Prior Probability for Scheduled Time: Left (y=0) and Right (y-1).

Figure 11.  Prior Probability for Carrier: Left (y=0) and Right (y-1).

Figure 12.  Prior Probability for Destination: Left (y=0) and Right (y-1).

Figure 13.  Prior Probability for Origin: Left (y=0) and Right (y-1).

Figure 14.  Prior Probability for Weather: Left (y=0) and Right (y-1).

Figure 15.  Prior Probability for Day of Week: Left (y=0) and Right (y-1).

Figure 16.  Test Data Plot.

Figure 17.  Histogram of the Prediction Using Bayesian Method.

Figure 18.  Plot of Prediction to the Response Using the Test Data.

Figure 19.  Probability Calculation for at least 0.5 or larger (left), and at least 0.3 or larger (right).

Figure 20.  Lift: Cum Success Sorted by Predicted Values Using Average Success Probabilities.

Task-3: Discussion and Analysis

            The descriptive analysis shows that the average schedule time is 13:72 which is less than the median of 14:55 indicating a negatively skewed distribution, while the average for the departure time is 13:69 which is less than the median of 14:50 confirming the negatively skewed distribution.  The result of the carrier shows that the DH has the highest rank of 551, followed by RU of 408. The result of the destination shows that the LGA has the highest rank of 1150, followed by EWR of 665 and JFK of 386.   The result of the origin shows that DCA has the highest rank of 1370, followed by IAD of 686 and 145 for BWI.   The result shows that the weather is not the primary reason for the delays.  Few instances of weather instances are related to the delays.  The descriptive analysis shows the ontime has the highest frequency of 1773, followed by the delays of 428 frequency.  The average delay or response is 0.195.

The result shows the success probability which is the proportion of delayed planes in the training set if 0.198 as analyzed in Task 2 of Part-II; the failure probability which is the proportion of on-time flights is 0.802 as discussed and analyzed in Task-2 of Part-II.   The naïve rule which does not incorporate any covariate information classified every flight as being on-time as the estimated unconditional probability of a flight being on-time, 0.802, is larger than the cutoff of 0.5. Thus, this rule does not make an error predicting a flight which is on-time, but it makes a 100% error when the flight is delayed.   The naïve rule fails to identify the 167 delayed flights among the 881 flights of the evaluation Dataset as shown in Task-1 of Part-II; its misclassification error rate in the holdout sample is 167/881=0.189.  The logistic regression reduces the overall misclassification error in the holdout (evaluation/test) Dataset to 0.176, which is a modest improvement over the naïve rule of (0.189) as illustrated in Task-1 of Part-II.   The logistic regression identifies, among 167 delayed flights, correctly 14 delayed flights 8.4%, but it misses 153/167 delayed flights (92.6%).  Moreover, the logistic regression model predicts 2 of the 714 on-time flights as being delayed as illustrated in Task-1 of Part-II.

The naïve Bayesian method used probabilities from the training set consisting of 60% randomly selected flights, and the remaining 40% of the 2201 flights serve as the holdout period.  The misclassification proportion of the naïve Bayesian method shows 19.52%, which is a little higher than the logistic regression. The prediction has 30 delayed flight out of the 167 correctly but fails to identify 137/(137+30), or 73% of the delayed flights.  Moreover, the 35/(35+679), or 4.9% of on-time flights are predicted as delayed as illustrated in Task-2 of Part-II and Figure-19.

The lift charts (Figure 20) is constructed with the number of cases on the x-axis and the cumulative true-positive cases on the y-axis.  True positives are those observations which are classified correctly.  It measures the effectiveness of a classification model by comparing the true positives without a model (Hodeghatta & Nayak, 2016).  It also provides an indication of how well the model performs if the samples are selected randomly from a population (Hodeghatta & Nayak, 2016).  With the lift chart, a comparison of different models’ performance for a set of random cases (Hodeghatta & Nayak, 2016).  In Figure 20, the lift varies with the number of cases, and the black line is a reference line, meaning if a prediction of a positive case is made in case there was no model, then, this line provides a benchmark.  The lift curve graph in Figure 20, graphs the expected number of delayed flights, assuming that the probability of delay is estimated by the proportion of delayed flights in the evaluation sample, against the number of cases.  The reference line expresses the performance of the naïve model. With ten flights, for instance, the expected number of delayed flights is 10 p, where p is the proportion of delayed flights in the evaluation sample which is 0.189 in this case.  At the very end, the lift curve and the reference line meet. However, in the beginning, the logistic regression leads to a “lift.” For instance, when picking 10 cases with the largest estimated success probabilities, all the 10 case turn out to be delayed.  If the lift is close to the reference line, then there is not much point in using the estimated model for classification. The overall misclassification rate of the logistic regression is not that different from that of the naïve strategy which considers all flights as being on-time. However, as the lift curve shows, flights with the largest probabilities of being delayed are classified correctly. The logistic regression is quite successful in identifying those flight as being delayed.  The lift curve in Figure 10 shows that the model gives an advantage in detecting the most apparent flights which are going to be delayed or on-time.

References

Ahlemeyer-Stubbe, A., & Coleman, S. (2014). A practical guide to data mining for business and industry: John Wiley & Sons.

Fischetti, T., Mayor, E., & Forte, R. M. (2017). R: Predictive Analysis: Packt Publishing.

Hodeghatta, U. R., & Nayak, U. (2016). Business Analytics Using R-A Practical Approach: Springer.

Ledolter, J. (2013). Data mining and business analytics with R: John Wiley & Sons.

r-project.org. (2018). R: A Language and Environment for Statistical Computing. Retrieved from https://cran.r-project.org/doc/manuals/r-release/fullrefman.pdf.

Quantitative Analysis of “German.Credit” Dataset Using K-NN Classification and Cross-Validation

Dr. O. Aly
Computer Science

Introduction

The purpose of this discussion is to use the german.credit.csv dataset to address the issues of lending which result in default.  Two outcomes are success (defaulting on the loan), and failure (not defaulting on the loan).  The explanatory variables in the Logistic Regression are both the type of loan and borrowing amount.  For the K-NN Classification, three continuous variables are used:  duration, amount, and installment.  The cross-validation with k=5 for the nearest neighbor will be used as well in this analysis.

The dataset is downloaded from the following archive site for machine learning repository : https://archive.ics.uci.edu/ml/datasets/Statlog+(German+Credit+Data).  The dataset has 1000 observation on 222 variables. There are two datasets for german.credit.csv.  The original dataset, in the form provided by Professor Hofmann, contains categorical/symbolic attributes and is in the current german.credit.csv file which is used in this disussion.  The other dataset “german.data-numeric” is not used in this discussion which was developed by Strathclyde University for algorithms that need numerical attributes.  This discussion utilized the original version of german.credit.csv which has categorical variables and the continuous variables. 

This analysis discusses and addresses fourteen Tasks as shown below:

  • Task-1: Understand the Variables of the Dataset
  • Task-2: Load and Review the Dataset using names(), head(), dim() functions.
  • Task-3: Pre and Post Factor and Level of Categorical Variables of the Dataset.
  • Task-4: Summary and Plot the Continuous Variables: Duration, Amount, and Installment
  • Task-5: Classify Amount into Groups.
  • Task-6: Summary of all selected variables.
  • Task-7: Select and Plot Specific Variables for this analysis.
  • Task-8:  Create Design Matrix
  • Task-9:   Create Training and Prediction Dataset.
  • Task-10:  Implement K-Nearest Neighbor Method.
  • Task-11: Calculate the Proportion of Correct Classification.
  • Task-12: Plot for 3 Nearest Neighbor.
  • Task-13: Cross-Validation with k=5 for the Nearest Neighbor.
  • Task-14: Discussion and Analysis.

Various resources were utilized to develop the required code using R. These resources include (Ahlemeyer-Stubbe & Coleman, 2014; Fischetti, Mayor, & Forte, 2017; Ledolter, 2013; r-project.org, 2018)

Task-1:  Understand the Variables of the Data Sets

The purpose of this task is to understand the variables of the dataset.  The dataset is “german.credit” dataset.  The dataset describes the clients who can default on a loan.  There are selected variables out of the 22 variables which are target for this analysis.  Table 1 and Table 2 summarize these selected variables for this discussion.  Table 1 focuses on the variables with binary and numerical values, while Table 2 focuses on the variables with categorical values.

Table 1:  Binary and Numerical Variables

Table 2: Categorical Variables.

Task-2:  Load and Review the Dataset using names(), heads(), dim() functions

  • gc <- read.csv(“C:/CS871/german.credit.csv”)
  • names(gc)
  • head(gc)
  • dim(gc)
  • gc[1:3,]

Task-3:  Pre and Post Factor and Level of Categorical Variables of the Data Sets

  • ## history categorical variable pre and post factor and level.
  • summary(gc$history)
  • plot(gc$history, col=”green”, xlab=”History Categorical Variable Pre Factor and Level”)
  • gc$history = factor(gc$history, levels=c(“A30”, “A31”, “A32”, “A33”, “A34”))
  • levels(gc$history)=c(“good-others”, “good-thisBank”, “current-paid-duly”, “bad-delayed”, “critical”)
  • summary(gc$history)
  • plot(gc$history, col=”green”, xlab=”History Categorical Variable Post Factor and Level”)
  • ##### purpose pre and post factor and level
  • summary(gc$purpose)
  • plot(gc$purpose, col=”darkgreen”)
  • ###tranform purpose
  • gc$purpose <- factor(gc$purpose, levels=c(“A40″,”A41″,”A42″,”A43″,”A44″,”A45″,”A46″,”A48″,”A49″,”A410”))
  • levels(gc$purpose) <- c(“newcar”,”usedcar”,”furniture/equipment”,”radio/television”,”domestic appliances”,”repairs”, “edu”,”vacation-doesNotExist”, “retraining”, “business”, “others”)
  • summary(gc$purpose)
  • plot(gc$purpose, col=”darkgreen”)

Figure 1.  Example of Pre and Post Factor of Purpose as Cateogircal Variable Illustration.

Task-4:  Summary & Plot the Numerical Variables: Duration, Amount, Installment

  • ##summary and plot of those numerical variables
  • summary(gc$duration)
  • summary(gc$amount)
  • plot(gc$amount, col=”blue”, main=”Amount Numerical Variable”)
  • summary(gc$installment)
  • plot(gc$installment, col=”blue”, main=”Installment Numerical Variable”)

Figure 2:  Duration, Amount, Installment Continuous IV.

Task-5:  Classify the Amount into Groups

  • #### To classify the amount into groups
  • gc$amount <-as.factor(ifelse(gc$amount <=2500, ‘0-2500′, ifelse(gc.df$amount<=5000,’2600-5000’, ‘5000+’)))
  • summary(gc$amount)

Task-6:  Summary of all variables

  • summary(gc$duration)
  • summary(gc$amount)
  • summary(gc$installment)
  • summary(gc$age)
  • summary(gc$history)
  • summary(gc$purpose)
  • summary(gc$housing)
  • summary(gc$rent)

Task-7:  Select and Plot specific variables for this discussion

  • ##cut the dataset to the selected variables
  • ##(duration, amount, installment, and age) which are numeric and
  • ##(history, purpose and housing) which are categorical and
  • ## Default (representing the risk) which is binary.
  • gc.sv <- gc[,c(“Default”, “duration”, “amount”, “installment”, “age”, “history”, “purpose”, “foreign”, “housing”)]
  • gc.sv[1:3,]
  • summary(gc.sv)
  • ### Setting the Rent
  • gc$rent <- factor(gc$housing==”A151″)
  • summary(gc$rent)
  • plot(gc, col=”blue”)

Figure 3:  Plot of The Selected Variables.

Task-8:  Create Design Matrix

  • ###Create a Design Matrix
  • ##Factor variables are turned into indicator variables
  • ##The first column of ones is ommitted
  • Xgc <- model.matrix(Default~.,data=gc)[,-1]
  • Xgc[1:3,]

Task-9: Create Training and Prediction Datasets

  • ## creating training and prediction datasets
  • ## select 900 rows for estimation and 100 for testing
  • set.seed(1)
  • train <- sample(1:1000,900)
  • xtrain <- Xgc[train,]
  • xnew <- Xgc[-train,]
  • ytrain <- gc$Default[train]
  • ynew <- gc$Default[-train]

Task-10:  K-Nearest Neighbor Method

  • ## k-nearest neighbor method
  • library(class)
  • nearest1 <- knn(train=xtrain, test=xnew, cl=ytrain, k=1)
  • nearest3 <- knn(train=xtrain, test=xnew, cl=ytrain, k=3)
  • data.frame(ynew,nearest1,nearest3)[1:10,]

Task-11: Calculate the Proportion of Correct Classification

  • ## calculate the proportion of correct classifications
  • proportion.correct.class1=100*sum(ynew==nearest1)/100
  • proportion.correct.class3=100*sum(ynew==nearest3)/100
  • proportion.correct.class1
  • proportion.correct.class3

Task-12: Plot for 3 Nearest Neighbors

  • ## plot for 3NN
  • plot(xtrain[,c(“amount”,”duration”)],
  • col=c(4,3,6,2)[gc[train,”installment”]],
  • pch=c(1,2)[as.numeric(ytrain)],
  • main=”Predicted Default, by 3 Nearest Neighbors”, xlab=”Amount”, ylab=”Duration”,cex.main=.95)
  • points(xnew[,c(“amount”,”duration”)],
  • bg=c(4,3,6,2)[gc[train,”installment”]],
  • pch=c(21,24)[as.numeric(nearest3)],cex=1.2,col=grey(.7))
  • legend(“bottomright”,pch=c(1,16,2,17),bg=c(1,1,1,1),
  • legend=c(“data 0″,”pred 0″,”data 1″,”pred 1”),
  • title=”default”,bty=”n”,cex=.8)
  • legend(“topleft”,fill=c(4,3,6,2),legend=c(1,2,3,4),
  • title=”installment %”, horiz=TRUE,bty=”n”,col=grey(.7),cex=.8)

Figure 4:  Predicted Default by 5 Nearest Neighbors.

Task-13: Cross-Validation with k=5 for the nearest neighbor

  • ## The above was for just one training set
  • ## The cross-validation (leave one out)
  • proportion.corr=dim(10)
  • for (k in 1:10) {
  • prediction=knn.cv(x,cl=gc$Default,k)
  • proportion.corr[k]=100*sum(gc$Default==prediction)/1000
  • }
  • proportion.corr

Task-14: Discussion and Analysis

The descriptive analysis shows that the average duration (Mean=20.9) is higher than the Median (Median=18) indicating a positively skewed distribution.  The average amount (Mean=3271) is higher than the Median (Median=2320) indicating a positively skewed distribution.  The average installment rate is (Mean=2.97) is a little less than the Median (Median=3.00) indicating a small negative skewed distribution.  The result also shows that the radio/TV ranks number one for the loan, followed by a new car.  A training dataset is created to select 900 rows for estimation and 100 for testing.  K-NN method is used to estimate the nearest using k=1 and k=3, and the proportion of the correct classification is calculated to result in 60% and 61% for k=1 and k=3 respectively (Figure 4).  The result of the cross-validation with k=5 for the nearest neighbor is about 65% of the outcome.

References

Ahlemeyer-Stubbe, A., & Coleman, S. (2014). A practical guide to data mining for business and industry: John Wiley & Sons.

Fischetti, T., Mayor, E., & Forte, R. M. (2017). R: Predictive Analysis: Packt Publishing.

Ledolter, J. (2013). Data mining and business analytics with R: John Wiley & Sons.

r-project.org. (2018). R: A Language and Environment for Statistical Computing. Retrieved from https://cran.r-project.org/doc/manuals/r-release/fullrefman.pdf.

Ahlemeyer-Stubbe, A., & Coleman, S. (2014). A practical guide to data mining for business and industry: John Wiley & Sons.

Fischetti, T., Mayor, E., & Forte, R. M. (2017). R: Predictive Analysis: Packt Publishing.

Ledolter, J. (2013). Data mining and business analytics with R: John Wiley & Sons.

r-project.org. (2018). R: A Language and Environment for Statistical Computing. Retrieved from https://cran.r-project.org/doc/manuals/r-release/fullrefman.pdf.

Examples of Bayesian Analysis in the Context of Social Media

Dr. O. Aly
Computer Science

Introduction

The purpose of this discussion is to provide examples of how Bayesian analysis can be used in the context of social media.  The discussion also summarizes the study which used Bayesian analysis in the context of social media. The discussion begins with Naïve Bayes Classifiers for Mining, followed by the Importance of Social Media, the Social Media Mining, Social Media Mining Techniques, Social Media Mining Process, Data Modelling Step, Twitter Mining Using Naïve Bayes with R.  The discussion ends with additional examples of the Bayesian Analysis methods in Social Media.

Naïve Bayes Classifiers for Mining

Naïve Bayes classifiers are probabilistic classifiers, built using the Bayes Theorem (Kumar & Paul, 2016). Naïve Bayes is also known as prior probability and a class conditional probability classifier, since it uses the prior probability of each feature and generates a posterior probability distribution over all the features (Kumar & Paul, 2016). 

The Naïve Bayes classifier makes the following assumptions about the data (Kumar & Paul, 2016):

  • All the features in the dataset are independent of each other.
  • All the features are important.

Though these assumptions may not be accurate in a real-world scenario, Naïve Bayes is still in many applications for text classification such as (Kumar & Paul, 2016):

  • Spam filtering for email applications
  • Social media mining, such as finding the sentiments in a given text.
  • Computer network security applications.

As indicated by (Kumar & Paul, 2016), the classifier has various strength such as:

  • Naïve Bayes classifiers are highly scalable and need less computational cycles when compared with other advanced and sophisticated classifiers.
  • A vast number of features can be taken into consideration.
  • The Naïve Bayes classifiers work well when there is missing data, and the dimensionality of the inputs is high.
  • The Naïve Bayes need only small amounts of training sets.

The Importance of Social Media

The traditional media such as radio, newspaper, or television facilitates one-way communication with a limited scope of reach and usability.  Although the audience can interact with channels such as radio, the quality, and frequency of such communications are limited (Ravindran & Garg, 2015).  On the other hand, the Internet-based social media offers multi-way communication with features such as immediacy and permanence (Ravindran & Garg, 2015).

Social media is an approach to communication using online tools such as Twitter, Facebook, LinkedIn, and so forth (Ravindran & Garg, 2015).  Social Media is defined by Andreas Kaplan and Michael Haenlein as cited in (Ravindran & Garg, 2015) as follows:  “A group of Internet-based applications that build on the ideological and technological foundations of Web 2.0 and that allow the creation and exchange of user-generated content.”

Social media spans various Internet-based platforms which facilitate human emotions such as:

  • Networking, such as Facebook, LinkedIn.
  • Microblogging, such as Twitter, Tumblr.  
  • Photo sharing, such as Instagram, Flickr.
  • Video sharing, such as YouTube, Vimeo.
  • Stack exchanging, such as Stack Overflow, Github.
  • Instant messaging, such as Whatsapp, Hike.

The marketing industry is maturing in understanding the promise or the impact of social media (Ravindran & Garg, 2015).  While social media is regarded to be a great tool for banner advertisement regarding cost and reach, it can turn out to be more influential in the long term (Ravindran & Garg, 2015).  Organizations need to find out about the opinions of consumers by mining social networks (Ravindran & Garg, 2015).  They can understand the current and potential outlook of consumers by collecting information on their opinions, and such informative information can guide a business decision, in the long run, influencing the fate of any business (Ravindran & Garg, 2015).

Social Media Mining

The social media mining is a systematic analysis of information generated from social media.  The set of tools and techniques which are used to mine such information are collectively called Data Mining techniques and in the context of social media; Social Media Mining (SMM) (Ravindran & Garg, 2015).  There has been much research in multiple disciplines of social media such as modeling behavior, predictive analysis, and recommending content (Ravindran & Garg, 2015).

Social Media Mining (SMM)Techniques

Graph mining is one technique of the SMM.  Graph mining is described as “the process of extracting useful knowledge (patterns, outliers and so on), from a social relationship between the community members can be represented as a graph” (Ravindran & Garg, 2015).  The most influential example of Graph Mining is Facebook Graph Search (Ravindran & Garg, 2015). The Text Mining is another SMM technique, which includes extraction of meaning from unstructured text data presented in social media.  The primary targets of this type of mining are blogs and microblogs such as Twitter (Ravindran & Garg, 2015). 

Social Media Mining Process

The process of the social media mining include the following five steps (Ravindran & Garg, 2015):

  1. Getting authentication from the social website.
  2. Data Visualization.
  3. Cleaning and pre-processing.
  4. Data modeling using standard algorithms such as opinion mining, clustering, anomaly/spam detection, correlations and segmentation, recommendations.
  5. Result Visualization.

Data Modelling Step

This step is number four in the process of social media mining which includes the application of mining algorithms (Ravindran & Garg, 2015).  Standard mining algorithms include the opinion mining or sentiment mining where the opinion/sentiment present in the given phrase is assessed (Ravindran & Garg, 2015).  Although the classification of sentiments is not a simple technique, various classification algorithms have been employed to aid opinion mining. This algorithm varies from simple probabilistic classifiers such as Naïve Bayes which assumes that all features are independent and does not use any prior information, to the more advanced classifiers such as Maximum Entropy, which uses the prior information to a certain extent (Ravindran & Garg, 2015).  Other classifiers include Support Vector Machine (SVM), and Neural Networks NN) which have been used to correctly classify the sentiments (Ravindran & Garg, 2015).  Additional methods include Anomaly/spam detection or social spammer detection (Ravindran & Garg, 2015).  Fake profiles created with malicious intentions are known as spam or anomalies profiles (Ravindran & Garg, 2015).

Twitter Mining Using Naïve Bayes with R

In this application, after getting the cleaned Twitter data, R packages are used to assess the sentiments in the tweets.  The first step is to obtain the authorization using the following two packages (r-project.org, 2018; Ravindran & Garg, 2015):

  • getTwitterOAuth(consumer_key, consumer_secret)
  • registerTwitterOAuth(OAuth)
  • source(“authenticate.R”)

Collect tweets as a corpus, using searchTwitter() function in R.  After obtaining the cleaned Twitter data; few R packages are used to assess the sentiments in the tweets.  The first step is to use a Naïve algorithm which gives a score based on the number of times a positive or negative word occurred in the given sentence in this example (Ravindran & Garg, 2015).  To estimate the sentiment further, Naïve Bayes is used in deciding on the emotion present in any tweet.  The Naïve Bayes method requires R packages called Rstem and sentiment to assist with this assessment.  These packages are now removed from R repository. However, they can still be downloaded from the archive at https://cran.r-project.org/src/contrib/Archive/.  Additional R packages include classify_emotion().  Example of the result is illustrated in Figure 1, when applying the Naïve Bayes method using R (Ravindran & Garg, 2015).

Figure 1. Example of the Result When Applying Naïve Bayes Method in R (Ravindran & Garg, 2015).

In summary, the Naïve Bayes method can be used in social media such as Twitter example.  Certain R packages must be installed to be able to complete the Naïve Bayes analysis on twitter dataset.

Additional Examples of Bayesian Analysis methods in Social Media

In another application of Naïve Bayes method on social media reported by (Singh, Singh, & Singh, 2017).  Naïve Bayes classifier is a popular supervised classifier, provides a way to express positive, negative and neutral feelings in the web text.  It utilizes conditional probability to classify words into their respective categories (Singh et al., 2017).  The benefit of using Naïve Bayes on text classification is that it needs a small dataset for training (Singh et al., 2017).  The raw data from web undergoes pre-processing, removal of numeric, foreign words, HTML tags, and special symbols yielding the set of words (Singh et al., 2017).  The tagging of words with labels of positive, negative and neutral tags is manually performed by human experts (Singh et al., 2017).  This pre-processing produces word-category pairs for training set (Singh et al., 2017). 

The work of (Singh et al., 2017) focused on four Text Classifiers utilized for sentiment analysis: Naïve Bayes, J48, BFTree, and OneR algorithms.  Naïve Bayes was found to be quite fast in learning whereas OneR method was found more promising in generating the accuracy of 91.3% in precision, 97% in F-measure and 92.34% in correctly classified instances (Singh et al., 2017). 

Another example of the application of Bayesian Analysis is also reported in the research paper of (Volkova & Van Durme, 2015).  The work of (Volkova & Van Durme, 2015) proposed two approaches in mining streaming social media.  They studied iterative, incremental retraining in batch and current settings with and without iterative annotations. They treated each new message as independent evidence which is combined into an incremental user-prediction model applying Bayes Rule and explored model training in parallel with its application, rather than assuming a previously existing labeled dataset.  The applied Bayesian rule updates to dynamically revise posterior probability estimates of the attribute value in question (Volkova & Van Durme, 2015). 

References

Kumar, A., & Paul, A. (2016). Mastering Text Mining with R: Packt Publishing Ltd.

r-project.org. (2018). Pakcage ‘twitterR’. Retrieved from https://cran.r-project.org/web/packages/twitteR/twitteR.pdf.

Ravindran, S. K., & Garg, V. (2015). Mastering social media mining with R: Packt Publishing Ltd.

Singh, J., Singh, G., & Singh, R. (2017). Optimization of sentiment analysis using machine learning classifiers. Human-centric Computing and Information Sciences, 7(1), 32.

Volkova, S., & Van Durme, B. (2015). Online Bayesian Models for Personal Analytics in Social Media.

Bayesian Analysis

Dr. Aly, O.
Computer Science

Introduction

The purpose of this discussion is to discuss and analyze Bayesian analysis and the reasons for using it when faced with uncertainty in making decisions.  The discussion also addresses any assumptions of Bayesian analysis, cases which would call for Bayesian analysis, and any problems with the Bayesian analysis.

Probability Theory and Probability Calculus

Various words and terms are used to describe uncertainty and related concepts such as probability, chance, randomness, luck, hazard, and fate (Hand, Mannila, & Smyth, 2001).  Modeling “uncertainty” is a required component of almost all data analysis (Hand et al., 2001).   There are various reasons for such uncertainty.  One reason is that the data may be only a sample from the population which is used for the research study so that the uncertainty is about the extent to which different samples differ from each other and the overall population (Hand et al., 2001).  Another reason for such uncertainty is a prediction about tomorrow based on today’s data so that the conclusions are subject to uncertainty about what the future will bring (Hand et al., 2001). Another reason includes the ignorance, and some value cannot be observed, and the ideas must be based on the “best guess” about it (Hand et al., 2001).

There are two different probabilities: probability theory and probability calculus (Hand et al., 2001). The probability theory is concerned with the interpretation of probability while the probability calculus is concerned with the manipulation of the mathematical representation of probability (Hand et al., 2001).  

The probability measures the likeliness that a particular event will occur.  Mathematicians refer to a set of potential outcomes of an experiment or trial to which a probability of occurrences can be assigned (Fischetti, Mayor, & Forte, 2017).  Probabilities are expressed as a number between 0 and 1 or as a percentage out of 100 (Fischetti et al., 2017).  An event with a probability of 0 denotes an impossible outcome, and a probability of 1 describes an event that is certain to occur (Fischetti et al., 2017).  An example of probability is a coin flip, where there are two outcomes: heads or tails.  Since the entire sample space is covered by these two outcomes, they are said to be collectively exhaustive, and mutually exclusive, meaning that they can never co-occur together (Fischetti et al., 2017). Thus, the probability of obtaining either heads or tails is P(heads)=0.50; P(tails)=0.50 respectively.  Moreover, when the probability of either outcome does not affect the probability of the other, these events are described as “conditionally independent” (Fischetti et al., 2017).   For instance, the probability of event A and event B is the product of the probability of A and the probability of B (Fischetti et al., 2017). 

Subjective vs. Objective Probability Views

In the first half of the 20th century the dominant statistics was the frequentist approach (Hand et al., 2001; O’Hagan, 2004).  The frequentist view of probability takes the perspective that probability is an “objective” concept, where the probability of an event is defined as the limiting proportion of times that the event would occur in repetitions of the substantially identical situation (Hand et al., 2001). Example of this frequentist probability is the coin example mentioned above. 

In the second half of the 20th century, the dominance of the frequentist view started to fade out (Hand et al., 2001; O’Hagan, 2004).  Although the vast majority of statistical analysis in practice is still frequentist, a competing view of “subjective probability” has acquired increasing importance (Hand et al., 2001; O’Hagan, 2004).  The principles and methodologies for data analysis driven from the “subjective” view are often referred to as “Bayesian” statistics (Fischetti et al., 2017; Hand et al., 2001; O’Hagan, 2004).   The calculus is the same for the two viewpoints, even though the underlying interpretation is entirely different (Hand et al., 2001).

Bayesian Theorem

It is named after the 18th-century minister Thomas Bayes, whose paper presented to the Royal Society in 1763 first used the Bayesian argument (O’Hagan, 2004).  Although the Bayesian approach can be traced back to Thomas Bayes, its modern incarnation began only in 1950 and 1960 (O’Hagan, 2004). 

The central tent of Bayesian statistics is the explicit characterization of all forms of uncertainty in a data analysis problem including uncertainty about any parameters which are estimated from the data, uncertainty as to which among a set of model structures are best or closest to “truth,” uncertainty in any forecast that can be made, and so forth (Hand et al., 2001).  Because Bayesian interpretation is subjective, when evidence is scarce, there are sometimes wildly different degrees of belief among different people (Fischetti et al., 2017; Hand et al., 2001; O’Hagan, 2004).

From the perspective of the “subjective” probability, the Bayesian interpretation of probability views probability as the degree of belief in a claim or hypothesis (Fischetti et al., 2017; Hand et al., 2001).  The Bayesian inference provides a method to update that belief or hypotheses in the light of new evidence (Fischetti et al., 2017).  The equation of the Bayes’ Theorem is defined in equation (1) (Fischetti et al., 2017; Hand et al., 2001; O’Hagan, 2004).

Where:

  • H is the hypothesis.
  • E is the evidence.

Bayesian Continuous Posterior Distribution

When working with Bayesian analysis, the hypothesis concerns a continuous parameter or many parameters (Fischetti et al., 2017).  Bayesian analysis usually yields a continuous posterior called a “posterior distribution” (Fischetti et al., 2017).  The Bayes methods utilize the Bayes’ rule which expresses a powerful framework for combining sample information with a prior expert opinion to produce an updated or posterior expert opinion (Giudici, 2005).  In the Bayesian analysis, a parameter is treated as a random variable whose uncertainty is modeled by a probability distribution (Giudici, 2005). This distribution is the expert’s prior distribution p(q), stated in the absence of the sampled data (Giudici, 2005).  The likelihood is the distribution of the sample, conditional on the values of the random variable q: p(x|q) (Giudici, 2005).  The Bayes’ rule provides an algorithm to update the expert’s opinion in the light of the data, producing the so-called posterior distribution p(x|q), as shown in equation (2) below (Giudici, 2005).  With c = p(x), a constant that does not depend on the unknown parameter (q).

The posterior distribution represents the main Bayesian inferential tool (Giudici, 2005).  Once it is obtained, it is easy to obtain any inference of interest (Giudici, 2005).  For instance, to obtain a point estimate, a summary of the posterior distribution is taken, such as the Mean or the Mode (Giudici, 2005).  Similarly, confidence intervals can be easily derived by taking any two values of q such the probability of q belonging to the interval described by those two values corresponds to the given confidence level (Giudici, 2005).  As q is a random variable, it is now correct to interpret the confidence level as a probabilistic statement: (1 – α ) is the coverage probability of the interval, namely, the probability that q assumes values in the interval (Giudici, 2005). Thus, the Bayesian approach is thus described to be a coherent and flexible procedure (Giudici, 2005).

Special Case of Bayesian Estimates; Maximum Likelihood Estimator (MLE)

The MLE is a special case of Bayesian estimates, when the assumption as a prior distribution for q a constant distribution expressing a vague state of prior knowledge, the posterior mode is equal to the MLE (Giudici, 2005).  More generally, when a large sample is considered, the Bayesian posterior distribution approaches an asymptotic normal distribution, with the MLE as expected value (Giudici, 2005).

Bayesian Statistics

In the Bayesian Statistics, there is a four-step process (O’Hagan, 2004).  The first step is to create a statistical model to link data to parameters.  The second step is to formulate prior information about parameters.  The third step is to combine the two sources of information using Bayes’ theorem. The last step is to use the result posterior distribution to derive inferences about parameters (O’Hagan, 2004). Figure 1 illustrates the synthesis of the information by Bayes’ theorem. 

Figure 1.  Synthesis of the Information by Bayes’ Theorem (O’Hagan, 2004).

Figure 2 illustrates Bayes’ Theorem using a “triplot,” in which the prior distribution, likelihood and posterior distribution are all plotted on the same graph.  The prior information is represented by the dashed line lying, in this example, lying between -4 and +4.  The data with the dotted line represents the likelihood which favors the values of the parameters between 0 and 3, and strongly argue against any value below -2 or above +4 (O’Hagan, 2004).  The posterior is represented as solid line putting these two sources of information together (O’Hagan, 2004).  Thus, for values below -2, the posterior density is minimal because the data are saying that these values are highly implausible, while values above +4 are ruled out by the prior (O’Hagan, 2004).  While the data favor values around 1.5, the prior prefers values around 0, the posterior listens to both and the synthesis is a compromise, and the parameter is most likely to be around 1 (O’Hagan, 2004).

Figure 2.  Triplot. Prior Density (dashed), Likelihood (dotted), and Posterior Density (solid) (O’Hagan, 2004).

Bayes Assumption, Naïve Bayes, and Bayes Classifier

Any joint distribution can be simplified by making appropriate independence assumptions, essentially approximating a full table of probabilities by-products of much smaller tables (Hand et al., 2001).  At an extreme, an assumption can be made that all the variables are conditionally independent.  Such assumption is sometimes referred to as the Naïve Bayes or first-order Bayes assumption (Alexander & Wang, 2017; Baştanlar & Özuysal, 2014; Hand et al., 2001; Suguna, Sakthi Sakunthala, Sanjana, & Sanjhana, 2017).  The conditional independence model is linear in the number of variables (p) rather than being exponential (Hand et al., 2001).  To use the model for classification, the product form is simply used for the class-conditional distributions, yielding the Naïve Bayes classifier (Hand et al., 2001). The reduction in the number of parameters by using the Naïve Bayes model comes at a cost as an extreme independence assumption is made (Hand et al., 2001).  In some cases, the conditional independence assumption can be made quite reasonable (Hand et al., 2001).  In many practical cases, the conditional independence assumption may not be realistic (Hand et al., 2001).  Although the independence assumption may not be a realistic model of the probabilities involved, it may still permit relatively accurate classification performance (Hand et al., 2001). 

The Naïve Bayes model can easily be generalized in many different directions (Hand et al., 2001).  The simplicity, parsimony, and interpretability of the Naïve Bayes model have led to its widespread popularity, particularly in the machine learning literature (Hand et al., 2001).  The model can be generalized equally well by including some but not all dependencies beyond first-order (Hand et al., 2001).  However, the conventional wisdom in practice is that such additions to the model often provide only limited improvements in classification performance on many data sets, underscoring the difference between building accurate density estimators and building good classifiers (Hand et al., 2001).

Markov Chain Monte Carlo (MCMC) vs. Bayesian Analysis

Computing tools were explicitly developed for Bayesian analysis which is more powerful than anything available for frequentist methods, in the sense that Bayesians can now tackle enormously intricate problems that frequentists methods cannot begin to address (O’Hagan, 2004).  The advent of MCMC methods in the early 1990s served to emancipate the implementation of the Bayesian analysis (Allenby, Bradlow, George, Liechty, & McCulloch, 2014). 

The transformation is continuing, and computational developments are shifting the balance consistently in favor of Bayesian methods (O’Hagan, 2004).  MCMC is a simulation technique, whose concept is to by-pass the mathematical operations rather than to implement them (O’Hagan, 2004).  The Bayesian inference is solved by randomly drawing a sizeable simulated sample from the posterior distribution (O’Hagan, 2004).  The underlying concept of the Bayesian inference is that a sufficiently large sample from any distribution can represent the whole distribution effectively (O’Hagan, 2004).

Bayesian Analysis Application

The Bayesian principle methods are not the tools of choice in many application areas (O’Hagan, 2004).  Bayes’ Theorem has been applied to and proven useful in various disciplines and contexts such as German Enigma code during World War II, saving millions of lives (Fischetti et al., 2017).  Furthermore, An essential application of Bayes’ rule arises in the predictive classification problems (Giudici, 2005).  Bayesian analyses applied to market science problems have become increasingly popular due to their ability to capture individual-level customer heterogeneity (Allenby et al., 2014).  The Big Data is promoting the collection and archiving of an unprecedented amount of data (Allenby et al., 2014).  The marketing industry is convinced that there is gold in such Big Data (Allenby et al., 2014).  Big Data is described as discrete, and as huge because of its breadth and not because of its depth (Allenby et al., 2014).  It provides significant amounts of shallow data which does not reveal the state of the respondent, and the state of the market (Allenby et al., 2014).  The Bayesian methods are found to be useful in marketing analysis because of their ability to deal with large, shallow datasets and their ability to produce exact, finite sample inference (Allenby et al., 2014).

The pharmaceutical industry is another example of the use of Bayesian methods.  The pharmaceutical companies are regularly forced to abandon drugs that have just failed to demonstrate beneficial effects in frequentist terms, while the Bayesian analysis suggests that it would be worth persevering (O’Hagan, 2004).  The DNA is another example of the use of Bayesian analysis (O’Hagan, 2004).  Other applications of Bayesian methods include fraud detection (Bolton & Hand, 2002), social networks (Rodriguez, 2012).

Bayesian Analysis Software

There is a growing range of software available to assist with Bayesian analysis (O’Hagan, 2004).  Two particular software packages which are in general use, freely available: First Bayes and WinBUGS (O’Hagan, 2004).

The First Bayes is an elementary program which is aimed at helping the beginner to learn and understand how Bayesian methods work (O’Hagan, 2004).  The WinBUGS is a robust program for carrying out MCMC computations and is in widespread use for serious Bayesian analysis (O’Hagan, 2004).

Advantages and Disadvantages of Bayesian Analysis

Bayesian methods and classical methods both have advantages and disadvantages, and there are some similarities (sas.com, n.d.)  When the sample size is large, Bayesian inference often provides results for parametric models which are very similar to the results produced by frequentist methods (sas.com, n.d.).  Bayesian Analysis has the following five advantages:

  • It provides a natural and principled technique of combining prior information with data, within a solid decision theoretical framework.  Thus, past information about a parameter can be incorporated to form a prior distribution for future analysis.  When new observations are available, the previous posterior distribution can be used as a prior.  All inferences logically follow from the Bayes’ Theorem (sas.com, n.d.).
  • It provides inferences which are conditional on the data and are precise, without reliance on the asymptotic approximation.  Small sample inference proceeds in the same manner as if one had a large sample.  The Bayesian analysis can also estimate any functions of parameters directly, without using the “plug-in” method, which is a way to estimate functionals by plugging the estimated parameters in the functionals (sas.com, n.d.).
  • It adheres to the likelihood principle.  If two distinct sampling designs yield proportional likelihood functions for q, then all inferences about q should be identical from these two designs.  The classical inference does not adhere to the likelihood principle in general (sas.com, n.d.).
  • It provides interpretable answers, such as “the true parameter q  has a probability of 0.95 of falling in a 95% credible interval” (sas.com, n.d.).
  • It provides a convenient setting for a wide range of models, such as hierarchical models and missing data problems (sas.com, n.d.).    

Bayesian Analysis also has the following disadvantages:

  • It does not tell how to select a prior.  There is no correct method to choose a prior. Bayesian inferences require skills to translate subjective prior beliefs into a mathematically formulated prior, which can generate misleading results if done with no caution (sas.com, n.d.).
  • It can produce posterior distributions which are heavily influenced by the priors.  From a practical point of view, subject matter experts might disagree with the validity of the chosen prior (sas.com, n.d.).
  • If often comes with a high computational cost, especially in models with a large number of parameters.  Also, simulations provide slightly different answers unless the same random seed is used.   However, the slight variations in simulation results do not contradict the claim that the Bayesian inferences are precise or exact, because the posterior distribution of a parameter is exact, given the likelihood function and the priors, while simulation-based estimates of posterior quantities can vary due to the random number generator used in the procedures (sas.com, n.d.).

References

Alexander, C., & Wang, L. (2017). Big data analytics in heart attack prediction. The Journal of Nursing Care, 6(393).

Allenby, G. M., Bradlow, E. T., George, E. I., Liechty, J., & McCulloch, R. E. (2014). Perspectives on Bayesian Methods and Big Data. Customer Needs and Solutions, 1(3), 169-175.

Baştanlar, Y., & Özuysal, M. (2014). Introduction to machine learning miRNomics: MicroRNA Biology and Computational Analysis (pp. 105-128): Springer.

Bolton, R. J., & Hand, D. J. (2002). Statistical fraud detection: A review. Statistical Science, 235-249.

Fischetti, T., Mayor, E., & Forte, R. M. (2017). R: Predictive Analysis: Packt Publishing.

Giudici, P. (2005). Applied data mining: statistical methods for business and industry: John Wiley & Sons.

Hand, D. J., Mannila, H., & Smyth, P. (2001). Principles of data mining.

O’Hagan, A. (2004). Bayesian statistics: principles and benefits. Frontis, 31-45.

Rodriguez, A. (2012). Modeling the dynamics of social networks using Bayesian hierarchical blockmodels. Statistical Analysis and Data Mining: The ASA Data Science Journal, 5(3), 218-234.

sas.com. (n.d.). Bayesian Analysis: Advantages and Disadvantages. Retrieved from https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_introbayes_sect006.htm.

Suguna, M., Sakthi Sakunthala, N., Sanjana, S., & Sanjhana, S. (2017). A Survey on Prediction of Heart Diseases Using Big Data Algorithms.

Quantitative Analysis of the “German.Credit” Dataset Using Logistic Regression

Dr. O. Aly
Computer Science

Abstract

The purpose of this project is to analyze the German Credit dataset. The project is divided into two main Parts.  Part-I evaluates and examines the DataSet for understanding the Dataset using the RStudio.  Part-I involves six significant tasks.  Part-II discusses the Pre-Data Analysis, by converting the Dataset to Data Frame, involving four significant tasks to analyze the Data Frames.   Although the project analyzes three significant models including Standards Linear Regression, Multiple Linear Regression, the  Logistic Regression is the emphasis of this project.  The result shows that the duration, amount, installment and rent show positive coefficient values indicating that they have a positive impact on the probability of the dependent binary outcome (Default).  As the p-value is much less than 0.05 for duration, amount, installment, history, purpose for used car, goods, repair, and business, and rent, we reject the null hypotheses that there is no significance of the parameter to the model and accept the alternate hypotheses that there is significance of the parameter to the model.  The p-value for the age is (p=0.05) indicating that we accept the null hypothesis that there is no significance of the parameter to the model.  The p-value for (purpose) of education is > 0.05 indicating that we accept the null hypothesis that there is no significance of the parameter to the model.  The performance of the Logistic Regression model for the test dataset shows that the Logistic Regression recognizes 23 of the 28 Defaults (82%) and predicts the defaults 42 of the 72 good loans (58%). 

Keywords: German-Credit Dataset; Regression; Logistic Regression Analysis Using R.

Introduction

This project examines and analyze the dataset of (german.credit.csv).  The dataset is downloaded from the following archive site for machine learning repository:

https://archive.ics.uci.edu/ml/datasets/Statlog+(German+Credit+Data).

The dataset has 1000 obeservation on 22 variables. There are two datasets for german.credit.csv.  The original dataset, in the form provided by Professor Hofmann, contains categorical/symbolic attributes and is in the current german.credit.csv file which is used in this project.  The other dataset “german.data-numeric” is not used in this project which was developed by Strathclyde University for algorithms that need numerical attributes.  This project utilized the original version of german.credit.csv which has categorical variables, because these categorical variables will be transformed during the analysis process to generate various models including linear models, and logistic model.

There are two Parts for this project.  Part-I addresses five tasks to examine and understand the dataset using R before the analysis as follows:

  • Task-1: Review the Variables of the Dataset
  • Task-2: Understand the Dataset using names(), head(), and dim() functions
  • Task-3: Pre and Post Factor and Level of Categorical Variables of the Dataset.
  • Task-4: Summary and Plot the Continuous Variables: Duration, Amount, and Installment
  • Task-5: Classify Amount into Groups.
  • Task-6: Summary of all selected variables.

Part-II address the analysis using R. Part-II includes seven tasks include the following. These seven tasks are followed by the discussion and analysis of the results. 

  • Task-1: Select and Plot Specific Variables for this Project.
  • Task-2:  Model-1:  Linear Regression – single variable, and Diagnostic Analysis.
  • Task-3:  Model-3:  Multiple Regression Analysis
  • Task-4:  Discussion and Analysis.

There is an assumption that, on average, lending into default is five times as costly as not lending to a good debtor (default=success=0, no default=failure=1).  The default is defined as “success,” while no defaulting on a loan is defined as “failure.”   If a certain (p) for the probability of default is estimated, the expected costs are 5p, assuming the bank makes the loan, and 1(1-p) if the bank refuses to make the loan. Thus, if 5p < 1-p, the bank can expect to lose less by making the loan than by turning away business.  The following decision rule can be implied: make the loan if the probability of default p < 1/6.  The prediction of Default (Success) is to implemented whenever p > 1/6.

This project analyuze the German Credit dataset.  The two expected outcomes are success (defaulting on the loan), and failure (not defaulting on the loan).  This project implements three models, Linear Regression, Multiple Linear Regression.  However, the emphasis of this project is on the Logistic Regression (Model-3) to estimate the probability of default, using continuous variables (duration, amount, installment, age), and categorical variables (loan history, purpose, rent) as explanatory variables (independent variables).

Various resources were utilized to develop the required code using R. These resources include (Ahlemeyer-Stubbe & Coleman, 2014; Fischetti, Mayor, & Forte, 2017; Ledolter, 2013; r-project.org, 2018).

Part-I:  Understand and Examine the Dataset “german.credit.csv”

Task-1:  Review the Variables of the Data Sets

The purpose of this task is to understand the variables of the dataset.  The dataset is “german.credit” dataset.  The dataset describes the clients who can default on a loan.  There are selected variables out of the 22 variables which are target for this project.  Table 1 and Table 2 summarize these selected variables for this project.  Table 1 focuses on the variables with binary and numerical values, while Table 2 focuses on the variables with categorical values.

Table 1:  Binary (Default) and Continuous (Numerical) Variables

Table 2: Categorical Variables.

Task-2:  Load and Understand the Data Sets Using names(), head(), dim() functions.

            The purpose of this task is to load and understand the data set using names(), head(), and dim() functions as shown in the code below.

  • gc <- read.csv(“C:/CS871/german.credit.csv”)
  • names(gc)
  • head(gc)
  • dim(gc)
  • gc[1:3,]

Task-3:  Pre and Post Factor and Level of Categorical Variables of the Data Sets

            The purpose of this task is to factor and level all categorical variables and show the result pre- and post this process as shown in the code and snapshots below.

  • ### history categorical variable pre and post factor and level.
  • summary(gc$history)
  • plot(gc$history, col=”green”, xlab=”History Categorical Variable Pre Factor and Level”)
  • gc$history = factor(gc$history, levels=c(“A30”, “A31”, “A32”, “A33”, “A34”))
  • levels(gc$history)=c(“good-others”, “good-thisBank”, “current-paid-duly”, “bad-delayed”, “critical”)
  • summary(gc$history)
  • plot(gc$history, col=”green”, xlab=”History Categorical Variable Post Factor and Level”)

Figure 1. Pre and Post Factor and Level of History Categorical Variable.

  • ##### purpose pre and post factor and level
  • summary(gc$purpose)
  • plot(gc$purpose, col=”darkgreen”)
  • ###tranform purpose
  • gc$purpose <- factor(gc$purpose, levels=c(“A40″,”A41″,”A42″,”A43″,”A44″,”A45″,”A46″,”A48″,”A49″,”A410”))
  • levels(gc$purpose) <- c(“newcar”,”usedcar”,”furniture/equipment”,”radio/television”,”domestic appliances”,”repairs”, “edu”,”vacation-doesNotExist”, “retraining”, “business”, “others”)
  • summary(gc$purpose)
  • plot(gc$purpose, col=”darkgreen”)

Figure 2. Pre and Post Factor and Level of Purpose Categorical Variable.

  • ### housing categorical variable pre and post factor and level.
  • summary(gc$housing)
  • gc$rent <- factor(gc$housing==”A151″)
  • summary(gc$rent)
  • ##### housing categorical variable pre and post factor and level
  • summary(gc$housing)
  • plot(gc$housing, col=”orange”)
  • gc$housing <- factor(gc$housing, levels=c(“A151”, “A152”, “A153”))
  • levels(gc$housing) <- c(“rent”,”own”,”for free”)
  • summary(gc$housing)

Figure 3. Pre and Post Factor and Level of Housing Categorical Variable.

 Task-4:  Summary & Plot the Numerical Variables: Duration, Amount, Installment, & Age.

            The purpose of this task is to obtain the summary of the numerical variables: duration, amount, installment and age and plot the result.

  • ##summary and plot of those numerical variables
  • summary(gc$duration)

Figure 4. Duration Plot as a Numerical and Continous Variable.

  • summary(gc$amount)
  • plot(gc$amount, col=”blue”, main=”Amount Numerical Variable”)

Figure 5. Amount Plot as a Numerical and Continous Variable.

  • summary(gc$installment)
  • plot(gc$installment, col=”blue”, main=”Installment Numerical Variable”)

Figure 6. Installment Plot as a Numerical and Continous Variable.

  • summary(gc$age)
  • plot(gc$age, col=”blue”, main=”Age Numerical Variable”)

Figure 7.  Age Plot as a Numerical and Continous Variable.

Task-5:  Classify the Amount into Groups

            The purpose of this task is to classify the amount into groups as shown below.

  • #### To classify the amount into groups
  • gc$amount <-as.factor(ifelse(gc$amount <=2500, ‘0-2500′, ifelse(gc.df$amount<=5000,’2600-5000’, ‘5000+’)))
  • summary(gc$amount)

Task-6:  Summary of all variables

The purpose of this task is to obtain the result of all required variables.

  • summary(gc$duration)
  • summary(gc$amount)
  • summary(gc$installment)
  • summary(gc$age)
  • summary(gc$history)
  • summary(gc$purpose)
  • summary(gc$housing)
  • summary(gc$rent)

Part-II: Plots, Discussion and Analysis

Task-1:  Select and Plot specific variables for this project

            The purpose of this task is to select the specific required variable and plot them into one single diagram.

  • ##for demonstration, cut the dataset to these selected variables
  • ##(duration, amount, installment, and age) which are numeric and
  • ##(history, purpose and housing) which are categorical and
  • ## Default (representing the risk) which is binary.
  • gc.sv <- gc[,c(“Default”, “duration”, “amount”, “installment”, “age”, “history”, “purpose”, “foreign”, “housing”)]
  • gc.sv[1:3,]
  • summary(gc.sv)
  • plot(gc.sv, col=”red”)
  • ### Setting the Rent
  • gc$rent <- factor(gc$housing==”A151″)
  • summary(gc$rent)

Figure 8.  Plot of all Selected Variables.

Task-2: Model-1: Linear Regression – single variable, and Diagnostic Analysis

                The purpose of this task is to implement Model-1 for Linear Regression using one variable (History) as a factor for the Default.

  • # to get a plot of the Default as dependent and history as independent
  • plot(Default~history, data=gc, col=”darkred”)
  • ##calculate the mean first – but no mean because of NA
  • mean(gc$Default)
  • # to check the NA values
  • gc$Default
  • ##we have to remove null values
  • mean(gc$Default, na.rm=T)
  • ##get the mean without NA values
  • mean.Default=mean(gc$Default,na.rm=T)
  • ## plot again after removing the NA value
  • plot(Default~history, data=gc, col=”darkred”, main=”Default and History Effect”)
  • #put horizontal line at the mean
  • abline(h=mean.Default)
  • #use lm to fit a regression line through these data:
  • model1.Default.history = lm(Default ~ history, data=gc)
  • model1.Default.history
  • abline(model1.Default.history, col=”yellow”)
  • plot(model1.Default.history)
  • # to see the effect of solar
  • termplot(model1.Default.history)
  • #summary
  • summary(model1.Default.history)

Figure 9.  Model-1: Linear Regression Using the Mean Line (black).

Figure 10.  Model-1: Linear Regression Using Regression Line (yellow).

Figure 11.  Model-1: Four Diagnostic Plots For Standard Linear Regression.

Task-3: Model-2: Multiple Regressions Analysis

            The purpose of this task is to implement Model-2 for Multiple Regressions including the Purpose, History, Installment, Housing, Amount, Duration, Age which can influence the Default as dependent variable.

  • #Find relationship between multiple variables
  • ##purpose on Default conditioned with history.
  • coplot(Default~purpose|history, panel=panel.smooth, gc)  
  • ##rent on Default conditioned with history.
  • coplot(Default~rent|history, panel=panel.smooth, gc)  
  • ##housing on Default conditioned with history.
  • coplot(Default~housing|history, panel=panel.smooth, gc)  

Figure 12.  Model-2: Multiple Linear Regression Using Purpose, Housing, Rent, conditioned with History as factors influencing Default.

  • ##amount on Default conditioned with duration.
  • coplot(Default~amount|duration, panel=panel.smooth, gc)  
  • ##installment on Default conditioned with duration.
  • coplot(Default~installment|duration, panel=panel.smooth, gc)
  • ##age on Default conditioned with duration.
  • coplot(Default~age|duration, panel=panel.smooth, gc)  

Figure 13.  Model-2: Multiple Linear Regression Using Amount, Duration as Factors influencing Default.

Task-3: Model-3:  Logistic Regression Analysis

            The purpose of this task is to implement the Logistic Regression Analysis.

  • summary(gc)
  • ###Create a Design Matrix
  • ##Factor variables are turned into indicator variables
  • ##The first column of ones is ommitted
  • Xgc <- model.matrix(Default~.,data=gc)[,-1]
  • Xgc[1:3,]
  • ## Create training and prediction datasets
  • ## Select 900 rows for estimation and 100 for testing
  • set.seed(1)
  • train <- sample(1:1000,900)
  • xtrain <- Xgc[train,]
  • xnew <- Xgc[-train,]
  • ytrain <- gc$Default[train]
  • ynew <- gc$Default[-train]
  • gcglm=glm(Default~.,family=binomial,data=data.frame(Default=ytrain,xtrain))
  • summary(gcglm)
  • plot(gcglm, col=”blue”)
  • coef(gcglm)

Figure 14.  Model-3: Logistic Regression: Diagnostic Analysis: Residuals v. Fitted.

Figure 15.  Model-3: Logistic Regression: Diagnostic Analysis: Normal Q-Q.

Figure 16.  Model-3: Logistic Regression: Diagnostic Analysis: Scale-Location.

Figure 17.  Model-3: Logistic Regression: Diagnostic Analysis: Residuals vs. Leverage.

  • ## Now to prediction: what are the underlying default probabilities
  • ## for cases in the test set
  • ptest <- predict(gcglm, newdata=data.frame(xnew),type=”response”)
  • data.frame(ynew,ptest)
  • ## Using probability cutoff 1/6
  • ## coding as 1 (predicting default) if probability 1/6 or larger
  • probability.one.sixth=floor(ptest+(5/6))
  • probability1=table(ynew,probability.one.sixth)
  • probability1
  • error=(probability1[1,2]+probability1[2,1])/100
  • error
  • ### Binary Classification, Using Probabiillties to make decision, sensitivity and specificity,
  • ### Cut 1/6
  • cut=1/6
  • true.positive <- ynew==1 & ptest >= cut
  • true.positive
  • true.negative <- ynew==0 & ptest < cut
  • true.negative
  • # Sensitivity (predict default when it does happen)
  • sum(true.positive)/sum(ynew==1)
  • # Specificity (predict no default when it does not happen)
  • sum(true.negative)/sum(ynew==0)
  • ## Using probability cutoff 1/2
  • ## coding as 1 if probability 1/2 or larger
  • cut=1/2
  • probability.half=floor(ptest+(1/2))
  • probability2=table(ynew,probability.half)
  • probability2
  • error=(probability2[1,2]+probability2[2,1])/100
  • error
  • true.positive <- ynew==1 & ptest >=cut
  • true.negative <- ynew==0 & ptest < cut
  • # Sensitivity (predict default when it does happen)
  • sum(true.positive)/sum(ynew==1)
  • # Specificity (predict no default when it does not happen)
  • sum(true.negative)/sum(ynew==0)
  • ## R macro for plotting the ROC curve
  • ## plot the ROC curve for classification of y with p
  • roc <- function(p,y){
  • y <- factor(y)
  • n <- length(p)
  • p <- as.vector(p)
  • Q <- p > matrix(rep(seq(0,1,length=500),n),ncol=500,byrow=TRUE)
  • fp <- colSums((y==levels(y)[1])*Q)/sum(y==levels(y)[1])
  • tp <- colSums((y==levels(y)[2])*Q)/sum(y==levels(y)[2])
  • plot(fp, tp, xlab=”1-Specificity”, ylab=”Sensitivity”)
  • abline(a=0,b=1,lty=2,col=8)
  • }
  • ###### ROC for hold-out period
  • roc(p=ptest,y=ynew)
  • ## ROC for all cases (in-sample)
  • gcglmall <- glm(gc$Default ~ Xgc,family=binomial)
  • roc(p=gcglmall$fitted, y=gcglmall$y)
  • ## using the ROCR package to graph the ROC curves
  • library(ROCR)

Figure 18.  Model-3: Logistic Regression: Sensitivity and Specificity for a sample of the data.

Figure 19.  Model-3: Logistic Regression: Sensitivity and Specificity for All the data.

  • ## input is a data frame consisting of two columns
  • ## predictions in first column and actual outcomes in the second
  • ## ROC for hold-out period
  • predictions=ptest
  • labels=ynew
  • data=data.frame(predictions,labels)
  • data
  • ## prediction1: function to create prediction objects
  • prediction1 <- prediction(data$predictions,data$labels)
  • prediction1
  • ## perf: creates the input to be plotted
  • ## sensitivity and one minus specificity (the false positive rate)
  • performance <- performance(prediction1, “sens”, “fpr”)
  • performance
  • plot(performance)

Figure 20.  Model-3: Logistic Regression: ROC for specifc cases.

  • ## ROC for all cases (in-sample)
  • gcglmall <- glm(gc$Default ~ Xgc,family=binomial)
  • predictions=gcglmall$fitted
  • labels=gcglmall$y
  • data=data.frame(predictions,labels)
  • prediction2 <- prediction(data$predictions,data$labels)
  • performance2 <- performance(prediction2, “sens”, “fpr”)
  • plot(performance2)

Figure 21.  Model-3: Logistic Regression: ROC for all cases.

Task-4:  Discussion and Analysis

The descriptive analysis of the history (Figure 1) shows that the existing credits paid back duly till now are ranked number one of 530, followed by the critical account of 293, followed by the category of delay in paying off in the past of 88.  The category of all credits at this bank paid back duly include only 49 and no credits taken or all credits paid back duly has only 40.  The descriptive analysis of the purpose (Figure 2) shows that the radio/TV of 280 ranks number one in the loan, followed by the new car category of 234, followed by the furniture/equipment of 181, and used car of103.  The business and education have 97 and 50 respectively, while the repairs, appliances, retaining and others have the least rank for loans. The descriptive analysis of the housing (Figure 3) shows that the own (Own=713) ranks number one for those who receive loans, followed by the rent (Rent=179).  The category of “free” housing (Free=108) ranks the last for receiving loans.  The descriptive analysis of the duration (Figure 4) shows that the duration average (Mean=21) is higher than the Median duration in a month (Median=18), indicating a positively skewed distribution.  The maximum duration has the value of 72 months, while the minimum duration for the loan is four months.  Most of the duration periods are up to 60 months.  There is an outlier of the duration period of ~70 months as illustrated in Figure 4.  The descriptive analysis of the amount (Figure 5) shows that the average amount of the loan (Mean=3271), is higher than the Median amount of the loan (Median=2320) indicating a positively skewed distribution.  The maximum amount for a loan is 18424, while the minimum amount is 250.  Most loans have the amount of ~5000, followed by the amount of 10,000-15,000.  There is an outlier of a loan amount above 15,000 as illustrated in Figure 5.  The descriptive analysis of the installment (Figure 6) shows that average installment (Mean=2.98) is higher than the Median installment (Median=1.00) indicating a positively skewed distribution.  The maximum installment rate is 4.00, while the minimum installment has a rate of 1.00.  The installment rates as illustrated in (Figure 6) are categorized between 1.00, 2.00, 3.00 and 4.00. The descriptive analysis of the age (Figure 7) shows that the average age (Mean=36) which is higher than the Median age (Median=33) indicating a positively skewed distribution.  The maximum age is 75, while the minimum age is 19.  As illustrated in Figure 7, most of the age is from ~20 to 50, with few densities from 50 to 60 and the fewest density is above 60 and 70.  

The Linear Regression is the first model (Model-1) is implemented on the (history) explanatory variable over the default.  The mean (Mean=3) is plotted in Figure 9 of the Linear Regression of history over the default.  Another line is plotted in Figure 10 is illustrated the Linear Regression using the Regression Line.  The result shows that there is a negative relationship between the Default (success) and the history.  The bad history shows the success in defaulting on a loan. The diagnostic plots of the standard regression are also discussed in this project. Figure 11 illustrates four different diagnostic plots of the standard regression. This analysis also covers the residuals and fitted lines.  Figure 11 illustrated the Residuals vs. Fitted in Linear Regression Model for the History explanatory variable as a function of the Default.  The residuals depict the difference between the actual value of the response variable and the response variable predicted using the regression equation (Hodeghatta & Nayak, 2016). The principle behind the regression line and the regression equation is to reduce the error or this difference (Hodeghatta & Nayak, 2016).  The expectation is that the median value should be near zero (Hodeghatta & Nayak, 2016).  For the model to pass the test of linearity, no pattern in the distribution of the residuals should exist (Hodeghatta & Nayak, 2016).  Where there is no pattern in the distribution of the residuals, it passes the condition of linearity (Hodeghatta & Nayak, 2016). The plot of the fitted values against the residuals with the line shows the relationship between the two. The horizontal and straight line indicates that the “average residual” for all “fitted values” it is more or less the same (Navarro, 2015).  The result of the Linear Regression for the identified variables of History and Default shows that the residual has a curved pattern, indicating that a better model can be obtained using the quadratic term because ideally, this line should be a straight horizontal line.  Figure 11 also illustrates the Normal QQ plot, which is used to test the normality of the distribution (Hodeghatta & Nayak, 2016).  The residuals are not on the straight line, indicating that the residuals are not normally distributed. Hence, the normality test of the residuals did not pass, as it is supposed to be a straight line for the residuals to pass.  Figure 11 also illustrates the Scale-Location graph, which is one of the graphs generated as part of the plot. The points are spread in a random fashion around the horizontal line but not equally the line.  If the horizontal line with equally randomly spread points, the result could indicate that the assumption of constant variance of the errors or homoscedasticity is fulfilled (Hodeghatta & Nayak, 2016).  Thus, it is not fulfilled in this case.  Figure 11 also illustrates the Residuals vs. Leverage Plot generated for the Linear Regression Model. In this plot of Residuals vs. Leverage, the patterns are not as relevant as the case with the diagnostics plot of the Linear Regression. In this plot, the outlying values at the upper right corner or the lower right are watched (Bommae, 2015).  Those spots are the places where a case can be influential against a regression line (Bommae, 2015).  When cases are outside of the Cook’s distance, meaning they have high Cook’s distance scores, the cases are influential to the regression results (Bommae, 2015).  The Cook’s distance lines are (red dashed line) are far indicating there is no influential case.

The Multiple Linear Regression is the second Model.  Multiple variables such as purpose conditioned with history, rent conditioned with history, housing conditioned with history are used to implement the Multiple Regression models.  There are two most noticeable results (Figure 12).  The first noticeable result shows that the category of “good to other banks” that the default as success goes down when the loans are made for (purpose) of new car, furniture, radio/TV, domestic appliances, and repair, while the default as success goes up – meaning failure to default) with education, retraining, business and others.  The second noticeable result is illustrated in the category of “currently paid duly,” that the default as success goes down meaning the loan receiver default on the loan when the loan is made to the same categories as the first noticeable result, but until radio/TV, after which the default on loan will fail for (purpose) of domestic appliances, repair, education, retraining, business, and others.   The other Multiple Regression used the rent and free, the history shows a failure to default for the “good to others” category, while the own category shows success to default for the “current paid duly” category.   For the rent specific, the result shows that these specific categories, there no default on loan with the rent on both categories.  For the amount, installment and age conditioned with duration Multiple Regression models, the result shows that the loan 5000+, when the duration increases, the default failure increases, and when the duration decreases, the default failure decreases meaning there is a significant chance for defaulting on the loan. The same pattern shows when the installment increases, the default on a loan decreases.  The same pattern is also shown for the age, when the age increases, the default on the loan decreases.

The Logistic Regression Model (Model-3) is the emphasis of this project. The Logistic Regression is used to predict the probability of Default on loan based on other independent variables. In this case, the probability of the Default based on the identified required independent and explanatory variables of duration, amount, installment, age (continuous variables), history, purpose, and rent (categorical variables). 

A random selection of 900 of the 1000 cases is made for the Training set, and the remaining of 100 cases is made into the Test set.  The result shows the coefficient estimates, starting with a negative intercept (slope) of -2.705e-01 with a standard error of 4.833e-01, and the coefficient for each of these identified explanatory variables are also estimated.  The standard error of the coefficient estimates represents the accuracy of the coefficient. The larger the standard error, the less confident about the estimates.  The (z) value represents the z-statistic, which is the coefficient estimate divided by the standard error of the estimates.  The Pr(>|z|) is the last column in the result of the logistic analysis, where the p-value corresponding to the z-statistic.  The smaller the p-value, the more significant the estimates are.  One unit increase in duration (an increase in the number of duration by one) is associated with an increase of logarithm of the odds of the observation being Default.  As indicated in (Fischetti et al., 2017), if the coefficient is positive, it has a positive impact on the probability of the dependent variable, and if the coefficient is negative, it has a negative impact on the probability of the binary outcome (Default).  The age, history with poor and terrible, the purpose for used care, goods or repairs, education, and business, have negative coefficient values indicating that there is a negative impact on the probability of the binary outcome of the Default.  The duration, amount, installment and rent show positive coefficient values indicating that they have a positive impact on the probability of the dependent binary outcome (Default).  As the p-value is much less than 0.05 for duration, amount, installment, history, purpose for used car, goods, repair, and business, and rent, we reject the null hypotheses that there is no significance of the parameter to the model and accept the alternate hypotheses that there is significance of the parameter to the model.  The p-value for the age is (p=0.05) indicating that we accept the null hypothesis that there is no significance of the parameter to the model.  The p-value for (purpose) of education is > 0.05 indicating that we accept the null hypothesis that there is no significance of the parameter to the model.  The performance of the Logistic Regression model for the Test dataset shows that the Logistic Regression recognizes 23 of the 28 Defaults (82%) and predicts the defaults 42 of the 72 good loans (58%).  The coordinates of the sensitivity and specificity (sensitivity = 0.82, 1-specifictiy=0.58) define one point on the ROC curve (Figure 18).  The sensitivity = 8/28=0.29, and specificity =68/72=0.94 for another point on ROC curve (sensitivity = 0.29, 1-specificity=0.06) (Figure 19).  The ROC is calculated using various cutoff on the probability.  The ROC curves that assess the predictive quality of the classification rule on the holdout sample of 100 observations as shown in (Figure 18), and on the complete data set of all 1000 cases as shown in (Figure 19).  Specified values on sensitivity and specificity imply a certain value for the probability cutoff.  However, for certain data and models, no cutoff may achieve the given desires properties on sensitivity and specificity, implying that the desired sensitivity and specificity cannot be attained (Ledolter, 2013).

References

Ahlemeyer-Stubbe, A., & Coleman, S. (2014). A practical guide to data mining for business and industry: John Wiley & Sons.

Bommae, K. (2015). Understanding Diagnostic Plots of Linear Regression Analysis. Retrieved from https://data.library.virginia.edu/diagnostic-plots/.

Fischetti, T., Mayor, E., & Forte, R. M. (2017). R: Predictive Analysis: Packt Publishing.

Hodeghatta, U. R., & Nayak, U. (2016). Business Analytics Using R-A Practical Approach: Springer.

Ledolter, J. (2013). Data mining and business analytics with R: John Wiley & Sons.

Navarro, D. J. (2015). Learning statistics with R: A tutorial for psychology students and other beginners. R package version 0.5.

r-project.org. (2018). R: A Language and Environment for Statistical Computing. Retrieved from https://cran.r-project.org/doc/manuals/r-release/fullrefman.pdf.

Machine Learning: How Logistic Regression Is Used to Predict Categorical Outcome

Dr. O. Aly
Computer Science

Introduction

The purpose of this discussion is to discuss how the Logistic Regression used to predict the categorical outcome.  The discussion addresses the predictive power of categorical predictors of a binary outcome and whether the Logistic Regression should be used.  The discussion begins with an overall overview of variable types, business analytics methods based on data types and by market sector. The discussion then addresses how Logistic Regression is used when working with categorical outcome variable, and it ends with an example of Logistic Regression using R.  

Variables Types

Variables can be classified in various ways.  Variables can be categorical or continuous (Ary, Jacobs, Sorensen, & Walker, 2013).  When researchers classify subjects by sorting them into mutually exclusive groups, the attribute on which they base the classification is termed as a “categorical variables” (Ary et al., 2013).   Examples of categorical variables are home language, county of residence, father’s principal occupation, and school in which enrolled (Ary et al., 2013).  The simplest type of categorical variable has only two mutually exclusive classes and is called a “dichotomous variable” (Ary et al., 2013).  Male-Female, Citizen-Alien, and Pass-Fail are examples of the dichotomous variables (Ary et al., 2013).  Some categorical variables have more than two classes such as educational level, religious affiliation, and state of birth (Ary et al., 2013).  When the attribute has an “infinite” number of values with a range, it is a continuous variable (Ary et al., 2013).  Examples of continuous variables include height, weight, age, and achievement test scores (Ary et al., 2013). 

The most important classification of variables is by their use in the research under consideration when they are classified as independent variables or dependent variables (Ary et al., 2013).  The independent variables are antecedent to dependent variables and are known or are hypothesized to influence the dependent variable which is the outcome (Ary et al., 2013).  In experimental studies, the treatment is the independent variable, and the outcome is the dependent variable (Ary et al., 2013).  In a non-experimental study, it is often more challenging to label variables as independent or dependent (Ary et al., 2013).  The variable that inevitably precedes another one in time is called an independent variable (Ary et al., 2013).  For instance, in a research study of the relationship between teacher experience and students’ achievement scores, teacher experience would be considered as the independent variable (Ary et al., 2013).

Business Analytics Methods Based on Variable Types

The data types play a significant role in the employment of the analytical method.  As indicated in (Hodeghatta & Nayak, 2016), when the response (dependent) variable is continuous, and the predictor variables are either continuous or categorical, the Linear Regression, Neural Network, K-Nearest Neighbor (K-NN) methods can be used as detailed in Table 1. When the response (dependent) variable is categorical, and the predictor variables are either continuous or categorical, the Logistic Regression, K-NN, Neural Network, Decision/Classification Trees, Naïve Bayes can be used as detailed in Table 1.

Table-1: Business Analytics Methods Based on Data Types. Adapted from (Hodeghatta & Nayak, 2016).

Analytics Techniques/Methods Used By Market Sectors

In (EMC, 2015), the Analytic Techniques and Methods used are summarized in Table 2 by some of the Market Sectors.  These are examples of the application of these analytic techniques and method used.  As shown in Table 2, Logistic Regression can be used in Retail Business and Wireless Telecom industries. Additional methods are also used for different Market Sector as shown in Table 2.

Table 2.  Analytic Techniques/Methods Used by Market Sector (EMC, 2015).

Besides the above Market Sectors, Logistic Regression can also be used in Medical, Finance, Marketing and Engineering (EMC, 2015), while the Linear Regression can be used in Real Estate, Demand Forecasting, and Medical (EMC, 2015).

Predicting Categorical Outcomes Using Logistic Regression

The Logistic Regression model was first introduced by Berkson (Colesca, 2009; Wilson & Lorenz, 2015), who showed how the model could be fitted using iteratively reweighted least squares (Colesca, 2009).  Logistic Regression is widely used (Ahlemeyer-Stubbe & Coleman, 2014; Colesca, 2009) in social science research because many studies involve binary response variable (Colesca, 2009). Thus, in Logistic Regression, the target outcome is “binary,” such as YES or NO or the target outcome is categorical with just a few categories (Ahlemeyer-Stubbe & Coleman, 2014), while the Regular Linear Regression is used to model continuous target variables (Ahlemeyer-Stubbe & Coleman, 2014).  Logistic Regression calculates the probability of the outcome occurring, rather than predicting the outcome corresponding to a given set of predictors (Ahlemeyer-Stubbe & Coleman, 2014).  The Logistic Regression can answer questions such as: “What is the probability that an applicant will default on a loan?” while the Linear Regression can answer questions such as “What is a person’s expected income?” (EMC, 2015).  The Logistic Regression is based on the logistic function f(y), as shown in equation (1) (EMC, 2015).  

The expected value of the target variable from a Logistic Regression is between 0 and 1 and can be interpreted as a “likelihood” (Ahlemeyer-Stubbe & Coleman, 2014).  When y à¥, f(y) à1, and when y à¥, f(y) à0.  Figure 1 illustrates an example of the value of the logistic function f(y) varies from 0 to 1 as y increases using the Logistic Regression method (EMC, 2015).

Figure 1.  Logistic Function (EMC, 2015).

Because the range of f(y) is (0,1), the logistic function appears to be an appropriate function to model the probability of a particular outcome occurring (EMC, 2015).  As the value of the (y) increases, the probability of the outcome occurring increases (EMC, 2015).  In any proposed model, (y) needs to be a function of the input variables in any proposed model to predict the likelihood of an outcome (EMC, 2015).  In the Logistic Regression, the (y) is expressed as a linear function of the input variables (EMC, 2015).  The formula of the Logistic Regression is shown in equation (2) below, which is similar to the Linear Regression equation (EMC, 2015).  However, one difference is that the values of (y) are not directly observed, only the value of f(y) regarding success or failure, typically expressed as 1 or 0 respectively is observed (EMC, 2015).

Based on the input variables of x1, x2, …, xp-1, the probability of an event is shown in equation (3) below (EMC, 2015).

Using the (p) to denote f(y), the equation can be re-written as shown in equation (4) (EMC, 2015).  The quantity ln(p/p-1), in the equation (4) is known as the log odds ratio, or the logit of (p) (EMC, 2015).       

The probability is a continuous measurement, but because it is a constrained measurement, and it is bounded by 0 and 1, it cannot be measured using the Regular Linear Regression (Fischetti, 2015), because one of the assumptions in Regular Linear Regression is that all predictor variables must be “quantitative” or “categorical,” and the outcome  variables must be “quantitative,” “continuous” and “unbounded” (Field, 2013). The “quantitative” indicates that they should be measured at the interval level, and the “unbounded” indicates that there should be no constraints on the variability of the outcome (Field, 2013).  In the Regular Linear Regression, the outcome is below 0 and above 1 (Fischetti, 2015). 

The logistic function can be applied to the outcome of a Linear Regression to constrain it to be between 0 and 1, and it can be interpreted as a proper probability (Fischetti, 2015).  As shown in Figure 1, the outcome of the logistic function is always between 0 and 1. Thus, the Linear Regression can be adapted to output probabilities (Fischetti, 2015).  However, the function which can be applied to the linear combination of predictors is called “inverse link function,” while the function that transforms the dependent variable into a value that can be modeled using linear regression is just called “link function” (Fischetti, 2015).  In the Logistic Regression, the “link function” is called “logit function” (Fischetti, 2015).   The transformation logit (p) is used in Logistic Regression with the letter (p) to represent the probability of success (Ahlemeyer-Stubbe & Coleman, 2014).  The logit (p) is a non-linear transformation, and Logistic Regression is a type of non-linear regression (Ahlemeyer-Stubbe & Coleman, 2014).

There are two problems that must be considered when dealing with Logistic Regressions. The first problem is that the ordinary least squares of the Regular Linear Regression to solve for the coefficients cannot be used because the link function is non-linear (Fischetti, 2015).  Most statistical software solves this problem by using a technique called Maximum Likelihood Estimation (MLE) instead (Fischetti, 2015). Techniques such as MLE are used to estimate the model parameters (EMC, 2015). The MLE determines the values of the model parameters which maximize the chances of observing the given dataset (EMC, 2015).  

The second problem is that Linear Regression assumes that the error distribution is normally distributed (Fischetti, 2015).  Logistic Regression models the error distribution as a “Bernoulli” distribution or a “binomial distribution” (Fischetti, 2015).   In the Logistic Regression, the link function and error distributions are the logits and binomial respectively.  In the Regular Linear Regression, the link function is the identity function, which returns its argument unchanged, and the error distribution is the normal distribution (Fischetti, 2015).

Logistic Regression in R

The function glm() is used in R to perform Logistic Regression.  The error distribution and link function will be specified in the “family” argument.  The family argument can be family=”binomial” or family=binomial(). Example of the glm() using the births.df dataset.  In this example, we are building Logistic Regression using all available predictor variables on SEX gender (male, female).

References

Ahlemeyer-Stubbe, A., & Coleman, S. (2014). A practical guide to data mining for business and industry: John Wiley & Sons.

Ary, D., Jacobs, L. C., Sorensen, C. K., & Walker, D. (2013). Introduction to research in education: Cengage Learning.

Colesca, S. E. (2009). Increasing e-trust: A solution to minimize risk in e-government adoption. Journal of applied quantitative methods, 4(1), 31-44.

EMC. (2015). Data Science and Big Data Analytics: Discovering, Analyzing, Visualizing and Presenting Data. (1st ed.): Wiley.

Field, A. (2013). Discovering Statistics using IBM SPSS Statistics: Sage publications.

Fischetti, T. (2015). Data Analysis with R: Packt Publishing Ltd.

Hodeghatta, U. R., & Nayak, U. (2016). Business Analytics Using R-A Practical Approach: Springer.

Wilson, J. R., & Lorenz, K. A. (2015). Short History of the Logistic Regression Model Modeling Binary Correlated Responses using SAS, SPSS and R (pp. 17-23): Springer.

Overfitting and Parsimony in Large Dataset Analysis

Dr. O. Aly
Computer Science

Introduction:  The purpose of this discussion is to discuss the issues of overfitting versus using parsimony and their importance in Big Data analysis.  The discussion also addresses if the overfitting approach is a problem in the General Least Square Model (GLM) approach.  Some hierarchical methods which do not require parsimony of GLM are also discussed in this discussion. This discussion does not include the GLM as it was discussed earlier. It begins with Parsimony in Statistics model.

Parsimony Principle in Statistical Model

The medieval (14th century) English philosopher, William of Ockham (1285 – 1347/49) (Forster, 1998) popularized a critical principle stated by Aristotle “Entities must not be multiplied beyond what is necessary” (Bordens & Abbott, 2008; Epstein, 1984; Forster, 1998).  The refinement of this principle by Ockham is now called “Occam’s Razor” stating that a problem should be stated in the simplest possible terms and explained with the fewest postulates possible (Bordens & Abbott, 2008; Epstein, 1984; Field, 2013; Forster, 1998).  This method is now known as Law or Principle of Parsimony (Bordens & Abbott, 2008; Epstein, 1984; Field, 2013; Forster, 1998).  Thus, based on this law, a theory should account for phenomena within its domain in the simplest terms possible and with the fewest assumptions (Bordens & Abbott, 2008; Epstein, 1984; Field, 2013; Forster, 1998).  As indicated by (Bordens & Abbott, 2008), if there are two competing theories concerning a behavior, the one which explains the behavior in the simplest terms is preferred under the law of parsimony. 

Modern theories of the attribution process, development, memory, and motivation adhere to this law of parsimony (Bordens & Abbott, 2008).  However, the history of science witnessed some theories which got crushed under their weight of complexity (Bordens & Abbott, 2008). For instance, the collapse of interest in the Hull-Spence model of learning occurred primarily because the theory had been modified so many times to account for anomalous data that was no longer parsimonious (Bordens & Abbott, 2008).  The model of Hull-Spence became too complicated with too many assumptions and too many variables whose values had to be extracted from the very data that the theory was meant to explain (Bordens & Abbott, 2008).  As a result of such complexity, the interest in the theory collapsed and got lost.  The Ptolemaic Theory of planetary motion also lost its parsimony because it lost much of its true predictive power (Bordens & Abbott, 2008).

Parsimonious is one of the characteristics of a good theory (Bordens & Abbott, 2008).  Parsimonious explanation or a theory explains a relationship using relatively few assumptions (Bordens & Abbott, 2008). When more than one explanation is offered for observed behavior, scientists and researchers prefer the parsimonious explanation which explains behavior with the fewest number of assumptions (Bordens & Abbott, 2008). Scientific explanations are regularly evaluated and examined for consistency with the evidence and with known principles for parsimony and generality (Bordens & Abbott, 2008).  Accepted explanations can be overthrown in favor of views which are more general, more parsimonious, and more consistent with observation (Bordens & Abbott, 2008).

How to Develop Fit Model Using Parsimony Principle

When building a model, the researcher should strive for parsimony  (Bordens & Abbott, 2008; Field, 2013). The statistical implication of using a parsimony heuristic is that models be kept as simple as possible, meaning predictors should not be included unless they have the explanatory benefit (Field, 2013).  This strategy can be implemented by fitting the model that include all potential predictors, and then systematically removing any that do not seem to contribute to the model (Field, 2013).  Moreover, if the model includes interaction terms, then, the interaction terms to be valid, the main effects involved in the interaction term should be retained (Field, 2013).  Example of the implementation of Parsimony in developing a model include three variables in a patient dataset: (1) outcome variable (as cured or not cured), which is dependent variable (DV), (2) intervention variable, which is a predictor independent variable (IV), and (3) duration, which is another predictor independent variable (Field, 2013).  Thus, the three potential predictors can be Intervention, Duration and the interaction of the “Intervention x Duration” (Field, 2013).  The most complex model includes all of these three predictors.  As the model is being developed, any terms that are added but did not improve the model should be removed and adopt the model which did not include those terms that did not make a difference.  Thus, the first model (model-1) which the researchers can fit would be to have only Intervention as a predictor (Field, 2013).  Then, the model is built up by adding in another main effect of the Duration in this example as model-2.  The interaction of the Intervention x Duration can be added in model-3. Figure 1 illustrates these three models of development. The goal is to determine which of these models best fits the data while adhering to the general idea of parsimony (Field, 2013).   If the interaction term model-3 did not improve the model (model-2), then model-2 should be used as the final model.  If the Duration in model-2 did not make any difference and did not improve model-1, then model-1 should be used as the final model (Field, 2013).  The aim is to build the model systematically and choose the most parsimonious model as the final model.  The parsimonious representations are essential because simpler models tend to give more insight into a problem (Ledolter, 2013). 

Figure 1.  Building Models based on the Principle of Parsimony (Field, 2013).

Overfitting in Statistical Models

Overfitting is a term used when using models or procedures which violate Parsimony Principle, it means that the model includes more terms than are necessary or uses more complicated approaches than necessary (Hawkins, 2004).   There are two types of “Overfitting” methods.  The first “Overfitting” method is to use a model which is more flexible than it needs to be (Hawkins, 2004).  For instance, a neural net can accommodate some curvilinear relationships and so is more flexible than a simple linear regression (Hawkins, 2004). However, if it is used on a dataset that conforms to the linear model, it will add a level of complexity without any corresponding benefit in performance, or even worse, with poorer performance than the simpler model (Hawkins, 2004).  The second “Overfitting” method is to use a model that includes irrelevant components such as a polynomial of excessive degree or a multiple linear regression that has irrelevant as well as the needed predictors (Hawkins, 2004). 

The “Overfitting” technique is not preferred for four essential reasons (Hawkins, 2004).  The first reason involves wasting resources and expanding the possibilities for undetected errors in databases which can lead to prediction mistakes, as the values of these unuseful predictors must be substituted in the future use of the mode (Hawkins, 2004).  The second reason is that the model with unneeded predictors can lead to worse decisions (Hawkins, 2004).   The third reason is that irrelevant predictor can make predictions worse because the coefficients fitted to them add random variation to the subsequent predictions (Hawkins, 2004). The last reason is that the choice of model has an impact on its portability (Hawkins, 2004). The one-predictor linear regression that captures a relationship with the model is highly portable (Hawkins, 2004).  The more portable model is preferred over, the less portable model, as the fundamental requirement of science is that one researcher’s results can be duplicated by another researcher (Hawkins, 2004). 

Moreover, large models overfitted on training dataset turn out to be extremely poor predictors in new situations as needed predictor variables increase the prediction error variance (Ledolter, 2013).  The overparameterized models are of little use if it is difficult to collect data on predictor variables in the future.  The partitioning of the data into training and evaluation (test) datasets is central to most data mining methods (Ledolter, 2013). Researchers must check whether the relationships found in the training dataset will hold up in the future (Ledolter, 2013).

How to recognize and avoid Overfit Models

A model overfits if it is more complicated than another model that fits equally well (Hawkins, 2004).  The recognition of overfitting model involves not only the comparison of the simpler model and the more complex model but also the issue of how the fit of a model is measured (Hawkins, 2004).  Cross-Validation can detect overfit models by determining how well the model generalizes to other datasets by partitioning the data (minitab.com, 2015).  This process of cross-validation helps assess how well the model fits new observations which were not used in the model estimation process (minitab.com, 2015). 

Hierarchical Methods

The regression analysis types include simple, hierarchical, and stepwise analysis (Bordens & Abbott, 2008).  The main difference between these types is how predictor variables are entered into the regression equation which may affect the regression solution (Bordens & Abbott, 2008).  In the simple regression analysis, all predictors variables are entered together, while in the hierarchical regression, the order in which variables are entered into the regression equation is specified (Bordens & Abbott, 2008; Field, 2013).  Thus, the hierarchical regression is used for a well-developed theory or model suggesting a specific causal order (Bordens & Abbott, 2008). As a general rule, known predictors should be entered into the model first in order of their importance in predicting the outcome (Field, 2013).  After the known predictors have been entered, any new predictors can be added into the model (Field, 2013).  In the stepwise regression, the order in which variables are entered is based on a statistical decision, not on a theory (Bordens & Abbott, 2008).  

The choice of the regression analysis should be based on the research questions or the underlying theory (Bordens & Abbott, 2008).  If the theoretical model is suggesting a particular order of entry, the hierarchical regression should be used (Bordens & Abbott, 2008). Stepwise regression is infrequently used because sampling and measurement error tends to make unstable correlations among variables in stepwise regression (Bordens & Abbott, 2008).  The main problem with the stepwise methods is that they assess the fit of a variable based on the other variables in the model (Field, 2013).

Goodness-of-fit Measure for the Fit Model

Comparison between hierarchical and stepwise methods:  The hierarchical and stepwise methods involve adding predictors to the model in stages, and it is useful to know these additions improve the model (Field, 2013).  Since the larger values of R2 indicates better fit, thus, a simple way to see whether a model has improved as a result of adding predictors to it would be to see whether R2 for the new model is bigger than for the old model.  However, it will always get bigger if predictors are added, so the issue is more whether it gets significantly bigger (Field, 2013).  The significance of the change in R2 can be assessed using the equation below as the F-statistics is also be used to calculate the significance of R2 (Field, 2013) 

However, because the focus is on the change in the models, thus the change in R2  (R2 change)  and R2 of the newer model (R2 new) are used using the following equation (Field, 2013). Thus, models can be compared using this F-ratio (Field, 2013). 

The Akaike’s Information Criterion (AIC) method is a goodness-of-fit measure which penalizes the model for having more variables. If the AIC is bigger, the fit is worse; if the AIC is smaller, the fit is better (Field, 2013).   If the Automated Linear Model function in SPSS is used, then AIC is used to select models rather than the change in R2. AIC is used to compare it with other models with the same outcome variables; if it is getting smaller, then the fit of the model is improving (Field, 2013).  In addition to the AIC method, there is Hurvich and Tsai’s criterion (AICC), which is a version of AIC designed for small samples (Field, 2013).  Bozdogan’s criterion (CAIC), which is a version of AIC which is used for model complexity and sample size. Bayesian Information Criterion (BIC) of Schwarz, which is comparable to the AIC (Field, 2013; Forster, 1998). However, it is slightly more conservative as it corrects more harshly for the number of parameters being estimated (Field, 2013).  It should be used when sample sizes are large, and the number of parameters is small (Field, 2013).

The AIC and BIC are the most commonly used measures for the fit of the model.  The values of these measures are all useful as a way of comparing models (Field, 2013).  The value of AIC, AICC, CAIC, and BIC can all be compared to their equivalent values in other models.  In all cases, smaller values mean better-fitting models (Field, 2013).

There is also Minimum Description Length (MDL) measure of Rissanen, which is based on the idea that statistical inference centers around capturing regularity in data; regularity, in turn, can be exploited to compress the data (Field, 2013; Vandekerckhove, Matzke, & Wagenmakers, 2015).  Thus, the goal is to find the model which compresses the data the most (Vandekerckhove et al., 2015).   There are three versions of MDL: crude two-part code, where the penalty for complex models is that they take many bits to describe, increasing the summed code length. In this version, it can be difficult to define the number of bits required to describe the model.  The second version of MDL is the Fisher Information approximation (FIA), which is similar to AIC and BIC in that it includes a first term that represents goodness-fo-fit, and additional terms that represent a penalty for complexity (Vandekerckhove et al., 2015).  The second term resembles that of BIC, and the third term reflects a more sophisticated penalty which represents the number of distinguishable probability distribution that a model can generate (Vandekerckhove et al., 2015).  The FIA differs from AIC and BIC in that it also accounts for functional form complexity, not just complexity due to the number of free parameters (Vandekerckhove et al., 2015).  The third version of MDL is normalized maximum likelihood (NML) which is simple to state but can be difficult to compute, for instance, the denominator may be infinite, and this requires further measures to be taken (Vandekerckhove et al., 2015). Moreover, NML requires integration over the entire set of possible datasets, which may be difficult to define as it depends on unknown decision process in the researchers (Vandekerckhove et al., 2015).

AIC and BIC in R: If there are (p) potential predictors, then there are 2p possible models (r-project.org, 2002).  AIC and BIC can be used in R as selection criteria for linear regression models as well as for other types of models.  As indicated in (r-project.org, 2002): the equations for AIC and BIC are as follows.

For the linear regression models, the -2log-likelihood (known as the deviance is nlog(RSS/n)) (r-project.org, 2002).  AIC and BIC need to get minimized (r-project.org, 2002).  The Larger models will fit better and so have smaller RSS but use more parameters (r-project.org, 2002).  Thus, the best choice of model will balance fit with model size (r-project.org, 2002).  The BIC penalizes larger models more heavily and so will tend to prefer smaller models in comparison to AIC (r-project.org, 2002). 

Example of the code in R using the state.x77 dataset is below. The function does not evaluate the AIC for all possible models but uses a search method that compares models sequentially as shown in the result of the R commands.

  • g <- lm(Life.Exp ~ ., data=state.x77.df)
  • step(g)

References

Bordens, K. S., & Abbott, B. B. (2008). Research Design and Methods: A Process Approach: McGraw-Hill.

Epstein, R. (1984). The principle of parsimony and some applications in psychology. The Journal of Mind and Behavior, 119-130.

Field, A. (2013). Discovering Statistics using IBM SPSS Statistics: Sage publications.

Forster, M. R. (1998). Parsimony and Simplicity. Retrieved from http://philosophy.wisc.edu/forster/220/simplicity.html, University of Wisconsin-Madison.

Hawkins, D. M. (2004). The problem of overfitting. Journal of chemical information and computer sciences, 44(1), 1-12.

Ledolter, J. (2013). Data mining and business analytics with R: John Wiley & Sons.

minitab.com. (2015). The Danger of Overfitting Regression Models. Retrieved from http://blog.minitab.com/blog/adventures-in-statistics-2/the-danger-of-overfitting-regression-models.

r-project.org. (2002). Practical Regression and ANOVA Using R Retrieved from https://cran.r-project.org/doc/contrib/Faraway-PRA.pdf.

Vandekerckhove, J., Matzke, D., & Wagenmakers, E.-J. (2015). Model Comparison and the Principle The Oxford handbook of computational and mathematical psychology (Vol. 300): Oxford Library of Psychology.