




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































This module will begin with the introduction of the multiple linear regression model along with its motivation with three data examples. This lesson will cover the fundamentals and objectives of multiple linear regression.
In multiple linear regression, the data consist of the response variable and a series of predicting or explanatory variables. More specifically, we observe "n" realizations of the response variable along with the corresponding predicting variables. The relationship captured is the linear relationship between the response variable and the predicting variables. In this model, the deviances, or epsilons (also called "error terms") are the difference between the response variable and the linear function in x’s. For estimating multiple linear regression, we assume that the error terms have zero mean, constant variance, and are independent. For statistical inference, we also need to assume that the error terms are normally distributed. Let’s review these assumptions in more detail. Zero mean assumption means that the expected value of the errors is zero across all errors; this also implies that the linearity assumption holds. Constant variance assumption means that it cannot be true that the model is more accurate for some parts of the population and less accurate for other parts. A violation
of this assumption means that the estimates are not as efficient in estimating the true parameters, resulting in poorly calibrated confidence and prediction intervals. Independence assumption means that the response variables are independently drawn from the data-generating process. Violation of this assumption can lead to a misleading assessment of the strength of the regression. If the normality assumption is violated, hypothesis tests and confidence or prediction intervals can be misleading. In the linear regression model, the parameters defining the regression line, the regression coefficients, β 0 , β 1 through βp, are unknown parameters. We have an additional parameter, the variance of the errors, denoted with sigma squared. Model parameters are unknown regardless of how much data we observe. But we can derive some approximations or estimates of the parameters given the data and the model assumptions. The parameter estimates will take different values if one uses different data sets, meaning that the estimates are uncertain. In a different lesson, we will describe the distribution of the estimated regression coefficients to capture this uncertainty.
In multiple linear regression, the model can be written in a matrix form. We stack up all the values of the response variable into a vector called here the Y vector. We define the design matrix as a matrix consisting of columns of predicting variables, including the column of ones corresponding to the intercept. We also stack up the regression parameters, the betas, into one vector of parameters and we stack up the error terms
In the third model, First Order Interaction model, we extend the 1st^ order model to include an interaction term between the two predicting variables. The contours of the regression function are non-parallel straight lines for any interaction model. Specifically, when x 1 is increased by 1 unit, the expected change in Y is β 1 plus β 3 times x 2 thus depending on x 2. The final example, the Second Order Interaction Model, combines aspects of these previous examples. Here, the model includes both second-order and interaction terms. In this model, a plot of the contours of the regression function yields non-parallel curves_._
Here I am contrasting the surface of the response for the 1st^ and 2nd^ order regression models with two predicting factors. While for the 1st^ order the surface is linear, for the 2 nd^ order the surface is non-linear. Note that the 2nd^ order is expressed as a linear model where the 2nd^ order factors are linear terms in the model but because we have 2 nd^ order terms, the resulting surface is non-linear.
Here I am contrasting the surface of the response for the 1st^ and 2nd^ order regression models with interactions with two predicting factors. As mentioned earlier, the regression lines are not anymore parallel. The interaction terms make the surface of the response variable non-parallel, as shown in the example on the slide. Thus, adding interaction terms to the model makes the interpretation of the relationships between the response and the predicting variables more challenging.
In Module 1, we contrasted the simple linear regression model with the ANOVA model. In simple linear regression, we considered modeling variations in the response with respect to a quantitative variable whereas in ANOVA, we considered modeling variations in the response with respect to qualitative variables. Multiple regression is a generalization of both models.
SAT is a standardized test used for college admissions in the United States. But back in 1982, SAT was not widely used for college admissions. In this example, we will study the average SAT scores by state for all the states in 1982 in the United States. The average SAT scores varied considerably by state with mean scores falling between 790 for South Carolina to 1,088 for Iowa. The researchers of this study examined compositional and demographic variables to assess to what extent the variables were tied to SAT scores. Research questions to be addressed in these examples are: ● Which variables are associated with SAT scores? ● How do the states rank? ● Which states perform best for the amount of money they spend?
The response variable is the mean SAT score, consisting of the verbal and quantitative tests combined. The predicting variables are: ● X1: "takers" The percentage of total eligible students, high school seniors, in the state who took the exam. ● X2: "income" The median income of families of test takers in hundreds of dollars. ● X3: "years" The average number of years that test takers had in social sciences, natural sciences, and humanities combined. ● X4: "public" A percentage of test takers who attended public schools. ● X5: "expend" A state expenditure on secondary schools in hundreds of dollars per student. ● X6 "rank" The median percentile of ranking of test takers.
Bike sharing systems are of great interest due to their important role in traffic management and ever-increasing number of people choosing it as their preferred mode of transport. In this study, we will address the key challenge of demand forecasting for bikes under a bike sharing program using two-years of historical data corresponding to
years 2011 and 2012 for Washington D.C., USA, one of the first bike sharing programs in the US. The data were acquired from the UCI Machine Learning Repository. The dataset included 17380 observations with 17 attributes.
Demand for bikes is dependent upon various environmental and time factors such as weather conditions, precipitation, day of week, season, hour of the day, and so on. We are interested in predicting the number of bikes rented per hour, which is the response variable. The details of attributes included in the data are listed on the slide. They include seasonal effects such as day of the week or month of the year. We also have a factor specifying weather conditions, coded as a categorical factor, as well as other weather factors. Overall, we have six qualitative predicting variables. For example, three of these predicting variables are capturing seasonality in bike rental, including day of the week, month of the year and hour of the day. We also have three quantitative variables accounting for variations in weather, more specifically, in temperature, rainfall, and wind speed, all three expected to impact bike rental.
At first glance, the year predicting variables may seem obviously to be a quantitative variable, and indeed, measures of time certainly can be. But in cases where there are only a few years across many observations (in this case we have only two different years of data), it may be better to consider year as a qualitative variable. If the observations are made over many years, then considering ‘year’ as a quantitative variable might be more appropriate. Generally, we can transform a quantitative variable into a qualitative variable, or categorical variable, when we see that there are non-linear relationships in how the predictive variable explains the response.
Typically, a regression analysis is used for the following purposes: ● Prediction of the response variable, ● Modeling the relationship of the associations between predicting variables and the response variable, ● Testing hypothesis of association relationships. Why restrict ourselves to linear models? Well, they are simpler to understand, and they're simpler mathematically. But most importantly, they work well for a wide range
2.2. Estimation & Interpretation The topic of this lesson is estimation of multiple linear regression. Specifically, I'll introduce the approach for estimating the regression coefficients and the variance parameter of the error terms. We will also learn about model interpretation along with different roles the predicting factors have in multiple linear regression.
I will begin this lesson by reviewing the multiple linear regression model and the notation of the model in matrix form. We define the design matrix as a matrix consisting of columns of predicting variables, including the column of ones corresponding to the intercept. We'll also stack up all the values of the response variable into a vector called here the Y vector. The same for the regression parameters, the betas, and the error terms. The resulting matrix formulation of the model is provided on the slide. We will be using this formulation in the estimation approach introduced in this lesson.
Estimating the model parameters in multiple linear regression is similar to the approach we learned for estimating the parameters of a regression model with a single predicting variable. Specifically, we minimize the sum of least squares, where the sum of least squares is the sum of the squared differences between the observed responses yi and the expected responses, or the linear combination β 0 +β 1 x 1 + … + βpxp. We can re-write it into a matrix format as Y - Xβ transpose times Y - Xβ. where Y is the stacked vector of responses, X is the design matrix, β is a stacked vector of parameters, all defined in the previous slide. If we use linear algebra to minimize the sum of least squares error, we obtain a system of equations with p+1 equations and p+1 unknowns, specifically the beta coefficients, including the intercept. To solve this system of equations for the beta coefficients, we need to assume that XTX
which is the inverse of XTX multiplied by the transpose of X and by Y. I will return later to this very important condition that XTX needs to be invertible when I will introduce an important concept in multiple linear regression, multicollinearity.
The fitted values are derived from the linear model by replacing the true coefficients with the estimated ones, specifically, given by X Beta hat where the estimated regression coefficients are derived as in the previous slides. We can re-write the fitted values as H times Y where H denotes the matrix that we multiply the observed vectors of the response values, y, also called the hat matrix. The hat matrix is only a function of the design matrix X and thus it depends on the design only. To obtain the residuals, we take the difference between observed and fitted. We can rewrite the residuals as (I – H) * Y, where I is the identity matrix and H again is the hat matrix. The estimated variance is now the sum of squared errors divided by n-p-1. The variance estimator for multiple linear regression is similar to the estimator for simple regression except that now we're using n-p-1 in the denominator rather than n-2. Assuming that the error terms are normally distributed, the sampling distribution of the estimated variance, or so-called mean squared errors or MSE, is a chi-squared distribution with n-p-1 degrees of freedom.
Let’s look closer at the estimator for the variance, specifically its statistical properties. We do not have the “true” error terms because we don't know the true betas. But we can replace the error terms with the residuals defined on the previous slide, I will call them here the epsilon hat. Thus, we use the sample variance of the residuals to estimate the variance of the error terms, sigma squared. The only difference from using the sample variance of the residuals vs the sample variance formula you have learned in basic statistics is the use of n-p-1 in the denominator, that is n-p-1 degrees of freedom. We will review this in the next slide. I will note here that the sampling distribution of the variance estimator is a chi-squared distribution. This is because the residuals also are going to be normally distributed when the response data are normally distributed. We reviewed this distribution when I introduced the variance estimator for the simple linear regression model.
fit the relationship between advertising expenditure and sales. But it also can be done in a multiple regression context when we add other predicting variables in the model. Thus, I will differentiate between so-called marginal and conditional models. The marginal model, or simple linear regression , captures the association of one predicting variable to the response variable marginally, that means without consideration of other factors. The conditional or multiple linear regression model captures the association of a predicting variable to the response variable, conditional of other predicting variables in the model. It’s important to highlight that the estimated regression coefficients for the conditional and marginal relationships can be different, not only in magnitude but also in sign or direction of the relationship. Thus, the two models used to capture the relationship between a predicting variable and a response variable will provide different estimates of the relationship. I will illustrate this aspect with a specific example in a different lesson.
But why do we need multiple linear regression when we can use simple linear regression? Often, the relationship between a response and a predicting variable is dependent on other factors and cannot be singled out to be estimated using a simple linear regression. Multiple linear regression allows for quantifying the relationship of a predicting variable to a response when other factors vary. One of the dangers of using multiple linear regression without much knowledge of fundamentals about regression is the interpretation of the model results. This is particularly important in the context of making causal statements when the setup of the regression does not allow so. Causality statements can only be made in a controlled environment such as randomized trials or experiments. In experimental studies, analysts can change the setting of one particular factor in the environment, holding others fixed thereby isolating its effect. But such isolation is not possible with observational data. Most of the data used in regression analysis will likely come from observational studies, which generate data without the ability to control biases and correlations among the observations, unless the regression model carefully considers biases in the observed sample. Multiple regression provides a statistical version of this practice, controlling for the bias, through its ability to statistically represent a conditional action that would otherwise be impossible. However, interpretation of relationships under multiple regression will need to be carefully considered as part of the entire multiple regression model.
Let's look at a very specific example. We take a sample of college students and determine their college GPA as well as their high school GPA and their SAT score. We then build a model of college GPA as a function of high school GPA and SAT: COLGPA = 1.3 + 0.7 HSGPA - 0.0003 SAT Based on this model, it is tempting to say that the coefficient for SAT must have the wrong sign, because it seems to say that higher values of SAT are associated with lower values of college GPA. However, what it says is that higher values of SAT are associated with lower values of college GPA, on the condition that high school GPA is held fixed. High school GPA and SAT are correlated with each other. Thus, changing SAT by one unit, holding high school GPA, may not actually even happen, it may not be possible. This simple example illustrates the fact that we cannot make direct or causal statements about how SAT impacts college GPA. We can only say that there is an associative relationship. We need to be careful in interpreting the regression coefficients when there are other predictive factors in a model that are correlated to SAT, such as high school GPA. To conclude this slide, the coefficient of multiple regression thus must be interpreted in the context of other predictors in the model. We do not want to interpret them marginally.
More explicitly or practically speaking, multiple linear regression allows including variables to explain the variability in the response variable, taking different roles. Particularly, I differentiate factors into controlling, explanatory, or predictive factors. Controlling variables can be used to control for bias selection in a sample. They're used as default variables to capture more meaningful relationships with respect to other explanatory or predicting factors. They are used in regression for observational studies, for example, when there are known sources of bias selection in the sample data. They are not necessarily of direct interest, but once a researcher identifies biases in the sample, he or she will need to correct for those biases and will do so through controlling variables. Explanatory variables can be used to explain variability in the response variable. They may be included in the model even if other similar variables are in the model. Predictive variables can be used to best predict variability in the response regardless of their explanatory power. Thus, when selecting explanatory variables, the objective is
2.3. Regression Parameter Estimation: Data Example The topic of this lesson is parameter estimation illustrated with a data example. We'll learn how to implement a multiple linear regression model in R, and how to interpret it.
Let's return to the example in which we study the relationship between advertisement expenditure and sales. We now consider other predictive variables, divided into quantitative and qualitative predicting variables.
This is a set of questions we may be interested to address in this example. A. Fit a linear regression with all the predictors and estimate the regression coefficients. What are the estimated regression coefficients and the estimated regression line? B. Interpret and compare the estimated coefficients from the conditional model versus the marginal model. Having analyzed the simple regression in Module 1, we want to compare it to the conditional model. C. Learn how the predictions of those two models will be different, and which of the predictions are more meaningful. a. What does the model predict as the advertisement expenditure increases for an additional $1,000 using the full regression model? b. Is the prediction different when compared to the prediction from the simple linear model with just the advertisement expenditure variable? D. Compare the estimated error variance under the conditional versus the marginal model. a. What is the estimate of the error variance? b. Is it different from the simple linear regression model? Why?
We will again use R to perform a multiple linear regression analysis. We have one qualitative factor and thus we use "as.factor()" command to convert the column corresponding to the region into a categorical variable in order to specify in the lm() command that this is a qualitative variable.
Using the lm() command to fit the regression model, with the response variable ‘sales’ regressed against all the predictors in the data, instead of specifying each variable explicitly, I have included here a dot after the tilde. This tells the lm() command to include all the columns (except the response) as predictors. When using this approach to fit the regression, it is thus important to first convert all qualitative predictors in the dataset using the as.factor() command. The output for this model is on the slide. Let’s review the output.
The highlighted column from the output consists of the estimated regression coefficients. The estimated β coefficient for the advertising expenditure is equal to 1.4092. We would interpret this estimate to be the expected additional gain in sales, in thousands of dollars, for each additional $100 expenditure in advertisement, while holding all other predictors fixed. A reminder here; the unit for sales is $1000 and the unit for advertising expenditure is $100. We can contrast this with the estimated coefficient from the marginal model, which was 2.772, larger than the estimated coefficient from the conditional model. The difference in the interpretation is that the estimated coefficient from the conditional model is given other predictors included in the model to explain the variability in the response while for the estimated coefficient from the marginal model is without accounting for other predicting factors.