Multiple Linear Regression¶
Multiple Linear Regression¶
By minimizing the sum squared error in a fashion similar to simple linear regression case, we can obtain the regression coefficients as follows (\(X\) is \(n \times p+1\) size with the first column containing all \(1s)\)
We note that the coefficients are linear combinations of \(Y\) and thus normally distributed themselves.
\(\hat{\beta}\) is a linear combination of independent \(Y_{i}s\) and is normally distributed. Also, note that \(X^{T}X\) is symmetric and so will be it's inverse.
An unbiased estimator of \(\sigma^{2}\) is
where the denominator is chosen to make the estimator unbiased. it can be shown that
with \(\hat{\beta}\) and \(\hat{\sigma}^{2}\) independent random variables.
Confidence Intervals¶
The mean response for any new input is also a random variable with the distributions
Utilizing the unbiased estimate of \(\sigma^{2}\) defined above, we can get the confidence and prediction intervals as follows (using t-distribution after dividing the normal distribution of response with the estimator of \(\sigma^{2}\)) for \(1-\alpha\) confidence
Hypopthesis Testing¶
Single Coefficient¶
To test
we utilize some of the above defined distributions
where variance utilizes the diagonal entry of variance of \(\beta\). If we know the actual variance \(\sigma^{2}\), we replace it in the above equation to get a normal distribution instead. A large value of the Z-score will lead to the elimination of the null hypothesis meaning the coefficient is not zero. The \(1-\alpha\) confidence intervals for \(\beta_{j}\) then become
Group of Coefficients, F-test¶
Suppose we have a set of \(k\) coefficients for a categorical variable and we wish to test
Then, we use the F-test assuming \(H_{0}\) is true
Multiple Outputs¶
We want to predict multiple outputs \(Y_{1}, Y_{2}, \ldots, Y_{k}\) from the same set of variables. The \(RSS\) then becomes
Thus, the problem is similar to doing the linear regression independently on each of the \(Y_{j}s\). One important assumption here is that the errors between different \(Y_{j}\) are not correlated with each other.
Coefficient Interpretation¶
The interpretation of coefficients for quantitative variables is straightforward. Further, suppose the equation has the form
Then, \(\beta_{1}\) denotes the change in \(y\) that will be caused by changing the value of \(X_{1}\) by 1 unit, provided all other inputs are constant. If we change two variables simultaneously, we can see their interaction together keeping the remaining variables constant.
However, this procedure is not straightforward for qualitative/categorical variables. Suppose we have one numeric variable, say age, and a variable denoting gender which we will constraint to have two values, \(0\) denoting male and \(1\) denoting female. The regression equation becomes
Thus, \(\beta_{gender} (<0)\) signifies how much \(y\) is less for males compared to females. The coefficient in itself has no meaning unless compared with respect to a base value.
Suppose we were to change the convention to \(-1\) for females and \(1\) for males, then
Now, \(2\beta_{gender}\) gives us the difference between the value of \(y\) between males and females, and \(\beta_{gender}\) denotes the change on either side from the base value of \(\beta_{age}x_{age} + \epsilon\). This new \(\beta\) should be have of the original coefficient because the real relation has stayed the same. Thus, the interpretation of coefficients changes based on how the variable gets defined.
In case of \(n\) levels, we will create \(n-1\) variables (since the last variable is perfectly correlated with all the remaining ones). Then, the coefficient of the \(i^{th}\) level is simply the increment over the base (last) level. Note that there is no coefficient for the last level, and all the other coefficients are relative to this level.
Hierarchical Principle¶
If we include an interaction in the model, we should include all the main effects, even if their p-values of those coefficients are insignificant. Simply put, if \(X_{1}X_{2}\) appears in the model, \(X_{1}\) and \(X_{2}\) should also be there. Similarly, for a categorical variable, either all the categories are present in the model, or none of them are present. It is alright to just use a single category, but then the remaining categories together constitute the base cateogory and in essence, all categories are still present in the model, albiet in a different form.
Importance of interactions¶
Suppose we build a bank balance model dependent on income, and if a person is a student or not. Basic model
The problem with this model is that for both student and non student, the effect of income is same, which is not what we want. Including interaction terms,
which gives different dependence on income (slope) for student (\(\beta_{income} + \beta_{income \times student}\)) and non student \((\beta_{income})\).