scieee AI-readable full text Open interactive document viewer

Block 4: Statistical Modeling through Regression. Part 1. Multiple Regression

Montero Mercadé, Lídia

Full text

ACADEMIC YEAR 2024-25 MASTER’S DEGREE IN URBAN MOBILITYCIVIL ENGINEERING SCHOOLUPC DATA ANALYSIS OF TRANSPORT SYSTEMS Block 4: Statistical Modeling through Regression Part 1. Multiple Regression Lecturer: Lídia Montero September 2024 – Version 2.2 DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-2 2.024-2.025 Academic Year CONTENTS 4.1-1. READINGS____________________________________________________________________________________________________________ 3 4.1-2. INTRODUCTION TO LINEAR MODELS _________________________________________________________________________________ 4 4.1-3. LEAST SQUARES ESTIMATION IN MULTIPLE REGRESSION ____________________________________________________________ 12 4.1-3.1 GEOMETRIC PROPERTIES _______________________________________________________________________________________________ 14 4.1-4. LEAST SQUARES ESTIMATION: INFERENCE __________________________________________________________________________ 16 4.1-4.1 BASIC INFERENCE PROPERTIES __________________________________________________________________________________________ 16 4.1-5. HYPOTHESIS TESTING IN MULTIPLE REGRESSION ___________________________________________________________________ 19 4.1-5.1 TESTING IN R ________________________________________________________________________________________________________ 21 4.1-5.2 CONFIDENCE INTERVAL FOR MODEL PARAMETERS __________________________________________________________________________ 22 4.1-6. MULTIPLE CORRELATION COEFFICIENT_____________________________________________________________________________ 23 4.1-6.1 PROPERTIES OF THE MULTIPLE CORRELATION COEFFICIENT _________________________________________________________________ 25 4.1-6.2 ADJUSTED R2 ________________________________________________________________________________________________________ 25 4.1-7. GLOBAL TEST FOR REGRESSION. ANOVA TABLE _____________________________________________________________________ 26 4.1-8. PREDICTIONS AND INFERENCE ______________________________________________________________________________________ 27 4.1-9. MODEL VALIDATION ________________________________________________________________________________________________ 28 4.1-10. MODEL TRANSFORMATIONS ON Y OR X ______________________________________________________________________________ 37 4.1-10.1 BOX-COX TRANSFORMATION OF Y ______________________________________________________________________________________ 38 4.1-11. MODEL VALIDATION: UNUSUAL AND INFLUENTIAL DATA ____________________________________________________________ 40 4.1-11.1 A PRIORI INFLUENTIAL OBSERVATIONS ___________________________________________________________________________________ 44 4.1-11.2 A POSTERIORI INFLUENTIAL DATA _______________________________________________________________________________________ 46 4.1-12. BEST MODEL SELECTION ____________________________________________________________________________________________ 50 4.1-12.1 STEPWISE REGRESSION _______________________________________________________________________________________________ 52 DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-3 2.024-2.025 Academic Year 4.1-1. READINGS Basic References:  S.P. Washington, M.G. Karlaftis and F.L. Mannering (2011) Statistical and Econometric methods for transportation data analysis, 2nd Edition, Chapman and Hall/CRC.ISBN: 978-1-4200-8285-2.  P. Dalgaard (2008) Introductory Statistics with R. Springer.  Fox, J.: Applied Regression Analysis and Generalized Linear Models. Sage Publications, 2015.  John Fox and Sanford Weisberg (2011) An R Companion to Applied Regression Second Edition SAGE Publications, Inc ISBN: 9781412975148. DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-4 2.024-2.025 Academic Year 4.1-2. INTRODUCTION TO LINEAR MODELS Let ( ) n Tyy ,,y  1 = be a vector of n observations, randomly drawn from the vector ( ) n TYY ,,Y  1 = , whose variables are statistically independent and distributed with expectation ( ) n T µµ ,, 1 = µ : In linear models, the random component distribution for () n TYY ,,Y  1 = is assumed to be normal with constant variance 2 σ and expectation [ ] µ =YΕ . Therefore, the response variable is modeled as normally distributed; thus, negative or positive values, which may be arbitrarily small or large, may be encountered as data for the response and prediction. The systematic component of the model consists in specifying a vector called the linear predictor, denoted η , of the same length as the response, dimension n, obtained from the linear combination of regressors (explanatory variables). In vector notation, the parameters are ( ) p T ββ ,, 1 = β and the regressors are ( ) p XX ,, 1=X and, thus, βη X= where η is nx1, X is nxp and β is px1. Vector µ is the direct linear predictor η ; therefore, the link function is µη = . DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-5 2.024-2.025 Academic Year 4.1-2 INTRODUCTION TO LINEAR MODELS Empirical problem: What do the data say about class sizes and test scores according to the California Test Score Data Set? All K-6 and K-8 California school districts (n = 420) Variables: • 5th grade test scores (Stanford-9 achievement test, combined math and reading), district average • Student-teacher ratio (STR) = number of students in the district divided by number of full-time equivalent teachers Policy question: What is the effect of reducing class size by one student per class? By 8 students/class? Do districts with smaller classes (lower STR) have higher test scores? An initial look at the California test score data: DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-6 2.024-2.025 Academic Year 4.1-2 INTRODUCTION TO LINEAR MODELS Stock and Watson (2007) DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-7 2.024-2.025 Academic Year 4.1-2 SOME NOTATION AND TERMINOLOGY • The population regression line is Test score = β1 + β2STR β1 is the intercept β2 is the slope of the population regression line = Test score STR ∆ ∆ = change in test score for a unit change in STR • Why are β1 and β2 “population” parameters? • We would like to know the population value of β2. • We don’t know β2, so we must estimate it using data. • How can we estimate β1 and β2 from the data? We will focus on the least squares (“ordinary least squares” or “OLS”) estimator of the unknown parameters β1 and β2, which solves ( ) ( ) ( ) ( ) ( ) ∑−−=−⋅−= = k k21k T ββ xββYSMin 21 2 , XβYXβYβ β DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-8 2.024-2.025 Academic Year 4.1-2 SOME NOTATION AND TERMINOLOGY: EXAMPLE The OLS estimator minimizes the average squared difference between the actual values of Yi and the prediction (predicted value) based on the estimated line. Application to the California Test Score – Class size data Estimated slope = – 2.28 Estimated intercept = 698.9 Estimated regression line: = 698.9 – 2.28 STR Interpretation of the estimated slope and intercept: • Districts with one more student per teacher on average have test scores that are 2.28 points lower. • The intercept (taken literally) means that, according to this estimated line, districts with zero students per teacher would have a (predicted) test score of 698.9. This makes no sense, since it extrapolates outside the range of the data. DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-9 2.024-2.025 Academic Year 4.1-2 SOME NOTATION AND TERMINOLOGY: EXAMPLE Predicted values & residuals: One of the districts in the data set for which STR = 25 and Test Score = 621 predicted value: = 698.9 – 2.28*25 = 641.9 residual: = 621 – 641.9 = -20.9 The OLS regression line is an estimate computed using our sample of data; a different sample would have given a different value of 2 β ˆ . κ y k y ˆ DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-16 2.024-2.025 Academic Year 4.1-4. LEAST SQUARES ESTIMATION: INFERENCE 4.1-4.1 Basic inference properties A continuous response linear model is assumed where εXβεμY+=+= or Yi = β1 + β2X2i + … + βpXpi + εi, i = 1,…,n where Y, µ are nx1, X nxp of p rank and β px1 and the conditional distribution of unbiased errors are i.i.d. of constant variance and normally distributed: ( ) 2 σ0,N| ≈Xε or 𝐘𝐘|𝐗𝐗~N(𝐗𝐗𝐗𝐗,σ2𝐈𝐈𝐧𝐧). Then, the minimum-variance unbiased estimator of β is ( ) YXXX ˆ TT 1− = β , the ordinary least squares estimator is equal to the maximum likelihood estimator MV β ˆ . If normal assumptions are not met, then OLS estimators are not efficient (they do not have minimum variance as ML estimator). If the hypothesis holds true, then the unbiased estimator of 2 σ , denoted 2 s , is efficient (minimum variance) and its square root, s , is called the standard error of the model. ( ) ( ) pn RSS pnpn s− = − −⋅− = − ⋅ =βXYβXYee T T ˆˆ 2 Residual sum of squares DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-17 2.024-2.025 Academic Year 4.1-4 LEAST SQUARES ESTIMATION: INFERENCE What we knew before presenting the statistical properties for OLS was about a sample (in particular, our sample), but now we know something about a larger set of observations from which this sample is drawn. We consider the statistical properties of ( ) YXXX ˆTT 1− = β an estimator of something, specifically the population parameter vector β , and the former theorem tells us that the OLS estimator is linear and unbiased. It is better and more efficient (with smaller variance) than any other estimator and has a normal sampling distribution. Any individual coefficient j β ˆ is distributed normally with expectation j β and sampling variance ( ) ( ) T jj XXV T j 2 ˆ σ = β and we can test the simple hypothesis (i.e., make some inference): 0 0 : jj H ββ = with ( ) ) 1, 0( ˆ0 0N Z jj jj ≈ − = X XT σ ββ But since it does not help that much, since j β and 2 σ are unknown, an unbiased estimator of 2 σ is proposed based on the standard error of regression 2 s and to estimate the sample variance of j β ˆ , ( ) j V β ˆ ˆ . DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-18 2.024-2.025 Academic Year 4.1-4 LEAST SQUARES ESTIMATION: INFERENCE () ( ) () ( ) 1 1 2 ˆˆ ˆ − − = →= jj jj sSEs XXXXV T j T j ββ and the ratio of j β ˆ and () j β ˆ SE (standard error of jth parameter) is distributed as a Student t with n-p degrees of freedom (since j β ˆ and 2 s are independent). ( ) pn jj t Student s t − ≈ − = XX T 0 0 ββ can be defined and thus ( ) () 0 0 t tP HP pn >= − or a bilateral confidence interval at () %100 1 α − for ( ) jpnjj SEt βββ α ˆˆ 2 − ±∈ can be calculated. Inference for multiple coefficients will be further presented by the F-test. DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-19 2.024-2.025 Academic Year 4.1-5. HYPOTHESIS TESTING IN MULTIPLE REGRESSION  Let the statistical model for multiple regression for a given data set be εβ ε µ + =+ =XY , where Y nx1, X nxp of range p and β px1 where errors are unbiased and iid normally distributed ( ) nn I 2 0,N σ ≈ ε . Ordinary least square estimators are denoted β ˆ .  Let a simpler model of multiple regression for the same set of data be the former one with a set of linear restrictions applied to the model parameters (a nested model), i.e., εβεµ +=+= XY , where Y nx1, X nxp of range p and β px1 is subject to linear constraints cA = β that define a linear hypothesis to contrast (to make an inference) that we call H; A is a qxp matrix of range q < p. Ordinary least square estimates subject to constraints are H β ˆ . The residual sum of squares is denoted RSSH. DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-20 2.024-2.025 Academic Year 4.1-5 HYPOTHESIS TESTING IN MULTIPLE REGRESSION • If hypothesis H is true, then it can be shown that () ( ) ( ) ( ) ( ) ( ) pnq TT T H F sqpnRSS qRSSRSS F − − − → −− = − − = , 2 1 1 ˆ XX ˆcAAAcA ββ Example: Suppose we have a model with the set of parameters ( ) 4321 ββββ = T β and we want to test the hypothesis    =− =−+ 0 24 : 21 421 ββ βββ H then,       =                   − − →= 0 2 0011 4011 4 3 2 1 β β β β β cA DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-21 2.024-2.025 Academic Year 4.1-5 HYPOTHESIS TESTING IN MULTIPLE REGRESSION 4.1-5.1 Testing in R anova() • For nested linear regression models, method anova(restrictedmodel, fullmodel) implements the F-test. Hypothesis testing in this subject will be suggested by this method. • Net effects tests for a multiple regression model performed with package car Anova(model) • Inconvenient: the two models have to be computed beforehand. linear.hypothesis() in car package: following the previous generic example library(car) linearHypothesis(model, hypothesis.matrix=matrix(c(1,1,0,-4,1,-1,0,0),nrow=2,ncol=4,byrow=TRUE), rhs=as.vector(c(2,0)) ) For glm() object performs a Wald test It requires the estimation of one model only (compared to anova() method) DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-22 2.024-2.025 Academic Year 4.1-5 HYPOTHESIS TESTING IN MULTIPLE REGRESSION 4.1-5.2 Confidence interval for model parameters Individual confidence interval for i β in OLS is summarized as: pn ii tt i − ≈ − = β σ ββ ˆ ˆ ˆ → i pni t β ασβ ˆ ˆ ˆ2 − ± where ( ) 1− =ii TXXs i β σ ˆ ˆ and pn RSS s− == σ ˆ 2 α pn t− is the Student t for the bilateral confidence interval 1- α . The degrees of freedom are (n-p) and correspond to the standard error of regression. Estimates of i β parameters are statistically dependent and individual confidence intervals might give a wrong idea of the jointly distributed values. There is much literature about how to build confidence regions or perform simultaneous tests on several hypotheses: this falls outside of the scope of this material. Some specific suggestions will be presented in the practical sessions. DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-23 2.024-2.025 Academic Year 4.1-6. MULTIPLE CORRELATION COEFFICIENT  Multiple correlation coefficient R is a goodness of fit measure for a regression model defined as the Pearson correlation coefficient between fitted values k y ˆ and observations k y :  The square of the multiple correlation coefficient R2 is called the coefficient of determination. The multiple correlation coefficient generalizes the standard coefficient of correlation. It is used in multiple regression analysis to assess the quality of the prediction of the dependent variable. It corresponds to the squared correlation between the predicted and the actual values of the response variable. 1. According to the decomposition of the total sum of squares (TSS) in the residual sum of squares plus the explained sum of squares for a given model (valid for models including an intercept), R-Squared can be rewritten. 2. TSS= ( ) ∑− k kyy 2 where ∑ = k k y n y1 is the mean of the observed response data. 3. ESS= ( ) ∑− k kyy 2 ˆ and RSS= ( ) ∑− k kk yy 2 ˆ . ( ) ( ) ( ) () 2 1 2 2      ∑− ∑− ∑−− = kk kk kkk yyyy yyyy R ˆˆ ˆˆ DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-24 2.024-2.025 Academic Year 4.1-6 MULTIPLE CORRELATION COEFFICIENT 4. TSS=ESS+RSS, ( ) ∑− k kyy 2 = ( ) ∑− k kyy 2 ˆ + ( ) ∑− k kk yy 2 ˆ , Proof: ( ) ( ) ( )( ) ( ) ( ) ( )( ) ( ) ( ) ∑∑ ∑∑∑∑∑ −+− =−−+−+−=−+−=− k kk k k k kkk k kk k k k kkk k k yyyy yyyyyyyyyyyyyy 22 2222 2 ˆˆ ˆˆˆˆˆˆ where ()( ) ( ) ( ) ( ) ( ) ( ) ( ) 0HYHIYHYHYY YYY T T T =−=−= =−=−=−−−=−− ∑∑∑∑ ˆˆ ˆˆˆˆˆˆˆ k kkk k kk k kkk k kkk yyyyyyyyyyyyy And:  Or equivalently ( ) TSSRRSS 2 1−= . ( ) ( ) TSS RSS TSS ESS yy yy R k k k k −== − − =∑ ∑ 1 ˆˆ 2 2 2 DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-25 2.024-2.025 Academic Year 4.1-6 MULTIPLE CORRELATION COEFFICIENT 4.1-6.1 Properties of the multiple correlation coefficient 1. 1≤R and if |R|=1 this indicates a perfect linear relation between response data and regressors. 2. )( 2 1100 R− represents the fraction of response data variability not explained by the current model. 3. 2 100R represents the fraction of response data variability explained by the current model. 4.1-6.2 Adjusted R2  Since this correlation can not go down when variables are added, the R2 must be adjusted in order to increase only when truly significant regressors are added to the model. This is the adjusted R-Squared: ( ) ( ) ( )         − − −−= − − −= pn n R nTSS pnRSS R a 1 11 1 1 22  Adjusted R-Squared is always less than the original R-Squared and might be negative. DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-32 2.024-2.025 Academic Year 4.1-9 RESIDUAL ANALYSIS: DIAGNOSTIC PLOTS DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-33 2.024-2.025 Academic Year 4.1-9 RESIDUAL ANALYSIS: DIAGNOSTIC PLOTS Anscombe’s data 1098765 1 0 -1 -2 Fitted Value Standardized Residual Residuals Versus the Fitted Values (response is YB) 5 6 7 8 9 10 -2 -1 0 1 2 Fitted Value Standardized Residual Residuals Versus the Fitted Values (response is YA) DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-34 2.024-2.025 Academic Year 4.1-9 RESIDUAL ANALYSIS: DIAGNOSTIC PLOTS Linear hypothesis and homoskedastic Heteroskedastic Linear hypothesis rejected DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-35 2.024-2.025 Academic Year 4.1-9 RESIDUAL ANALYSIS: DIAGNOSTIC PLOTS 6. Scatterplots of residuals vs each regressor (except intercept) The horizontal band indicates linearity satisfaction and homoskedastic hypothesis. Use residualPlots(model) method in package car for R. Example: Duncan data lm(prestige~education+income,data=Duncan)-> lm(prestige~poly(education,2)+income,data=Duncan) Homoskedastic Hypothesis Test - Breusch-Pagan test in package lmtest might be of interest. > library(lmtest) > bptest(model) # Null Hypothesis: Homoskedasticity holds studentized Breusch-Pagan test data: model BP = 0.57522, df = 2, p-value = 0.7501 H0 can’t be rejected OK for income Lack of fit for education DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-36 2.024-2.025 Academic Year 4.1-9 RESIDUAL ANALYSIS: DIAGNOSTIC PLOTS 7. Residual vs time/order or any omitted variable in the model suspected to affect hypothesis Such as the autocorrelation function for residuals (method in R, acf(rstudent(model)) of order k, ( ) ∑ ∑+ = ik ikii e ee kr 2 , and contrasts for simultaneous hypothesis r(j)=0 for j>k. Or Durbin-Watson test (tables are very difficult to interpret) also for autocorrelation testing. No temporal dependency Temporal dependency DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-37 2.024-2.025 Academic Year 4.1-10. MODEL TRANSFORMATIONS ON Y OR X Use marginalModelPlots(model) method in package car for R. Lack of fit between data smoother and current model behavior for one variable indicates that transformation on selected regressor is needed. o Use poly(varname,2) to model linear and quadratic terms on varname regressor. o Use poly(varname,3) to model linear, quadratic and cubic terms on varname regressor. There seem to be no problems in any of them! DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-38 2.024-2.025 Academic Year 4.1-10 MODEL VALIDATION: TRANSFORMATIONS 4.1-10.1 Box-Cox transformation of Y The Box-Cox transformation of Y functions to normalize the error distribution, stabilize the error variance and straighten the relationship of Y to the Xs. Basic transformations are log(Y), 1/Y, Y : o If λ =1, no transformation is necessary. Note that all of the Yi must be positive. o λ may be by maximum likelihood in R: boxcox( formula, data ) method in MASS library. o Or boxCoxVariable(response) after loading car package with λ =1-coefficient for the boxCoxVariable() ). The t-test for the coefficient of the constructed variable is an approximate score test for whether a transformation is required. ( )      = ≠ − = 0λ 0λ λ 1 λ Y log Y Yh DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-39 2.024-2.025 Academic Year 4.1-10 MODEL VALIDATION: TRANSFORMATIONS lm(formula = prestige ~ boxCoxVariable(prestige) + income + education, data = Duncan) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 13.7510 7.7283 1.779 0.082607 . boxCoxVariable(prestige) 0.5954 0.2001 2.975 0.004888 ** income 0.5860 0.1099 5.332 3.84e-06 *** education 0.4165 0.1001 4.160 0.000158 *** Residual standard error: 12.27 on 41 degrees of freedom Multiple R-squared: 0.8587, Adjusted R-squared: 0.8483 Or Y^0.4146 -> squared/cubic root (Y) boxcox(prestige ~ income + education, data = df) 95% CI for λ excludes 1 Transformation is needed DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-40 2.024-2.025 Academic Year 4.1-11. MODEL VALIDATION: UNUSUAL AND INFLUENTIAL DATA It is easy to find examples of regression analysis that show the existence of a few observations that strongly affect the estimation of model parameters in OLS: 1% of data might weigh more in parameter estimation than 99% of the data. Influential data affects model prediction and it seems only natural that predicted values should be supported by 99% of data and not seriously affected by the remaining 1%. Classifying an observation as a priori influential is related to robustness of the design of data collection. We’ll see a technical case study (Anscombe’s data) in one of the lab sessions to further discuss this extremely important aspect of model validation if regression (in general linear) models are formulated and estimated with a predictive future scope of use. DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-41 2.024-2.025 Academic Year 4.1-10 UNUSUAL AND INFLUENTIAL DATA Outlying observations can lead us to misinterpret patterns in plots. • Temporarily removing them can sometimes help us see patterns that we otherwise would not. • Transformations can also spread out clustered observations and bring in the outliers. • More importantly, separated points can have a strong influence on statistical models – removing outliers from a regression model can sometimes give completely different results. Unusual cases can substantially influence the fit of the OLS model. • Cases that are both outliers and high leverage exert influence on both the slopes and intercept of the model. • Outliers may also indicate that our model fails to capture important characteristics of the data. DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-48 2.024-2.025 Academic Year 4.1-10 UNUSUAL AND INFLUENTIAL DATA • In R it’s possible to plot DFBETAS (using matplot) for each observation and regressor, as well as the indication of overall influence related to Cook’s distance. To unify metrics, Cook’s distance is a squared distance, but DFBETAS are ordinary units, so the squared root of Di (Cook’s distance) can be added to the DFBETAS matplot. Standard cut-offs may be suggested and drawn. >matplot(dfbetas(duncan1.lm), type="l", col=2:4,lwd=2) >lines(sqrt(cooks.distance(duncan1.lm)) ,col=1,lwd=3) >abline(h=2/sqrt(dim(duncan1)[1]), lty=3,lwd=1,col=5) >abline(h=-2/sqrt(dim(duncan1)[1]), lty=3,lwd=1,col=5) > abline(h=sqrt(4/(dim(duncan1)[1]- length(names(coef(duncan1.lm))))), lty=3,lwd=1,col=6) >llegenda<-c("Cook d", names(coef(duncan1.lm)), "DFBETA Cutoff", "Ch-H Cut-off") > legend(locator(n=1), legend=llegenda, col=1:length(llegenda), lty=c(1,2,2,2,3,3), lwd=c(3,2,2,2,1,1)) DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-49 2.024-2.025 Academic Year 4.1-10 UNUSUAL AND INFLUENTIAL DATA • DFFITSi suggested by Belsley et al. (1980) are related to Cook’s distance and combine studentized residuals and leverages. A usual cut-off for abnormal absolute value is pn p DFFITSi− >2 . Use dffits(model) in R. ( ) ( ) ( ) ( ) ii ii ii iii i i ii ipDDFFITS h h hs e s DFFITS =→ −         − = −− =1 1 ˆˆˆˆ )( 2 )( ββββ XXT T or DFFITSi=y �i−y �i(−i) σ �(−i)�hii influence(model) plot(dffits(model),type="l",lwd=3) pp=length(names(coef(model))) lines(sqrt(cooks.distance(model)),col=3,lwd=2) abline(h=2*(sqrt(pp/(nrow(duncan)-pp))),lty=3,lwd=1,col=2) abline(h=-2*(sqrt(pp/(nrow(duncan1)-pp))),lty=3,lwd=1,col=2) llegenda<-c("DFFITS","DFFITS Cut-off","Cooks D") legend(locator(n=1),legend=llegenda,col=1:3,lty=c(1,3,1),lwd=c(3,1,2)) DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-50 2.024-2.025 Academic Year 4.1-12. BEST MODEL SELECTION The best regression equation for Y given the regressors ( p1 x , ,x  ) might contain dummy variables, transformations of the original variables and terms related to polynomial regression (higher order rather than linear for covariate variables) for the original variables ( q1 z,,z  ). Model selection should satisfy trade-off between simplicity and goodness of fit, often called parsimony criteria. 1. As many regressors as necessary to make good predictions, on average and with the highest precision in confidence interval. 2. Many variables are expensive to obtain (data collection) and difficult to maintain. It is not practical to build all possible regression models and choose the best one according to some balance criteria. A good model should be consistent with theoretical properties in residual analysis. Neither influential nor unusual data should be included. DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-51 2.024-2.025 Academic Year 4.1-11 BEST MODEL SELECTION The elements available to assess the quality of a particular multiple regression (goodness of fit) model are: 1. Determination coefficient 2 R . A marginal increase is expected when the number of regressors included in the model is consistent with the data available. Any added regressors would (marginally) increase the determination coefficient, so stability must be found. Sometimes the adjusted coefficient 2 a R is useful. 2. Stability of the standard error of regression estimate. Estimation of 𝜎𝜎2 by s2 of underfitting is biased and greater than the true value. The stability of s2 confirms or at least points to goodness of fit. 3. Residual analysis. 4. Unusual and influential data analysis. 5. And a new element: Mallows p C . Related to Akaike Information Criteria (AIC) ()( ) pAIC +−= y,β ˆ 2 . Models with lower values of Cp or AIC indicator are preferred. Some authors strongly recommend BIC (Bayesian Information Criteria) Schwartz criteria () n pBIC log ˆ 2+− =y,β where extra parameters are penalized. In R, AIC(model) for AIC on model objects for which a log-likelihood value can be obtained and AIC(model, k=log(nrow(data.frame))) for BIC. DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-52 2.024-2.025 Academic Year 4.1-11 BEST MODEL SELECTION 4.1-12.1 Stepwise regression Backward elimination is a heuristic strategy to select the best model given a number of regressors and a maximal model built from them. It is a robust method that suppresses insignificant terms from the maximal model to the point that all the terms maintained are statistically significant and cannot be removed. It has been proven to be very effective for polynomial regression. Forward inclusion is a heuristic strategy to select the best model given a set of regressors from the null model by iteratively adding terms and regressors to the target set. It is not a robust procedure and it is not recommended as an automatic procedure to find the best model for a data set and regressor terms. Stepwise regression is a forward strategy that builds on the starting model but, at each iteration, regressor terms are checked for statistical significance. Criteria for adding/removing regressor terms vary in different statistical packages, but F-tests or AIC are commonly used. Partial correlation between Y and each Xj, once some subset of regressors is already in the model, has proven to be successful in the selection of regressors to increase the current model. DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-53 2.024-2.025 Academic Year 4.1-11 BEST MODEL SELECTION R software implements these heuristics in a sophisticated way in the method step(model, target model) based on AIC criteria for model selection at each step. > step(duncan1.lm0, ~income+education, direction="forward",data=duncan1) #AIC direction "forward" Start: AIC=311.52 prestige ~ 1 Df Sum of Sq RSS AIC + education 1 31707 11981 255.30 + income 1 30665 13023 259.05 <none> 43688 311.52 Step: AIC=255.3 prestige ~ education Df Sum of Sq RSS AIC + income 1 4474.2 7506.7 236.26 <none> 11980.9 255.30 Step: AIC=236.26 prestige ~ education + income Call: lm(formula = prestige ~ education + income, data = duncan1) Coefficients: (Intercept) education income DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-54 2.024-2.025 Academic Year -6.0647 0.5458 0.5987 > step(duncan1.lm2,data=duncan1) # Without scope direction is "backward" using AIC Start: AIC=236.26 prestige ~ income + education Df Sum of Sq RSS AIC <none> 7506.7 236.26 - income 1 4474.2 11980.9 255.30 - education 1 5516.1 13022.8 259.05 Call: lm(formula = prestige ~ income + education, data = duncan1) Coefficients: (Intercept) income education -6.0647 0.5987 0.5458 > step(duncan1.lm2,k=log(dim(duncan1)[1]),data=duncan1) # Without scope direction is "backward" using BIC Start: AIC=241.68 prestige ~ income + education Df Sum of Sq RSS AIC <none> 7506.7 241.68 - income 1 4474.2 11980.9 258.91 - education 1 5516.1 13022.8 262.66 Call: lm(formula = prestige ~ income + education, data = duncan1) DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-55 2.024-2.025 Academic Year Coefficients: (Intercept) income education -6.0647 0.5987 0.5458 > step(duncan1.lm0, ~income+education, data=duncan1) #AIC direction "both" Start: AIC=311.52 prestige ~ 1 Df Sum of Sq RSS AIC + education 1 31707 11981 255.30 + income 1 30665 13023 259.05 <none> 43688 311.52 Step: AIC=255.3 prestige ~ education Df Sum of Sq RSS AIC + income 1 4474 7507 236.26 <none> 11981 255.30 - education 1 31707 43688 311.52 Step: AIC=236.26 prestige ~ education + income Df Sum of Sq RSS AIC <none> 7506.7 236.26 - income 1 4474.2 11980.9 255.30 - education 1 5516.1 13022.8 259.05 Call: DATA ANALYSIS OF TRANSPORT SYSTEMS – MUM Prof. Lídia Montero © Page. 4.1-56 2.024-2.025 Academic Year lm(formula = prestige ~ education + income, data = duncan1) Coefficients: (Intercept) education income -6.0647 0.5458 0.5987 >