Multiple Linear Regression in Excel
Multiple Linear Regression in Excel
j
n
(x
i j
- x
avg
) y
j
, where (7a)
x
avg
=
j
n
x
j
*)/n
or
SS
R
=
i
p
b
i
j
n
x
i j
y
j
* - (
j
n
y
j
*)
2
/n (7b)
Relationships (7a-b) give the same numerical result, however, it is difficult to see the
physical meaning of SS
R
from them.
Mean square (variance) and degrees of freedom
The general expression for the mean square of an arbitrary quantity q is:
MS
q
= SS
q
/ df (8)
SS
q
is defined by (3) and df is the number of degrees of freedom associated with quantity
SS
q
. MS is also often referred to as the variance. The number of degrees of freedom could
be viewed as the difference between the number of observations n and the number of
constraints (fixed parameters associated with the corresponding sum of squares SS
q
).
1). Total mean squareMS
T
(total variance):
MS
T
= SS
T
/(n - 1) (9)
SS
T
is associated with the model (4), which has only one constraint (parameter b
0
),
therefore the number of degrees of freedom in this case is:
df
T
= n - 1 (10)
2). Residual (error) mean squareMS
E
(error variance):
MS
E
= SS
E
/ (n - k) (11)
SS
E
is associated with the random error around the regression model (1), which has k=p+1
parameters (one per each variable out of p variables total plus intercept). It means there are
k constraints and the number of degrees of freedom is :
df
E
= n - k (12)
10
3). Regression mean squareMS
R
(regression variance):
MS
R
= SS
R
/(k - 1) (13)
The number of degrees of freedom in this case can be viewed as the difference between the
total number of degrees of freedom df
T
(10) and the number of degrees of freedom for
residuals df
E
(12) :
df
R
= df
T
- df
E
= (n - 1) - (n - k)
df
R
= k - 1 = p (14)
Tests of significance and F-numbers
The F-number is the quantity which can be used to test for the statistical difference between
two variances. For example, if we have two random variables q and v, the corresponding
F- number is:
F
qv
= MS
q
/ MS
v
(15)
The variances MS
q
and MS
v
are defined by an expression of type (8). In order to tell
whether two variances are statistically different, we determine the corresponding
probability P from F-distribution function:
P=P(F
qv
, df
q
, df
v
) (16)
The quantities df
q
, df
v
- degrees of freedom for numerator and denominator - are
parameters of this function. Tabulated numerical values of P for the F-distribution can be
found in various texts on statistics or simply determined in a spreadsheet directly by using
the corresponding statistical function (e.g. in Microsoft Excel one would use FDIST(F
qv
,
df
q
, df
v
) to return the numerical value of P). An interested reader can find the analytical
form of P=P(F
qv
, df
q
, df
v
) in the literature (e.g. [1, p.383]).
The probability P given by (16) is a probability that the variances MS
q
and MS
v
are
statistically indistinguishable. On the other hand, 1-P is the probability that they are
different and is often called confidence level. Conventionally, a reasonable confidence
level is 0.95 or higher. If it turns out that 1-P < 0.95, we say that MS
q
and MS
v
are
statistically the same. If 1-P > 0.95, we say that at least with the 0.95 (or 95%) confidence
MS
q
and MS
v
are different. The higher the confidence level, the more reliable our
conclusion. The procedure just described is called the F-test.
There are several F-tests related to regression analysis. We will discuss the three most
common ones. They deal with significance of parameters in the regression model . The first
11
and the last of them is performed by spreadsheet regression tool automatically, whereas the
second one is not.
1). Significance test of all coefficients in the regression model
In this case we ask ourselves: With what level of confidence can we state that AT LEAST
ONE of the coefficients b (b
1
, b
2
, b
p
) in the regression model is significantly different
from zero?. The first step is to calculate the F-number for the whole regression (part of
the regression output (see Table 4)):
F
R
= MS
R
/ MS
E
(17)
The second step is to determine the numerical value of the corresponding probability P
R
(also part of the regression output ( see Table 4)) :
P
R
= FDIST(F
R
, df
R
, df
E
) (18)
Taking into account expressions (12) and (14) we obtain:
P
R
= FDIST(F
R
, k - 1, n - k) (18a)
Finally we can determine the confidence level 1 - P
R
. At this level of confidence, the
variance due to regression MS
R
is statistically different from the variance due to error
MS
E
. In its turn it means that the addition of p variables (x
1
, x
2
, , x
p
) to the simplest
model (4) (dependent variable y is just a constant) is a statistically significant improvement
of the fit. Thus, at the confidence level not less than 1- P
R
we can say: At least ONE of
coefficients in the model is significant. F
R
could be also used to compare two models
describing the same experimental data: the higher F
R
the more adequate the corresponding
model.
Example
In our illustrative exercise we have P
R
= 6.12E-09 (Table 4), the corresponding level of
confidence 1 - P
R
= 0.9999. Therefore with the confidence close to 100% we can say that at
least one of coefficients b
1
, b
2
and b
3
is significant for the model y = b
0
+ b
1
x
1
+ b
2
x
2
+
b
3
x
3
, where x
1
=z, x
2
= z
2
and x
3
= z
3
.
NOTE: From this test, however, we can not be sure that ALL coefficients b
1
,b
2
and b
3
are non-zero .
If 1- P
R
is not big enough (usually less than 0.95), we conclude that ALL the coefficients
in the regression model are zero (in other words, the hypothesis that the variable y is just
a constant is better than it is function of variables x (x
1
, x
2
, , x
p
) ).
12
2). Significance test of subset of coefficients in the regression model
Now we want to decide With what level of confidence can we be sure that at least ONE
of the coefficients in a selected subset of all the coefficients is significant?. Let us test a
subset of the last m coefficients in the model with a total of p coefficients (b
1
, b
2
, b
p
).
Here we need to consider two models:
y = b
0
+ b
1
x
1
+ b
2
x
2
+ b
p
x
p
(unrestricted) (19)
and
y = b
0
+ b
1
x
1
+ b
2
x
+ b
p-m
x
p-m
(restricted) (20)
These models are called unrestricted (19) and restricted (20) respectively. We need to
perform two separate least square regression analyses for each model.
From the regression output (see Table 4) for each model we obtain the corresponding error
sum of squares SS
E
and SS
E
as well as variance MS
E
for the unrestricted model. The next
step is to calculate the F-number for testing a subset of m variables by hand (it is not
part of Microsoft Excel ANOVA for an obvious reason, i.e. you must decide how many
variables to include in the subset):
F
m
= {( SS
E
- SS
E
) / m} / MS
E
(21)
F
m
could be viewed as an indicator of whether the reduction in the error variance due to the
addition of the subset of m variables to the restricted model (20) (( SS
E
- SS
E
) / m ) is
statistically significant with respect to the overall error variance MS
E
for the unrestricted
model (19). It is equivalent to testing the hypothesis that at least one of coefficients in the
subset is not zero. In the final step, we determine probability P
m
(also by hand):
P
m
= FDIST(F
m
, m, n - k) (22)
At the confidence level 1- P
m
at least ONE of the coefficients in the subset of m is
significant. If 1- P
m
is not big enough (less than 0.95) we state that ALL m coefficients
in the subset are insignificant.
13
Example
The regression output for the unrestricted model (y = b
0
+ b
1
x
1
+ b
2
x
2
+ b
3
x
3
, where x
1
=z,
x
2
= z
2
and x
3
= z
3
) is presented in Table 4.
Say, we want to test whether the quadratic and
the cubic terms are significant. In this case the restricted model is:
y = b
0
+ b
1
x
1
, (restricted model) (23)
where x
1
= z
The subset of parameters consists of two parameter and m=2. By analogy with the input
table for the unrestricted model (Table 2) we prepare one for the restricted model:
Table 5. Regression input for restricted model
Data point # Dependent var. Independent var.
j y* x
1
(=z)
1 20.6947 2.5
2 28.5623 3.1
3 157.0020 8.1
4 334.6340 12.2
5 406.5697 13.5
6 696.0331 17.9
7 945.1385 21.0
We perform an additional regression using this input table and as part of ANOVA obtain:
Table 6. Regression ANOVA output for the restricted model
df SS MS F Significance
F
Regression 1 689216 689216 100 1.70-4
Residual (error) 5 34415.70 6883
Total 6 723632
From Table 4 and Table 6 we have:
SS
E
= 1.70 (error sum of squares; unrestricted model)
MS
E
= 0.57 (error mean square; unrestricted model)
df
E
=(n - k)= 3 (degrees of freedom; unrestricted model)
SS
E
= 34415.70 (error sum of squares; restricted model)
Now we are able to calculate F
m=2
:
F
m=2
= {(34415.70-1.70)/ 2} / 0.57
F
m=2
= 30187.72
14
Using the Microsoft Excel function for the F-distribution we determine the probability
P
m=2
:
P
m=2
= FDIST(30187.72, 2, 3)
P
m=2
= 3.50E-07
Finally we calculate the level of confidence 1- P
m=2
:
1-P
m=1
= 1 - 3.50E-07
1-P
m=1
= 0.99999
The confidence level is high (more than 99.99 %). We conclude that at least one of the
parameters (b
2
or b
3
) in the subset is non-zero. However, we can not be sure that both
quadratic and cubic terms are significant.
3). Significance test of an individual coefficient in the regression model
Here the question to answer is: With what confidence level can we state that the ith
coefficient b
i
in the model is significant?. The corresponding F-number is:
F
i
= b
i
2
/ [se(b
i
)]
2
(24)
se(b
i
) is the standard error in the individual coefficient b
i
and is part of the ANOVA output
(see Table 4a). The corresponding probability
P
i
= FDIST(F
i
, 1, n - k) (25)
leads us to the confidence level 1- P
i
at which we can state that coefficient b
i
is significant.
If this level is lower than desired one we say that coefficient b
i
is insignificant. F
i
is not
part of spreadsheet regression output, but might be calculated by hand if needed.
However, there is another statistics for testing individual parameters, which is part of
ANOVA (see Table 4a):
t
i
= b
i
/ se(b
i
) (26)
The t
i
- number is the square root of F
i
(expression (24)). It has a Students distribution
(see [1, p. 381] for the analytical form of the distribution). The corresponding probability is
numerically the same as that given by (25). There is a statistical function in Microsoft
Excel which allows one to determine P
i
( part of ANOVA (see Table 4a)):
P
i
= TDIST(t
i
, n-k, 2) (27)
15
Parameters of the function (27) are: the number of degrees of freedom df (df
E
=n - k) and form of test (TL=2).
If TL=1 a result for a one-tailed distribution is returned; if TL=2 two-tailed distribution result is returned.
An interested reader can find more information about the issue in ref. [1]
Example
In our illustration P
0
=0.7881 and P
3
= 0.6731 (see Table 4a) corresponds to fairly low
confidence levels, 1 - P
0
= 0.2119 and 1 - P
3
= 0.3269. This suggests that parameters b
0
and
b
3
are not significant. The confidence levels for b
1
and b
2
are high (1 - P
1
= 1 - 0.0282 =
0.9718 and 1- P
2
= 1 - 0.0001 = 0.9999), which means that they are significant.
In conclusion of this F-test discussion, it should be noted that in case we remove even one
insignificant variable from the model, we need to test the model once again, since
coefficients which were significant in certain cases might become insignificant after
removal and visa versa. It is a good practice to use a reasonable combination of all three
tests in order to achieve the most reliable conclusions.
Confidence interval
In the previous section we were obtaining confidence levels given F-numbers or t-
numbers. We can go in an opposite direction: given a desired minimal confidence level 1-P
(e.g. 0.95) calculate the related F- or t-number. Microsoft Excel provides two statistical
functions for that purpose:
F
(1-P)
=FINV (P, df
q
, df
v
) (28)
t
(1-P)
=TINV(P, df ) (29)
df
q
, df
v
- degrees of freedom of numerator and denominator, respectively (see (15))
df - degree of freedom associated with a given t-test (varies from test to test)
NOTE: in expression (29) P
is the probability associated with so called two-
tailed Students distribution. A one- tailed distribution has the different
probability The relationship between the two is:
=P/2 (30)
Values of F-numbers and t-numbers for various probabilities and degrees of freedom
are tabulated and can be found in any text on statistics [1,2,3,4] . Usually the one-tailed
Students distribution is presented.
16
Knowing the t-number for a coefficient b
i
we can calculate the numerical interval which
contains the coefficient b
i
with the desired probability 1-P
i
:
b
L, (1- Pi)
= b
i
- se(b
i
)*t
(1-Pi)
(lower limit) (31)
b
U, (1- Pi)
= b
i
+ se(b
i
)*t
(1-Pi)
(upper limit) (31a)
t
(1-Pi)
=TINV(P
i
, n-k) (32)
The standard errors for individual parameters se(b
i
) are part of ANOVA (Table 4a). The
interval [b
L, (1- Pi)
; b
U, (1- Pi)
] is called the confidence interval of parameter b
i
with the 1-P
i
confidence level. The upper and lower limits of this interval at a 95% confidence are listed
in the ANOVA output by default ( Table 4a; columns Lower 95% and Upper 95%). If
in addition to this default, the confidence interval at a confidence other than 95% is desired,
the box Confidence level should be checked and the value of the alternative confidence
entered in the corresponding window of the Regression input dialog box (see Fig. 1).
Example
For the unrestricted model (1b), the lower and upper 95% limits for intercept are -5.1413
and 6.1872 respectively (see Table 4a). The fact that with the 95% probability zero falls
in this interval is consistent with our conclusion of insignificance of b
0
made in the course
of F-testing of individual parameters (see Example at the end of previous section). The
confidence intervals at the 95% level for b
1
and b
2
do not include zero. This also agrees
with the F-test of individual parameters.
I n fact, analysis whether zero falls in a confidence interval could be viewed as a different
way to perform the F-test (t-test) of individual parameters and must not be used as an
additional proof of conclusions made in such a test.
Regression statistics output
The information contained in the Regression statistics output characterizes the
goodness of the model as a whole. Note that quantities listed in this output can be
expressed in terms of the regression F-number F
R
(Table 4) which we have already used
for the significance test of all coefficients.
17
Example
For our unrestricted model (1b) the output is:
Table 7. Regression statistics output*
Multiple R 0.99999882
R Square (R
2
) 0.99999765
Adjusted R Square (R
2
adj
) 0.9999953
Standard Error (S
y
) 0.75291216
Observations (n) 7
* - Corresponding notation used in this handout is given in parenthesis
Standard error (S
y
):
S
y
= (MS
E
)
0.5
(33)
MS
E
is an error variance discussed before (see expression (11)). Quantity S
y
is an estimate
of the standard error (deviation) of experimental values of the dependent variable y* with
respect to those predicted by the regression model. It is used in statistics for different
purposes. One of the applications we saw in the discussion of Residual output
(Standardized residuals; see expression (2a)).
Coefficient of determination R
2
(or R Square):
R
2
=SS
R
/ SS
T
= 1 - SS
E
/SS
T
(34)
SS
R
, SS
E
and SS
T
are regression, residual (error) and total sum of squares defined by (7),
(6a) and (3a) respectively. The coefficient of determination is a measure of the regression
model as whole. The closer R
2
is
to one, the better the model (1) describes the data. In the
case of a perfect fit R
2
=1.
Adjusted coefficient of determination R
2
(or Adjusted R Square):
R
2
adj
=1- {SS
E
/ (n-k)} / {SS
T
/ (n-1)} (35)
SS
E
and SS
T
are the residual (error) and the total sum of squares (see expressions (6a) and
(3a)). The significance of R
2
adj
is basically the same as that of R
2
(the closer to one the
better). Strictly speaking R
2
adj
should be used as an indicator of an adequacy of the model,
since it takes in to account not only deviations, but also numbers of degrees of freedom.
18
Multiple correlation coefficient R:
R = ( SS
R
/ SS
T
)
0.5
(36)
This quantity is just the square root of coefficient of determination.
Example
The fact that R
2
adj
= 0.9999953 in our illustration is fairly close to 1 (see Table 7) suggests
that overall model (1b) is adequate to fit the experimental data presented in Table 1.
However, it does not mean that there are no insignificant parameters in it.
REGRESSION OUTPUT FORMULA MAP
For references, the following tables present a summary of the formula numbers for
individual items in the Microsoft Excel Regression Output. Variables in parenthesis,
introduced and used in this handout, do not appear in the output.
Table 8. Formula map of Regression statistics output
Multiple R (36)
R Square (R
2
) (34)
Adjusted R Square (R
2
adj
) (35)
Standard Error (S
y
) (33)
Observations (n)
Table 9. Formula map of Residual output
Observation (j) Predicted Y (y
j
) Residuals (r
j
) Standard Residuals(r
j
)
1 (1) (2) (2a)
2 (1) (2) (2a)
Table 10. Formula map of ANOVA output (part I)
df SS MS F Significance F
Regression (df
R
) (14) (SS
R
) (7) (MS
R
) (13) (F
R
) (17) (P
R
) (18)
Residual (error) (df
E
) (12) (SS
E
) (6a) (MS
E
) (11)
Total (df
T
) (10) (SS
T
) (3a) (MS
T
)* (9)
*- not reported in Microsoft Excel Regression output
19
Table 10a. Formula map of ANOVA output (part II)
Coefficients
(b
i
)
Standard
Error (se(b
i
))
t Stat
(t
i
)
P-value
(P
i
)
Lower
95%
(b
L,(1-Pi)
)
Upper
95%
(b
U,(1-
Pi)
)
Intercept (b
0
) (26) (25) (27) (31) (31a)
X Variable 1 (x
1
) (26) (25) (27) (31) (31a)
X Variable 2 (x
2
) (26) (25) (27) (31) (31a)
LITERATURE
1. Afifi A.A., Azen S.P. Statistical analysis. Computer oriented approach, Academic
press, New York (1979)
2. Natrella M.G. Experimental Statistics, National Bureau of Standards, Washington
DC (1963)
3. Neter J., Wasserman W. Applied linear statistical models, R.D. Irwin Inc.,
Homewood, Illinois (1974)
4. Gunst R.F., Mason R.L. Regression analysis and its application, Marcel Dekker Inc.,
NewYork (1980)
5. Shoemaker D.P., Garland C.W., Nibler J.W. Experiments in Physical Chemistry,
The McGraw-Hill Companies Inc. (1996)