Last time we discussed simple linear regression, which is a model that predicts the value of a dependent variable based on the value of a single independent variable.
But, often in the real world, we may want to model our dependent variable from multiple independent variables.
Or, mathematically represented as,
Yi=β0+β1x1i+β2x2i+…+βpxpi+ei.
To have a “good” fit, we try to minimize RSS, however, since we now have multiple variables, we need to minimize the RSS with respect to all the variables.
Now, we can write the RSS, denoted as RSS(β), in matrix form as,
RSS(β)=(Y−Xβ)T(Y−Xβ)
We can also write our predictor for β^ as,
β^=(XTX)−1XTY
Since we are trying to generalize linear regression with this, it must mean that simple linear regression is a special case of multiple linear regression.
This new adjusted coefficient of determination is due to the fact of, if we add variables (even irrelevant variables) R2 never decreases.
Thus to compare the model with different number of variables, we use this.
We can also test a subset of coefficients using ANOVA.
Let’s look at a simple example and the corresponding R code.
Data from surveys of customers of 168 Italian restaurants in the target area are available, with the following variables:
Yx1x2x3x4=Price=the price (in $US) of a dinner (including 1 drink & a tip)=Food=customer rating of the food (out of 30)=Deˊcor=customer rating of the decor (out of 30)=Service=customer rating of the service (out of 30)=East=dummy variable=1 if the restaurant is east of Fifth Avenue, 0 if it is west
So, let’s first develop a regression model that predicts the price of a dinner.
We can see that Décor has the largest effect on the price (note that Food, Décor and Service are each measured on the same 0 to 30 scale so it is meaningful to compare the regression coefficients).
We can also observe that, if a new restaurant wants to choose a location, it should be east of Fifth Avenue, since our dummy variable is statistically significantly larger than 0.
Interaction Effects
Consider we want to model Y based on a continuous predictor x and a dummy variable d.
Compared to using a single variable x, the additional effect of d could be,
d has no effect on Y, that is, Y=β0+β1x+e.
d produces only an additive change in Y, that is,
Y=β0+β1x+β2d+e={β0+β1x+eβ0+β2+β1x+ed=0,d=1.
d produces an additive change in Y and also changes the size of the effect of x on Y, that is,
Y=β0+β1x+β2d+β3xd+e={β0+β1x+eβ0+β2+(β1+β3)x+ed=0,d=1.
Let’s go back to our example again.
After you present your model to the management team, the debate focuses on the statistical insignificance of the Service variable.
The team feels like the model may be too simple to reflect the reality of an Italian restaurant in Manhattan.
In particular, there is general consensus amongst the team that restaurants on the east of Fifth Avenue are very different from those on the west side.
As such, you have been asked to consider different models for the East and West.
Determine which (if any) of the data points are outliers.
Assess the effect of each predictor variable, having adjusted for the effect of other predictor variables using added variable plots.
Assess the extent of collinearity among the predictor variables using variance inflation factors.
Examine whether the assumption of normality of error and constant error variance is reasonable.
Leverage Points and Residuals
Remember from simple linear regression, leverage points are points that have extreme values of the predictor variable.
Y^=Xβ^=X(XTX)−1XTY=HY,
where H=X(XTX)−1XT (also called the hat matrix).
Let hij be the (i,j)-entry of H, then,
Y^i=hiiYi+j=i∑hijYj.
The rule of thumb for leverage points are,
hii>2×average(hii)=2×np+1.
The residuals are defined as,
e^=Y−Y^=(I−H)Y.
We can show that,
Var(e^∣X)=σ2(I−H),
and that the standardized residuals are,
ri=s1−hiie^i,
where,
s=n−p−1∑i=1ne^i2.
Any pattern in a residual plot indicates that an incorrect model has been fit, but the pattern in general does not provide direct information on how the model is misspecified.
Added Variable Plots
Assume we originally have the model,
Y=Xβ+e.
With an additional predictor, we now consider,
Y=Xβ+Zα+e,
where,
Z=z1z2⋮zn.
The procedure is as follows,
Algorithm 1: Added variable plot
Perform Regression
Y=Xβ+e
to get the residual eY.X.
Perform Regression
Z=Xβ+e
to get residual eZ.X.
Plot eY.X (on y-axis)
against eZ.X (on x-axis).
Transformations
Transforming only Y using inverse response plot.
Assume the true model is actually,
Y=g(β0+β1x1+…+βpxp+e),
the inverse model is thus,
g−1(Y)=β0+β1x1+…+βpxp+e.
To use inverse response plot, an important assumption is that the predictors are pairwise linearly related.
Example: Defective rates.
We want to develop a model for number of defectives based on x1: temperature, x2: density, and x3: production rate.
To get the pairwise linear relationship, we can use the scatterplot matrix.
1
pairs(~Defective+Temperature+Density+Rate)
To get the inverse response plot, we can use the following code.
1
m1<-lm(Defective~Temperature+Density+Rate)
2
inverseResponsePlot(m1)
Collinearity of Predictors
When highly correlated predictor variables are included, they are effectively carrying very similar information about the response variable.
Thus, it is difficult for least squares to distinguish their separate effects on the response variable.
Some of the coefficients in the regression model are of the opposite sign than expected.
Consider the multiple regression model,
Y=β0+β1x1+…+βpxp+e.
Let Rj2 be the coefficient of determination R2 obtained when regressing xj on other predictors.
Then it can be shown that,
Var(β^j)=1−Rj21(n−1)Sxj2σ2.
1−Rj21 is called the variance inflation factor.
A rough guide for identifying large VIF is to use the cut-off value 5.
What do you do when collinearity exists?
Do nothing but be careful of interpretation.
Remove highly correlated variables (keep only one of them).