C H A P T E R 5 Inferential Statistics and Predictive Analytics Inferential statistics draws valid inferences about a population based on an analysis of a representative sample of that population. The results of such an analysis are generalized to the larger population from which the sample originates, in order to make assumptions or predictions about the population in general. This chapter introduces linear, logistics, and polynomial regression analyses for inferential statistics. The result of a regression analysis on a sample is a predictive model in the form of a set of equations. The rst task of sample analysis is to make sure that the chosen sample is representative of the population as a whole. We have previously discussed the one-way chi-square goodness-of-t test for such a task by comparing the sample distribution with an expected distribution. Here we present the chi-square two-way test of independence to determine whether signicant dierences exist between the distributions in two or more categories. This test helps to determine whether a candidate independent variable in a regression analysis is a true candidate predictor of the dependent variable, and to thus exclude irrelevant variables from consideration in the process. We also generalize traditional regression analyses to Bayesian regression analyses, where the regression is undertaken within the context of the Bayesian inference. We present the most general Bayesian regression analysis, known as the Gaussian process. Given its similarity to other decision tree learning techniques, we save discussion of the Classication and Regression Tree (CART) technique for the later chapter on ML. To use inferential statistics to infer latent concepts and variables and their relationships, this chapter includes a detailed description of principal component and factor analyses. To use inferential statistics for forecasting by modeling time series data, we present survival analysis and autoregression techniques. Later in the book we devote a full chapter to AI- and ML-oriented 75
76 Computational Business Analytics techniques for modeling and forecasting from time series data, including dynamic Bayesian networks and Kalman ltering. 5.1 CHI-SQUARE TEST OF INDEPENDENCE The one-way Chi-Square (χ 2 ) goodness-of-t test (which was introduced earlier in the descriptive analytics chapter) is a non-parametric test used to decide whether distributions of categorical variables dier signicantly from predicted values. The two-way or two-sample chi-square test of independence is used to determine whether a signicant dierence exists between the distributions of two or more categorical variables. To determine if Outlook is a good predictor of Decision in our play-tennis example in Appendix B, for instance, the null hypothesis H0 is that two distributions are not equal; in other words, that the weather does not aect if one decides to play or not. The Outlook vs. Decision table is shown below in TABLE 5.1. Note that the row and the column subtotals must have equal sums, and that total expected frequencies must equal total observed frequencies. TABLE 5.1: : Outlook vs. Decision table Outlook Decision play Decision don't play Row Subtotal sunny 2 3 5 overcast 4 0 4 rain 3 2 5 Column Subtotal 9 5 Total = 14 Note also that we are computing expectation as follows with a view that the observations are assumed to be representative of the past Exp (Outlook = sunny & Decision = play) = 14 p (Outlook = sunny & Decision = play) = 14 p ( (Outlook = sunny) p (Decision = play) ) = 14 (p (Outlook = sunny) p (Decision)) ( Decision ) (p (Decision = play) p (Outlook)) Outlook = 14 (p (sunny) p (play) + p (sunny) p (don t play)) (p (play) p (sunny) + p (play) p (overcast) + p (play) p (rain)) = 14 (Row subtotal for sunny/14) (Column subtotal for play/14) = (5 9) /14 The computation of Chi-square statistic is shown in TABLE 5.2.
Inferential Statistics and Predictive Analytics 77 TABLE 5.2: : Computation of Chi-square statistic Joint Variable Observed (O) Expected (E) (O-E) 2 /E sunny & play 2 3.21 0.39 sunny & don't play 3 1.79 0.82 overcast & play 4 2.57 0.79 overcast & don't play 0 1.43 1.43 rainy & play 3 3.21 0.01 rainy & don't play 2 1.79 0.02 Therefore, Chi-square statistic = i (O E) 2 E = 3.46 The degree of freedom is (3 1) (2 1), that is, 2. With 95% as the level of signicance, the critical value from the Chi-square table is 5.99. Since the value 3.46 is less than 5.99, so we would reject the null hypothesis that there is signicant dierence between the distributions in Outlook and Decision. Hence the weather does aect if one decides to play or not. 5.2 REGRESSION ANALYSES In this section, we begin with simple and multiple linear regression techniques, then present logistic regression for handling categorical variables as the dependent variables, and, nally, discuss polynomial regression for modeling nonlinearity in data. 5.2.1 Simple Linear Regression Simple linear regression models the relationship between two variables X and Y by tting a linear equation to observed data: Y = a + bx where X is called an explanatory variable and Y is called a dependent variable. The slope b and the intercept a in the above equation must be estimated from a given set of observations. Least-squares is the most common method for tting equations, wherein the best-tting line for the observed data is calculated by minimizing the sum of the squares of the vertical deviations from each data point to the line. Suppose the set (y 1, x 1 ),..., (y n, x n ) of n observations are given. The expression to be minimized is the sum of the squares of the residuals (i.e., the dierences between the observed and predicted values): n (y i a bx i ) 2 i=1 By solving the two equations obtained by taking partial derivatives of the
78 Computational Business Analytics above expression with respect to a and b and then equating them to zero, the estimations of a and b can be obtained. n n n x iy i 1 n x i y j i=1 i=1 j=1 n (x i X) = ( 2 n n ) 2 = Cov(X,Y ) x 2 i 1 V ar(x) n x i i=1 i=1 i=1 n (x i ˆb X)(y i Ȳ ) = i=1 â = Ȳ ˆb X The plot in FIGURE 5.1 shows the observations and linear regression model (the straight line) of the two variables Temperature (Fahrenheit degree) and Humidity (%), with Temperature as the dependent variable. For any given observation of Humidity, the dierence between the observed and predicted value of Temperature provides the residual error. FIGURE 5.1 : Example linear regression The correlation coecient measure between the observed and predicted values can be used to determine how close the residuals are to the regression line. 5.2.2 Multiple Linear Regression Multiple linear regression models the relationship between two or more response variables X i and one dependent variable Y as follows: Y = a + b 1 X 1 +... + b p X p The given n observations (y 1, x 11,..., x 1p ),..., (y n, x n1,..., x np ) in matrix form are
Inferential Statistics and Predictive Analytics 79 y 1 y 2... y n = Or in abbreviated form a a... a + The expression to be minimized is b 1 b 2... b p T Y=A+B T X x 11 x 21... x n1 x 12 x 22... x n2............ x 1p x 2p... x np n (y i a b 1 x i1... b p x ip ) 2 i=1 The estimates of A and B are as follows: 5.2.3 Logistic Regression ˆB = ( X T X ) 1 X T Y = Cov(X,Y) V ar(x) Â = Ȳ ˆB X The dependent variable in logistic regression is binary. In order to predict categorical attribute Decision in the play-tennis example in Appendix B from a new category Temperature, suppose the attribute Temp_0_1 represents a continuous version of the attribute Decision, with 0 and 1 representing the values don't play and play respectively. FIGURE 5.2 shows the scatter plot and a line plot of Temperature vs. Temp_0_1 (left), and a scatter plot and logistic curve for the same (right). The scatter plot shows that there is a uctuation among the observed values, in the sense that for a given Temperature (say, 72), the value of the dependent variable (play/don't play) has been observed to be both 0 and 1 on two dierent occasions. Consequently, the line plot oscillates between 0 and 1 around that temperature. On the other hand, the logistic curve transitions smoothly from 0 to 1. We describe here briey how logistic regression is formalized. Since the value of the dependent variable is either 0 or 1, the most intuitive way to apply linear regression would be to think of the response as a probability value. The prediction will fall into one class or the other if the response crosses a certain threshold or not, and therefore the linear equation will be of the form: p (Y = 1 X) = a + bx However, the value of a+bx could be > 1 or < 0 for some X, giving probabilities that cannot exist. The solution is to use a dierent probability representation. Consider the following equation with a ratio as the response variable: p 1 p = a + bx
80 Computational Business Analytics FIGURE 5.2 : (left) Scatter and line plots of Temperature vs. Temp_0_1, and (right) scatter plot and logistic curve for the same The ratio ranges from 0 to for some X but the value of a + bx would be below 0 for some X. The solution is to take the log of the ratio: ( ) p log = a + bx 1 p The logit function above transforms a probability statement dened in 0 < p < 1 to one dened in < a + bx <. The value of p is as follows: p = ea+bx 1 + e a+bx A maximum likelihood method can be applied to estimate the parameters a and b of a logistic model with binary response: Y = 1 with probability p Y = 0 with probability 1 p For each Y i = 1 the probability p i appears in the likelihood product. Similarly, for each Y i = 0 the probability 1 p i appears in the product. Thus, the likelihood of the sample (y 1, x 1 ),..., (y n, x n ) of n observations takes the following form: L (a, b; (y 1, x 1 ),..., (y n, x n )) = n p yi (1 p) 1 yi i=1 = n ( ) yi ( i=1 = n i=1 e a+bx i 1+e a+bx i (e a+bx i ) y i 1+e a+bx i 1 1+e a+bx i ) 1 yi Alternatively, we can maximize the log likelihood, log (L (a, b; Data)), to solve
Inferential Statistics and Predictive Analytics 81 for a and b. In the example above, the two values of a and b that maximize the likelihood are 45.94 and -0.62, respectively. Hence the logistic equation is: ( ) p log = 45.94 0.62X 1 p FIGURE 5.2 (right) shows the logistics curve plotted for the sample. 5.2.4 Polynomial Regression The regression model Y = a 0 + a 1 X + a 2 X 2 +... + a k X k is called the k-th order polynomial model with one variable, where a 0 is the Y -intercept of X, a 1 is called the linear eect parameter, a 2 is called the quadratic eect parameter, and so on. The model is a linear regression model for k = 1. This model is non-linear in the X variable, but it is linear in the parameters a 0, a 1, a 2,... and a k. One can also have higher-order polynomial regression involving more than one variable. For example, a second-order or quadratic polynomial regression with two variables X 1 and X 2 is Y = a 0 + a 1 X 1 + a 2 X 2 + a 11 X 2 1 + a 22 X 2 2 + a 12 X 1 X 2 FIGURE 5.3 (left) shows a plot of 7 noisy, evenly-spaced random training samples (x 1, y 1 ),..., (x 7, y 7 ) drawn from an underlying function f (shown in dotted line). Note that a dataset of k+1 observations can be modeled perfectly by a polynomial of degree k. In this case, a six-degree polynomial will t the data perfectly, but will over-t the data and will not generalize well for test data. To decide on the appropriate degree for a polynomial regression model, one can begin with a linear model and include higher-order terms one by one until the highest-order term becomes non-signicant (determined by looking at p-values for the t-test for slopes). One could also start with a high-order model and exclude the non-signicant highest-order terms one by one until the remaining highest-order term becomes signicant. Here we measure tness with respect to the test data of eight evenly-spaced samples as shown plotted in FIGURE 5.3 (right). FIGURE 5.4 shows six dierent polynomial regressions of degrees 1 to 6 along with the sample data. Note that the polynomial regression of degree 6 goes through all seven points and ts perfectly. The closest t to the sample training data is based on the R2 measure in Excel. FIGURE 5.5 (left) shows this measure of tness between the training data and the predictions of each polynomial model of certain degree. As shown in the gure, the polynomial of degree 6 has the perfect measure of tness 1.0. The test error is based on the error measure 8 y i f (x i ) i=1
82 Computational Business Analytics FIGURE 5.3 : Sample (left) and test data (right) from a function between the test data and the six polynomial regressions corresponding to degrees 1 to 6. We can see in FIGURE 5.5 (left) that while the measure of tness is steadily increasing towards 1.0, the test error in FIGURE 5.5 (right) reaches a minimum at degree 2 (hence the best t) and then increases rapidly as the models begin to over-t the training data. 5.3 BAYESIAN LINEAR REGRESSION Bayesian linear regression views the regression problem as introduced above as an estimation of the functional dependence between an input variable X in R d and an output variable Y in R as shown below: Y (X) = M w i φ i (X) + ε i=1 = w T Φ (X) + ε where w T Φ (X) (e.g., Φ (X) = ( 1, x, x 2,... ) ) is a linear combination of M predened nonlinear basis functions φ i (X) with input in R d and output in R. The observations are additively corrupted by i.i.d. noise with normal distribution ε N ( 0, σn 2 ) that has zero mean and variance σ 2 n. The goal of Bayesian regression is to estimate the weights w i given a training set {(x 1, y 1 ),..., (x n, y n )} of data points. In contrast to classical regression, a Bayesian linear regression characterizes the uncertainty in w through a probability distribution p (w). We use a multivariate normal distribution as prior on the weights as p (w) = N (0, Σ w )
Inferential Statistics and Predictive Analytics 83 FIGURE 5.4 : Fitting polynomials of degrees 1 to 6 with zero mean and Σ w as an M M -sized covariance matrix. Further observations of data points modify this distribution using Bayes' theorem, with the assumption that the data points have been generated via the likelihood function. Let us illustrate Bayesian linear regression as Y = w T X + ε
84 Computational Business Analytics FIGURE 5.5 : Plots of tness measures (left) and test errors (right) against polynomial degrees Suppose D is the d n matrix of input x vectors from this training set and y is the vector of y values. We have a Gaussian prior p (w) of parameters w, and the likelihood of the parameters is p (y D, w) = N ( w T D, σ 2 ni ) According to Bayes' rule, the posterior distribution over w is p (w y, D) p (y D, ( w) p (w) = N 1 σ 2 n The predictive distribution is ) A 1 Dy, A 1, where A = Σ 1 w + 1 σ DD T n 2 p (Y X, y, D) = ( w T X ) p (w y, D) dw w ( ) 1 = N σ X T A 1 Dy, X T A 1 X n 2 The multivariate normal distribution above can be used for predicting Y given a vector input X. 5.3.1 Gaussian Processes A Gaussian process is a collection of random variables, any nite subset of which has a joint Gaussian distribution. Gaussian processes extend multivariate Gaussian distributions to innite dimensionality. A regression technique starts with a set of data points, {(x 1, y 1 ),..., (x n, y n )}, consisting of inputoutput pairs. The task is then to predict or interpolate the output value y given an input vector x. As we observe the output, the new input-output pair
Inferential Statistics and Predictive Analytics 85 is added to the observation data set. Thus the data set grows in size over time. Any number of observations y 1,..., y n in an arbitrary data set can be viewed as a single point sampled from some multivariate Gaussian distribution. Hence, a regression data set can be partnered with a Gaussian process where the prediction always takes into account the latest observations. We consider a more general form of regression function for interpolation Y = f (X) + N ( 0, σn 2 ) where each observation X can be thought of as related to an underlying function f through some Gaussian noise model. We solve the above for the function f. In fact, given n data points and new input X, our objective is to predict Y and not the actual f since their expected values are identical (according to the above regression function). We can obtain a Gaussian process from the Bayesian linear regression model: f (X) = w T X with w N (0, Σ w ) where the mean is given by E [f (X)] = E [ w T ] X = 0 and the covariance is given by [ ] E f (x i ) T f (x j ) = x T i E [ ww T ] x j = x T i Σ w x j It is often assumed that the mean of this Gaussian process is zero everywhere, but one observation is related to another observation via the covariance function k (x i, x j ) = σ 2 f e x i x j 2 2l 2 + σ 2 n δ (x i, x j ) where the maximum allowable covariance is dened as σf 2, which should be high (and hence not zero) for functions covering a broad range on the Y axis. The value of the kernel function approaches its maximum if x i x j. In this case f (x i ) and f (x j ) are perfectly correlated. This means the neighboring points yield very close functional values, making the function smooth, and distant observations will have a negligible eect during interpolation of f at a new x value. The length parameterl determines the eect of this separation. δ (x i, x j ) is known as the Kronecker delta function (δ (x i, x j ) = 0 if x i x j else 1). For Gaussian process regression, suppose the observation set is {(x 1, y 1 ),..., (x n, y n )} and a new input observation is x We capture the covariance functions k (x i, x j ) for all possible x i, x j, and x in the following three matrices: K = k (x 1, x 1 ) k (x 1, x 2 )... k (x 1, x n ) k (x 2, x 1 ) k (x 2, x 2 )... k (x 2, x n )............ k (x n, x 1 ) k (x n, x 2 )... k (x n, x n )
86 Computational Business Analytics K = [ k (x, x 1 ) k (x, x 2 )... k (x, x n ) ] K = k (x, x ) Note that k (x i, x i ) = σf 2 + σ2 n, for all i. As per the assumption of a Gaussian process, the data set can be represented as a multivariate Gaussian distribution as follows: [ ] ( [ ]) y K K T N 0, y K K We are interested in the conditional distribution p (y y) which is given below: y y N ( K K 1 y, K K K 1 K T ) Therefore the best estimate for y is the mean K K 1 y of the above distribution. Example To illustrate the Gaussian process, consider the sample data set of seven points in TABLE 5.3, a plot of which was shown earlier in FIGURE 5.3. Considering the covariance function: TABLE 5.3: : Sample data set X Y 1 1 2 4.5 3 6.5 4 6 5 6.7 6 7 8 3 7.5? k (x i, x j ) = e x i x j 2 2l 2 With the value of l as 0.8 in the function k above, we calculate the covariance matrix K as shown in TABLE 5.4. TABLE 5.4: : Matrix of covariance functions 1 0.457833 0.043937 0.000884 3.73E-06 3.29E-09 2.37E-17 0.457833 1 0.457833 0.043937 0.000884 3.73E-06 6.1E-13 0.043937 0.457833 1 0.457833 0.043937 0.000884 3.29E-09 0.000884 0.043937 0.457833 1 0.457833 0.043937 3.73E-06 3.73E-06 0.000884 0.043937 0.457833 1 0.457833 0.000884
Inferential Statistics and Predictive Analytics 87 TABLE 5.4: : Matrix of covariance functions 3.29E-09 3.73E-06 0.000884 0.043937 0.457833 1 0.043937 2.37E-17 6.1E-13 3.29E-09 3.73E-06 0.000884 0.043937 1 It is clear from the above table that the closer the X values are to each other, the higher the values of the covariance function are. We also have K as shown in TABLE 5.5. TABLE 5.5: : Vector of covariance functions 4.62E-15 5.45E-11 1.35E-07 6.98E-05 0.007576 0.172422 0.822578 The formula K K 1 y provides 3.23 as the mean of the predicted y-value for x = 7.5. 5.4 PRINCIPAL COMPONENT AND FACTOR ANALYSES Principal component analysis (PCA) converts a set of measurements of possibly correlated variables into a set of values of linearly uncorrelated variables called principal components. PCA can be done by eigenvalue decomposition or SVD as introduced earlier in the background chapter. Example Consider the data set in FIGURE 5.6 with 6 variables and 51 observations of the US Electoral College votes, population, and area by state. The full data set is given in Appendix B. FIGURE 5.6 : United States Electoral College votes, population, and area by state The correlation matrix in FIGURE 5.7 clearly indicates two groups of correlated variables. The fact that the number of electoral votes is proportional to the population gives rise to the rst set of correlated variables. The second set of correlated variables is the set of all areas.
88 Computational Business Analytics FIGURE 5.7 : Correlation matrix for the data in FIGURE 5.6 All six eigenvalues and eigenvectors are shown in FIGURE 5.8, of which the rst three are dominating as expected, given the two groups of correlated variables as shown in FIGURE 5.7 and the only remaining variable for density. The rst principal component PRIN1 shows the domination of the coecients corresponding to the three variables related to the areas. The second principal component PRIN2 shows the domination of the coecients corresponding to Electoral Votes and Population. FIGURE 5.8 : Eigenvalues and eigenvectors of the correlation matrix in FIGURE 5.7 FIGURE 5.9 shows the principal component plot of the data set in FIG- URE 5.6 with the rst two components. It is clear from the plot that the component PRIN1 is about the area and PRIN2 is about the population. This is the reason why the state of Alaska has a large PRIN1 value but very little PRIN2, and DC is just opposite. The state of California has large values for both PRIN1 and PRIN2. Factor analysis (Anderson, 2003; Gorsuch, 1983) helps to obtain a small set of independent variables, called factors or latent variables, from a large set of correlated observed variables. Factor analysis describes the variability among observed variables in order to gain better insight into categories or to provide a simpler prediction structure. For example, factor analysis can reduce a large number of nancial ratios into categories of nancial ratios on
Inferential Statistics and Predictive Analytics 89 FIGURE 5.9 : Principal component plot of the data set in FIGURE 5.6 the basis of empirical evidence. It can help with nding contributing factors aecting, for example, prices of groups of stocks, GDPs of countries, and water and air qualities. For exploratory factor analysis (EFA), there is no predened idea of the structure or dimensions in a set of variables. On the other hand, a conrmatory factor analysis (CFA) tests specic hypotheses about the structure or the number of dimensions underlying a set of variables. The factor model proposes that observed responses X 1,..., X n are partially inuenced by underlying common factors F 1,..., F m and partially by underlying unique factors e 1,..., e n. X 1 = λ 11 F 1 + λ 12 F 2 +... + λ 1m F m + e 1 X 2 = λ 21 F 1 + λ 22 F 2 +... + λ 2m F m + e 2... X n = λ n1 F 1 + λ n2 F 2 +... + λ nm F m + e n The coecients λ ij are called the factor loadings, so that λ ij is the loading of the ith variable on the jth factor. Factor loadings are the weights and correlations between each variable and the factor. The higher the loading value, the more relevant the variable is in dening the factor's dimensionality. A negative value indicates an inverse impact on the factor. Thus a given factor inuences some measures more than others, and this degree of inuence is determined by loadings. The error terms e 1,..., e n serve to indicate that the hypothesized relationships are not exact. The ith error term describes the residual variation specic to the ith variable X i. The factors are often called
90 Computational Business Analytics the common factors while the residual variables are often called the unique or specic factors. The number of factors m should be substantially smaller than n. If the original variables X 1,..., X n are at least moderately correlated, the basic dimensionality of the system is less than n. The goal of factor analysis is to reduce the redundancy among the variables by using a smaller number of factors. To start an EFA, we rst extract initial factors, using principal components to decide on the number of factors. Eigenvalue is the amount of variance in the data described by the factor, and eigenvalues help to choose the number of factors. In principal components, the rst factor describes most of the variability. We then choose the number of factors to retain, and rotate axes to spread variability more evenly among factors. Redening factors that loadings tend to make very high (-1 or 1) or very low (0) makes sharper distinctions in the interpretations of the factors. Example We apply the principal component-based factoring method on the data in FIG- URE 5.6. The eigenvalues and the factor patterns are shown in FIGURE 5.10. FIGURE 5.10 URE 5.6 : Eigenvalues and factor patterns for the data in FIG- Now we apply the orthogonal Varimax rotation (maximizes the sum of the variances of the squared loadings) to obtain rotated factor patterns, as shown in FIGURE 5.11, and the revised distribution of variance explained by each factor, as shown in FIGURE 5.12. The total variance explained remains the same and gets evenly distributed between the major two factors. Example Here is an articial example to check the validity and robustness of factor analysis. The data from the Thurstone box problem (Thurstone, 1947), as shown in FIGURE 5.13, measures 20 dierent characteristics of boxes, such as individual surface areas and box inter-diagonals. If these measurements are only linear combinations of the height, width, and depth of the box, then the
Inferential Statistics and Predictive Analytics 91 FIGURE 5.11 : Rotated factor patterns from factors in FIGURE 5.10 FIGURE 5.12 : Variance explained by each factor in FIGURE 5.11 data set could be reproduced by knowing only these dimensions and by giving them appropriate weights. These three dimensions are considered as factors. FIGURE 5.13 : 20 variable box problem data set (Thurstone, 1947) As shown in FIGURE 5.14, the three dimensions of space are approximately discovered by the factor analysis, despite the fact that the box characteristics are not linear combinations of underlying factors but are instead multiplicative functions. Initial loadings and components are extracted using PCA. The question is how many factors to extract in a given data set. Kaiser's criterion suggests that it is only worthwhile to extract factors which account for large variance. Therefore, we retain those factors with eigenvalues equal to or greater than 1.
92 Computational Business Analytics There are 20 observations, each a function of x, y or z or one of their combinations. In FIGURE 5.14, Proportion indicates the relative weight of each factor in the total variance. For example, 12.6149/20 = 0.6307. So the rst factor explains about 63% of the total variance. Cumulative shows the total amount of variance explained, and the rst six eigenvalues explain almost 99.6% of the total variance. From a factor analysis perspective the rst three eigenvalues suggest a factor model with three common factors. This is because the rst two eigenvalues are greater than unity and the third one is closer to unity and together they explain over 98% of the total variance. FIGURE 5.14 : Factor analysis of the data in FIGURE 5.13 shows the eigenvalues for variance explained by each factor and three retained factors Rotating the components towards independence, rather than rotating the loadings towards simplicity, allows one to accurately recover the dimensions of each box and also to produce simple loadings. FIGURE 5.15 shows the factors of FIGURE 5.14 after an orthogonal Varimax rotation. The total of eigenvalues for the factors remains the same, but variability among factors is evenly distributed. There are some dierences between EFA and PCA and they will provide somewhat dierent results when applied to the same data. EFA assumes that the observations are based on the underlying factors, whereas in PCA the principal components are based on observations. The rotation of components is part of EFA but not PCA. 5.5 SURVIVAL ANALYSIS Survival analysis (Kleinbaum and Klein, 2005; Hosmer et al., 2008) is a timeto-event analysis that measures the time from the beginning of a study to a terminal event, conclusion of the observation period, or loss of contact/with-
Inferential Statistics and Predictive Analytics 93 FIGURE 5.15 rotation : Factors of FIGURE 5.14 after an orthogonal Varimax drawal from the study. Survival data consist of a response variable that measures the duration of time (event time, failure time, or survival time) until a specied event occurs. Optionally, the data may contain a set of independent variables that are possibly associated with the failure time variable. Examples of survival analysis include determining the lifetime of a device (the time after installation until the device breaks down), the time until a company declares bankruptcy after its inception, the length of time an auto driver stayed accident-free since becoming insured, the length of time a person stayed on a job, the retention time of customers, and the survival time (or time until death) for organ transplant patients since transplant surgery. The censoring problem in survival analysis arises due to incomplete observations of survival time during a period of study. Some subjects of study have censored survival times because they may not be observed for the full study period due to drop-out, loss to followup, or early termination of the study. A censored subject may or may not have an event of interest if it occurs before the end of the study but their data is incomplete. Example FIGURE 5.16 illustrates the survival histories of six subjects in an example of a study that could be measuring implanted device lifetimes or post-organ transplant outcomes. In the gure, the terminal event of interest is breakdown or death which motivates a study of survival time. Not all devices will cease to work during the 325 days of the study period, but all will break down eventually. In the gure, the solid line represents an observed period at risk, while the broken line represents an unobserved period at risk. The letter X represents an
94 Computational Business Analytics FIGURE 5.16 : Survival histories of subjects for analysis observed terminal event, the open circle represents the censoring time, and the letter N represents an unobserved event. An observation that is right-censored means the relevant event has not yet occurred at the time of observation. An observation that is left-censored means the relevant event has occurred before the time of observation but the exact time is not known. An observation is interval-censored if the event occurs at an unknown point in a time interval. Right-censored observations are the most common kind. Example In FIGURE 5.16, the observation of subject 5 is right-censored. Subject 4 joined the study late. Subject 6 is lost to observation for a while. Subject 2 joined the study on time but was lost to observation after some time, and died before the study period ended, but it is not known exactly when. Consider the random variable T representing the survival time with density f (t). The cumulative distribution function is F (t) = p (T t), which represents the probability that a subject survives no longer than time t. S (t) is the survival function or the probability that a subject survives longer than
Inferential Statistics and Predictive Analytics 95 time t, that is, S (t) = p (T > t) = 1 F (t) = t f (s) ds. A typical question to be asked is What is the probability of the device lasting past 300 days? and the answer is S (300). The hazard function is dened as h (t) = f (t) S (t). Methods for estimating survival function include life table analysis, Kaplan- Meier product-limit estimator, and Cox's semi-parametric proportional hazard model, of which the life table is the least complicated way to describe the survival in a sample. A straightforward multiple regression technique is not suitable for survival analysis because of the problem of censoring and the survival time dependent variable, as well as the fact that other independent variables are not normally distributed. In the life table analysis, the distribution of survival times is divided into a certain number of intervals. For each interval we can then compute the number and proportion of cases or objects that entered the respective interval, the number and proportion of terminal events, and the number of cases that were lost or censored in the respective interval. Several additional statistics can be computed based on these numbers and proportions, especially the estimated probability p i of failure in the respective interval. This probability p i of the ith interval is computed per unit of time as (n i n i+1 ) /t i, where n i is the estimated cumulative proportion surviving at the beginning of the ith interval, n i+1 is the cumulative proportion surviving at the end of the ith interval, and t i is the width of the ith interval. Since the probabilities of survival are assumed to be independent across the intervals, the survival probability up to an interval is computed by multiplying out the probabilities of survival across all previous intervals. The life table gives us a good indication of the distribution of survival over time. However, for predictive purposes it is often desirable to understand the shape of the underlying survival function in the population. The two major distributions that have been proposed for modeling survival or failure times are the exponential and the Weibull distribution. The Kaplan-Meier product-limit estimator (1958) is a life table analysis in which each time interval contains exactly one case. The method arranges the data in increasing order of the observed values, noting the censored cases. It then computes the proportion of subjects who left the study after each change in the ordering. The advantage of using this estimator is that the resulting estimates do not depend on the grouping of the data into a certain number of time intervals. Cox's proportional hazards model determines the underlying hazard rate as a function of the independent variables.
96 Computational Business Analytics Example We undertake a retrospective analysis of 863 records (part displayed in FIG- URE 5.17) of patients who underwent a kidney transplant during a certain period of time. The patient population examined contains males and females, and both black and white subjects. FIGURE 5.17 : Example data for survival analysis (Ref: http://www.mcw.edu/filelibrary/groups/biostatistics/publicles/ DataFromSection/DataFromSectionTXT/Data_from_section_1.7.txt) Survival studies were calculated using the Kaplan-Meier Product-Limit method. The outcome endpoints were alive and dead. The data were grouped by the gender and race variables and hence there were four groups. The survival functions for both white and black females are shown in FIGURE 5.18. FIGURE 5.18 : An example survival analysis plots
Inferential Statistics and Predictive Analytics 97 It's clear from the gure that the average survival time is higher for the population representing the distribution function on the left than on the right. Similar other conclusions can be drawn by studying and comparing the two distribution functions. 5.6 AUTOREGRESSION MODELS A process is stochastic if it evolves in time according to probabilistic laws. In this section, we introduce three types of stochastic processes, Autoregressive (AR), Moving Average (MA), and Autoregressive and Moving Average (ARMA), which are a special type of Gaussian process for modeling timeseries data. A simple AR process, AR(1), is recursively dened as follows: X t = ax t 1 + ε t where a is the coecient, ε t is white noise with ε t N ( 0, σ 2) and ε i and ε j are independent for i j. By repeated substitution, X t = ε t + aε t 1 + a 2 ε t 2 +... Therefore, E [X t ] = 0 and V ar [X t ] = σ ( 2 1 + a 2 + a 4 +... ) = σ2 1 a, if a < 2 1. More generally, an autoregression model of order p, AR(p), is dened as : X t = a 1 X t 1 +... + a p X t p + ε t where X t can be obtained by linear regression from X t 1,..., X t p. The MA process represents time series that are generated by passing the white noise through a non-recursive linear lter. The general MA process of order q, MA(q), is dened as follows: X t = ε t + b 1 ε t 1 +... + b q ε t q where b i s are coecients and ε i is white noise with ε i N ( 0, σ 2). AR(p) and MA(q) processes can be combined to dene ARMA(p, q) as Example X t = a 1 X t 1 +... + a p X t p + ε t + b 1 ε t 1 +... + b q ε t q } {{ } } {{ } Autoregressive (AR) MovingAvergae (MA) FIGURE 5.19 is an autoregressive plot of forecasts of the closing values of Intuit stock for seven days in the rst half of January 2006. The order of the autoregressive process is 5 and the process employs a maximum likelihood estimator method. The gure also shows the 3 standard deviations from the mean as the Lower Control Limit (LCL) and Upper Control Limit (UCL) values. Note from the gure that the autoregression process takes a time-step or two to predict a steep ascension or decline in the observed data.
98 Computational Business Analytics FIGURE 5.19 : Plot of forecasts by autoregression 5.7 FURTHER READING Two very comprehensive books on applied regression analyses are (Gelman and Hill, 2006) and (Kleinbaum et al., 2007). A great tutorial on survival analysis can be found in (Kleinbaum and Klein, 2005).