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 dependant variable from multiple independent variables.
Or, mathematically represented as,
Yi=β0+β1x1i0β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.
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 devlop 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 resturant 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,
After you present your model to the management team, the debate foucses on the statistical insignificane of the Service variable.
The team feels like the model may be too simple to reflect the reality of a 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.
Asses the effect of each predictor variable, having adjusted for the effect of other predictor variables using added variable plots.
Asses 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(XX)−1XT (also called the hat matrix).
Let hij be the (i,j)-entry of H, then,
Yi^=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−hiiei^
where,
s=n−p−1∑i=1nei2^
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,
YXβ+e.
With an additional predictor, we now consider,
Y=Xβ+Zα+e,
where,
Z=z1z2⋮zn
The procedure is as follows,
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 higly 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).