5. Multiple regression



Similar documents
Forecasting in supply chains

4. Simple regression. QBUS6840 Predictive Analytics.

STATISTICA Formula Guide: Logistic Regression. Table of Contents

1. What is the critical value for this 95% confidence interval? CV = z.025 = invnorm(0.025) = 1.96

International Statistical Institute, 56th Session, 2007: Phil Everson

Multiple Linear Regression in Data Mining

Analysis of algorithms of time series analysis for forecasting sales

Simple linear regression

DEPARTMENT OF PSYCHOLOGY UNIVERSITY OF LANCASTER MSC IN PSYCHOLOGICAL RESEARCH METHODS ANALYSING AND INTERPRETING DATA 2 PART 1 WEEK 9

5. Linear Regression

Exercise 1.12 (Pg )

TIME SERIES ANALYSIS

1. The parameters to be estimated in the simple linear regression model Y=α+βx+ε ε~n(0,σ) are: a) α, β, σ b) α, β, ε c) a, b, s d) ε, 0, σ

Introduction to Linear Regression

NCSS Statistical Software Principal Components Regression. In ordinary least squares, the regression coefficients are estimated using the formula ( )

Premaster Statistics Tutorial 4 Full solutions

Rob J Hyndman. Forecasting using. 11. Dynamic regression OTexts.com/fpp/9/1/ Forecasting using R 1

Interaction between quantitative predictors

Example: Boats and Manatees

Issues in Modeling and Adjusting Calendar Effects in Economic Time Series

Penalized regression: Introduction

2. Linear regression with multiple regressors

TIME SERIES ANALYSIS

Ridge Regression. Patrick Breheny. September 1. Ridge regression Selection of λ Ridge regression in R/SAS

2. Simple Linear Regression

A Primer on Forecasting Business Performance

16 : Demand Forecasting

3. Regression & Exponential Smoothing

Academic Calendar for Faculty

Chapter 7: Simple linear regression Learning Objectives

Stepwise Regression. Chapter 311. Introduction. Variable Selection Procedures. Forward (Step-Up) Selection

Outline. Topic 4 - Analysis of Variance Approach to Regression. Partitioning Sums of Squares. Total Sum of Squares. Partitioning sums of squares

IAPRI Quantitative Analysis Capacity Building Series. Multiple regression analysis & interpreting results

Basic Statistics and Data Analysis for Health Researchers from Foreign Countries

Section 14 Simple Linear Regression: Introduction to Least Squares Regression

ECLT5810 E-Commerce Data Mining Technique SAS Enterprise Miner -- Regression Model I. Regression Node

Section 6: Model Selection, Logistic Regression and more...

Forecasting Methods. What is forecasting? Why is forecasting important? How can we evaluate a future demand? How do we make mistakes?

Causal Forecasting Models

Multiple Regression in SPSS This example shows you how to perform multiple regression. The basic command is regression : linear.

Estimation of σ 2, the variance of ɛ

MULTIPLE REGRESSION AND ISSUES IN REGRESSION ANALYSIS

Chapter 10. Key Ideas Correlation, Correlation Coefficient (r),

Forecasting in STATA: Tools and Tricks

Homework 8 Solutions

Forecast. Forecast is the linear function with estimated coefficients. Compute with predict command

New Work Item for ISO Predictive Analytics (Initial Notes and Thoughts) Introduction

2. What is the general linear model to be used to model linear trend? (Write out the model) = or

Chapter 4: Vector Autoregressive Models

ADVANCED FORECASTING MODELS USING SAS SOFTWARE

Data Mining Lab 5: Introduction to Neural Networks

Multivariate Logistic Regression

(More Practice With Trend Forecasts)

Chapter 27 Using Predictor Variables. Chapter Table of Contents

8. Time Series and Prediction

1/27/2013. PSY 512: Advanced Statistics for Psychological and Behavioral Research 2

Introduction to Regression and Data Analysis

SAS Code to Select the Best Multiple Linear Regression Model for Multivariate Data Using Information Criteria

Time Series Analysis

Module 3: Correlation and Covariance

Model selection in R featuring the lasso. Chris Franck LISA Short Course March 26, 2013

Getting Correct Results from PROC REG

MATCHDAY September 2014

X X X a) perfect linear correlation b) no correlation c) positive correlation (r = 1) (r = 0) (0 < r < 1)

Introduction to Linear Regression

Booth School of Business, University of Chicago Business 41202, Spring Quarter 2015, Mr. Ruey S. Tsay. Solutions to Midterm

Module 5: Multiple Regression Analysis

MGT 267 PROJECT. Forecasting the United States Retail Sales of the Pharmacies and Drug Stores. Done by: Shunwei Wang & Mohammad Zainal

College Readiness LINKING STUDY

Data Mining and Data Warehousing. Henryk Maciejewski. Data Mining Predictive modelling: regression

Chapter 13 Introduction to Linear Regression and Correlation Analysis

Multiple Linear Regression

Chapter 6: Multivariate Cointegration Analysis

1) Write the following as an algebraic expression using x as the variable: Triple a number subtracted from the number

The importance of graphing the data: Anscombe s regression examples

Final Exam Practice Problem Answers

Simple Regression Theory II 2010 Samuel L. Baker

IBM SPSS Forecasting 22

7 Time series analysis

Data Mining Techniques Chapter 6: Decision Trees

" Y. Notation and Equations for Regression Lecture 11/4. Notation:

We extended the additive model in two variables to the interaction model by adding a third term to the equation.

CHAPTER 13 SIMPLE LINEAR REGRESSION. Opening Example. Simple Regression. Linear Regression

Chapter Seven. Multiple regression An introduction to multiple regression Performing a multiple regression on SPSS

Stat 412/512 CASE INFLUENCE STATISTICS. Charlotte Wickham. stat512.cwick.co.nz. Feb

COMP6053 lecture: Time series analysis, autocorrelation.

FINAL EXAM SECTIONS AND OBJECTIVES FOR COLLEGE ALGEBRA

11. Analysis of Case-control Studies Logistic Regression

17. SIMPLE LINEAR REGRESSION II

Logistic Regression.

Adequacy of Biomath. Models. Empirical Modeling Tools. Bayesian Modeling. Model Uncertainty / Selection

Robust procedures for Canadian Test Day Model final report for the Holstein breed

Section A. Index. Section A. Planning, Budgeting and Forecasting Section A.2 Forecasting techniques Page 1 of 11. EduPristine CMA - Part I

Simple Linear Regression Inference

Auxiliary Variables in Mixture Modeling: 3-Step Approaches Using Mplus

Chapter 3 Quantitative Demand Analysis

Bill Burton Albert Einstein College of Medicine April 28, 2014 EERS: Managing the Tension Between Rigor and Resources 1

Transcription:

5. Multiple regression QBUS6840 Predictive Analytics https://www.otexts.org/fpp/5

QBUS6840 Predictive Analytics 5. Multiple regression 2/39 Outline Introduction to multiple linear regression Some useful predictors Seasonal Dummy variables Other dummy predictors Trend Example: Australian quarterly beer production Other things to keep in mind Selecting predictors Residual diagnostics

QBUS6840 Predictive Analytics 5. Multiple regression 3/39 Outline Introduction to multiple linear regression Some useful predictors Seasonal Dummy variables Other dummy predictors Trend Example: Australian quarterly beer production Other things to keep in mind Selecting predictors Residual diagnostics

QBUS6840 Predictive Analytics 5. Multiple regression 4/39 Example: Australian quarterly beer production I Figure 5.1: Australian quarterly beer production.

Introduction to multiple linear regression I The general form of a multiple regression is y i = β 0 + β 1 x 1,i + β 2 x 2,i + + β k x k,i + e i, where y i is the variable to be forecast and x 1,i,..., x k,i are the k predictor variables. Each of the predictor variables must be numerical. The coefficients β 1,..., β k measure the effect of each predictor after taking account of the effect of all other predictors in the model. Thus, the coefficients measure the marginal effects of the predictor variables. As for simple linear regression, when forecasting we require the following assumptions for the errors (e 1,..., e N ): 1. the errors have mean zero; 2. the errors are uncorrelated with each other; 3. the errors are uncorrelated with each predictor xj,i. It is also useful to have the errors normally distributed with constant variance in order to produce prediction intervals, but this is not necessary for forecasting.

QBUS6840 Predictive Analytics 5. Multiple regression 6/39 Estimation of the model The values of the coefficients β 0,..., β k are obtained by finding the minimum sum of squares of the errors. That is, we find the values of β 0,..., β k which minimize N ei 2 = i=1 N (y i β 0 β 1 x 1,i β k x k,i ) 2. i=1 This is called least squares estimation because it the least value of the sum of squared errors. In practice, the calculation is always done using a computer package. Finding the best estimates of the coefficients is often called fitting the model to the data. When we refer to the estimated coefficients, we will use the notation ˆβ 0,..., ˆβ k. The equations for these will be given in Section 5/5.

Fitted values, forecast values, residuals and R 2 I Predictions of y can be calculated by ignoring the error in the regression equation. That is ŷ = ˆβ 0 + ˆβ 1 x 1 + ˆβ 2 x 2 + + ˆβ k x k. Plugging in values of x 1,..., x k into the right hand side of this equation gives a prediction of y for that combination of predictors. When this calculation is done using values of the predictors from the data that were used to estimate the model, we call the resulting values of ŷ the fitted values. These are predictions of the data used in estimating the model. They are not genuine forecasts as the actual value of y for that set of predictors was used in estimating the model, and so the value of ŷ is affected by the true value of y. When the values of x 1,..., x k are new values (i.e., not part of the data that were used to estimate the model), the resulting value of ŷ is a genuine forecast.

QBUS6840 Predictive Analytics 5. Multiple regression 8/39 Fitted values, forecast values, residuals and R 2 II The difference between the y observations and the fitted values are the residuals : e i = y i ŷ i = y i ˆβ 0 ˆβ 1 x 1 ˆβ 2 x 2 ˆβ k x k. As with simple regression (see Section 4/2), the residuals have zero mean and are uncorrelated with any of the predictors. The R 2 value was introduced in Section 4/4. The value of R 2 can also be calculated as the proportion of variation in the forecast variable that is explained by the regression model: R 2 (ŷi ȳ) 2 = (yi ȳ) 2

QBUS6840 Predictive Analytics 5. Multiple regression 9/39 Outline Introduction to multiple linear regression Some useful predictors Seasonal Dummy variables Other dummy predictors Trend Example: Australian quarterly beer production Other things to keep in mind Selecting predictors Residual diagnostics

QBUS6840 Predictive Analytics 5. Multiple regression 10/39 Seasonal Dummy variables I For example, suppose we are forecasting daily electricity demand and we want to account for the day of the week as a predictor. Then the following dummy variables can be created. Day D1 D2 D3 D4 D5 D6 Monday 1 0 0 0 0 0 Tuesday 0 1 0 0 0 0 Wednesday 0 0 1 0 0 0 Thursday 0 0 0 1 0 0 Friday 0 0 0 0 1 0 Saturday 0 0 0 0 0 1 Sunday 0 0 0 0 0 0 Monday 1 0 0 0 0 0 Tuesday 0 1 0 0 0 0 Wednesday 0 0 1 0 0 0 Thursday 0 0 0 1 0 0.......

Seasonal Dummy variables II Notice that only six dummy variables are needed to code seven categories. That is because the seventh category (in this case Sunday) is specified when the dummy variables are all set to zero. Many beginners will try to add a seventh dummy variable for the seventh category. This is known as the dummy variable trap because it will cause the regression to fail. There will be too many parameters to estimate. The general rule is to use one fewer dummy variables than categories. So for quarterly data, use three dummy variables; for monthly data, use 11 dummy variables; and for daily data, use six dummy variables. The interpretation of each of the coefficients associated with the dummy variables is that it is a measure of the effect of that category relative to the omitted category. In the above example, the coefficient associated with Monday will measure the effect of Monday compared to Sunday on the forecast variable.

Other dummy predictors Outliers: If there is an outlier in the data, rather than omit it, you can use a dummy variable to remove its effect. In this case, the dummy variable takes value one for that observation and zero everywhere else. Public holidays: For daily data, the effect of public holidays can be accounted for by including a dummy variable predictor taking value one on public holidays and zero elsewhere. Easter: Easter is different from most holidays because it not held on the same date each year and the effect can last for several days. In this case, a dummy variable can be used with value one where any part of the holiday falls in the particular time period and zero otherwise.

Trend I A linear trend is easily accounted for by including the predictor x 1,t = t. A piecewise linear trend with a bend at time can be specified by including the following predictors in the model. x 1,t = t { 0 t < τ x 2,t = (t τ) t τ A quadratic or higher order trend is obtained by specifying x 1,t = t, x 2,t = t 2,... However, it is not recommended that quadratic or higher order trends are used in forecasting. When they are extrapolated, the resulting forecasts are often very unrealistic.

Trend II A better approach is to use a piecewise linear trend which bends at some time. If the trend bends at time τ, then it can be specified by including the following predictors in the model. x 1,t = t { 0 t < τ x 2,t = (t τ) t τ If the associated coefficients of x 1,t and x 2,t are β 1 and β 2, then β 1 gives the slope of the trend before time τ, while the slope of the line after time τ is given by β 1 + β 2.

QBUS6840 Predictive Analytics 5. Multiple regression 15/39 Outline Introduction to multiple linear regression Some useful predictors Seasonal Dummy variables Other dummy predictors Trend Example: Australian quarterly beer production Other things to keep in mind Selecting predictors Residual diagnostics

Example: Australian quarterly beer production I We can model the Australian beer production data using a regression model with a linear trend and quarterly dummy variables: y t = β 0 + β 1 t + β 2 d 2,t + β 3 d 3,t + β 4 d 4,t + e t, here d i,t = 1 if t is in quarter i and 0 otherwise. The first quarter variable has been omitted, so the coefficients associated with the other quarters are measures of the difference between those quarters and the first quarter. Estimation results: There is a strong downward trend of 0.382 megalitres per quarter. On average, the second quarter has production of 34.0 megalitres lower than the first quarter, the third quarter has production of 18.1 megalitres lower than the first quarter, and the fourth quarter has production 76.1 megalitres higher than the first quarter. The model explains 92.1% of the variation in the beer production data. The following plots show the actual values compared to the predicted values.

QBUS6840 Predictive Analytics 5. Multiple regression 17/39 Example: Australian quarterly beer production II Figure 5.5: Time plot of beer production and predicted beer production.

QBUS6840 Predictive Analytics 5. Multiple regression 18/39 Example: Australian quarterly beer production III Figure 5.6: Actual beer production plotted against predicted beer production.

Example: Australian quarterly beer production IV Figure 5.7: Forecasts from the regression model for beer production. The dark blue region shows 80% prediction intervals and the light blue region shows 95% prediction intervals.

QBUS6840 Predictive Analytics 5. Multiple regression 20/39 Outline Introduction to multiple linear regression Some useful predictors Seasonal Dummy variables Other dummy predictors Trend Example: Australian quarterly beer production Other things to keep in mind Selecting predictors Residual diagnostics

Intervention variables It is often necessary to model interventions that may have affected the variable to be forecast. For example, competitor activity, advertising expenditure, industrial action, and so on, can all have an effect. When the effect lasts only for one period, we use a spike variable. This is a dummy variable taking value one in the period of the intervention and zero elsewhere. A spike variable is equivalent to a dummy variable for handling an outlier. Other interventions have an immediate and permanent effect. If an intervention causes a level shift (i.e., the value of the series changes suddenly and permanently from the time of intervention), then we use a step variable. A step variable takes value zero before the intervention and one from the time of intervention onwards. Another form of permanent effect is a change of slope. Here the intervention is handled using a piecewise linear trend as discussed earlier (where is the time of intervention).

Trading days The number of trading days in a month can vary considerably and can have a substantial effect on sales data. To allow for this, the number of trading days in each month can be included as a predictor. An alternative that allows for the effects of different days of the week has the following predictors. x 1 = # Mondays in month; x 2 = # Tuesdays in month;. x 7 = # Sundays in month.

Distributed lags It is often useful to include advertising expenditure as a predictor. However, since the effect of advertising can last beyond the actual campaign, we need to include lagged values of advertising expenditure. So the following predictors may be used. x 1 = advertising for previous month; x 2 = advertising for two months previously;. x m = advertising for m months previously. It is common to require the coefficients to decrease as the lag increases. In Chapter 9 we discuss methods to allow this constraint to be implemented.

QBUS6840 Predictive Analytics 5. Multiple regression 24/39 Outline Introduction to multiple linear regression Some useful predictors Seasonal Dummy variables Other dummy predictors Trend Example: Australian quarterly beer production Other things to keep in mind Selecting predictors Residual diagnostics

Adjusted R 2 I Computer output for regression will always give the R 2 value, discussed in Section 5/1. However, it is not a good measure of the predictive ability of a model. Imagine a model which produces forecasts that are exactly 20% of the actual values. In that case, the R 2 value would be 1 (indicating perfect correlation), but the forecasts are not very close to the actual values. In addition, R 2 does not allow for degrees of freedom. Adding any variable tends to increase the value of R 2, even if that variable is irrelevant. For these reasons, forecasters should not use R 2 to determine whether a model will give good predictions. An equivalent idea is to select the model which gives the minimum sum of squared errors (SSE), given by SSE = N ei 2. i=1

QBUS6840 Predictive Analytics 5. Multiple regression 26/39 Adjusted R 2 II Minimizing the SSE is equivalent to maximizing R 2 and will always choose the model with the most variables, and so is not a valid way of selecting predictors. An alternative, designed to overcome these problems, is the adjusted R 2 (also called R-bar-squared ): R 2 = 1 (1 R 2 N 1 ) N k 1, where N is the number of observations and k is the number of predictors. This is an improvement on R 2 as it will no longer increase with each added predictor. Using this measure, the best model will be the one with the largest value of R 2. Maximizing R 2 is equivalent to minimizing the following estimate of the variance of the forecast errors: ˆσ 2 = SSE N k 1.

QBUS6840 Predictive Analytics 5. Multiple regression 27/39 Adjusted R 2 III Maximizing R 2 works quite well as a method of selecting predictors, although it does tend to err on the side of selecting too many predictors.

Cross-validation As discussed in Section 2/5, cross-validation is a very useful way of determining the predictive ability of a model. In general, leave-one-out cross-validation for regression can be carried out using the following steps. 1. Remove observation i from the data set, and fit the model using the remaining data. Then compute the error (ei = y i ŷ i ) for the omitted observation. (This is not the same as the residual because the ith observation was not used in estimating the value of ŷ i.) 2. Repeat step 1 for i = 1,..., N. 3. Compute the MSE from e1,..., en. We shall call this the CV. For many forecasting models, this is a time-consuming procedure, but for regression there are very fast methods of calculating CV so it takes no longer than fitting one model to the full data set. The equation for computing CV is given in Section 5/5. Under this criterion, the best model is the one with the smallest value of CV.

Akaike s Information Criterion A closely-related method is Akaike s Information Criterion, which we define as ( ) SSE AIC = N log + 2(k + 2), N where N is the number of observations used for estimation and k is the number of predictors in the model. Different computer packages use slightly different definitions for the AIC, although they should all lead to the same model being selected. The k + 2 part of the equation occurs because there are k + 2 parameters in the model the k coefficients for the predictors, the intercept and the variance of the residuals. The model with the minimum value of the AIC is often the best model for forecasting. For large values of N, minimizing the AIC is equivalent to minimizing the CV value.

QBUS6840 Predictive Analytics 5. Multiple regression 30/39 Corrected Akaike s Information Criterion For small values of N, the AIC tends to select too many predictors, and so a bias-corrected version of the AIC has been developed. AIC c = AIC + 2(k + 2)(k + 3). N k 3 As with the AIC, the AICc should be minimized.

Schwarz Bayesian Information Criterion A related measure is Schwarz s Bayesian Information Criterion (known as SBIC, BIC or SC): ( ) SSE BIC = N log + (k + 2) log(n). N As with the AIC, minimizing the BIC is intended to give the best model. The model chosen by BIC is either the same as that chosen by AIC, or one with fewer terms. This is because BIC penalizes the SSE more heavily than the AIC. For large values of N, minimizing BIC is similar to leave-v-out cross-validation when v = N[1 1/(log(N) 1)]. Many statisticians like to use BIC because it has the feature that if there is a true underlying model, then with enough data the BIC will select that model. However, in reality there is rarely if ever a true underlying model, and even if there was a true underlying model, selecting that model will not necessarily give the best forecasts (because the parameter estimates may not be accurate).

Best subset regression Where possible, all potential regression models can be fitted (as was done in the above example) and the best one selected based on one of the measures discussed here. This is known as best subsets regression or all possible subsets regression. It is recommended that one of CV, AIC or AICc be used for this purpose. If the value of N is large enough, they will all lead to the same model. Most software packages will at least produce AIC, although CV and AICc will be more accurate for smaller values of N. While R 2 is very widely used, and has been around longer than the other measures, its tendency to select too many variables makes it less suitable for forecasting than either CV, AIC or AICc. Also, the tendency of BIC to select too few variables makes it less suitable for forecasting than either CV, AIC or AICc.

Stepwise regression If there are a large number of predictors, it is not possible to fit all possible models. For example, 40 predictors leads to 2 40 > 1 trillion possible models! Consequently, a strategy is required to limit the number of models to be explored. An approach that works quite well is backwards stepwise regression: 1. Start with the model containing all potential predictors. 2. Try subtracting one predictor at a time. Keep the model if it improves the measure of predictive accuracy. 3. Iterate until no further improvement. It is important to realise that a stepwise approach is not guaranteed to lead to the best possible model. But it almost always leads to a good model. If the number of potential predictors is too large, then this backwards stepwise regression will not work and the starting model will need to use only a subset of potential predictors. In this case, an extra step needs to be inserted in which predictors are also added one at a time, with the model being retained if it improves the measure of predictive accuracy.

QBUS6840 Predictive Analytics 5. Multiple regression 34/39 Outline Introduction to multiple linear regression Some useful predictors Seasonal Dummy variables Other dummy predictors Trend Example: Australian quarterly beer production Other things to keep in mind Selecting predictors Residual diagnostics

Scatterplots of residuals against predictors Figure 5.8: The residuals from the regression model for credit scores plotted against each of the predictors in the model. QBUS6840 Predictive Analytics 5. Multiple regression 35/39

Scatterplot of residuals against fitted values Figure 5.9: The residuals from the credit score model plotted against the fitted values obtained from the model.

QBUS6840 Predictive Analytics 5. Multiple regression 37/39 Autocorrelation in the residuals Figure 5.10: Residuals from the regression model for beer production.

QBUS6840 Predictive Analytics 5. Multiple regression 38/39 Histogram of residuals Figure 5.11: Histogram of residuals from regression model for beer production.

QBUS6840 Predictive Analytics 5. Multiple regression 39/39 Outline Introduction to multiple linear regression Some useful predictors Seasonal Dummy variables Other dummy predictors Trend Example: Australian quarterly beer production Other things to keep in mind Selecting predictors Residual diagnostics