|
EXAMPLE: Two-Variable Regression Example
|
With Intercept
From J. Johnston (1984) p178.
I. Data and Summary Stats
Two-Variable Regression Example
Observations : n=5
Independent Variables : k=2
With Intercept
Data Table
obs | yi | intcpt | xi,1 | xi,2
| 1. | 3 | 1 | 3 | 5
| 2. | 1 | 1 | 1 | 4
| 3. | 8 | 1 | 5 | 6
| 4. | 3 | 1 | 2 | 4
| 5. | 5 | 1 | 4 | 6
| | | | |
| sum | 20 | 5 | 15 | 25
| mean | 4 | 1 | 3 | 5
| StD ≡ σ | 2.646 | 0
| 1.581
| 1
|
Means and Standard Deviations
| Mean
Var
StD
| Mx= Σxi/n
Varx≡σx2 = Σ(x-Mx)2 / n-1
StDx≡σx=Varx1/2
y
| 4
| 7.000
| 2.646
|
x1
| 3
| 2.500
| 1.581
|
x2
| 5
| 1
| 1
| | | | | | |
Covariance Matrix -- Cov(xi,xj)=Σ[(xi-Mxi)(xj-Mxj)] / n-1 NOTE: be careful of MS Excel's COVAR() function, which divides by n instead of n-1.
| y | x1 | x2
| y | 7 | 4 | 2.250
| x1 | 4 | 2.500 | 1.500
| x2 | 2.250 | 1.500 | 1
|
Correlation Matrix -- Corr(xi,xj)=Σ[(xi-Mxi)(xj-Mxj)] / (n-1)σiσj
| y | x1 | x2
| y | 1.000 | 0.956 | 0.850
| x1 | 0.956 | 1.000 | 0.949
| x2 | 0.850 | 0.949 | 1.000
|
The basic input matrices are:
II. Regression Calculations
yi = alpha + b1 xi,1 + b2 xi,2 + ui
The q.c.e. basic equation in matrix form is:
y = Xb + e
where y (dependent variable) is (nx1) or (5x1)
X (independent vars) is (nxk) or (5x3)
b (betas) is (kx1) or (3x1)
e (errors) is (nx1) or (5x1)
Minimizing sum or squared errors using calculus results in the OLS eqn: b=(X'X)-1.X'y
To minimize the sum of squared errors of
a k dimensional line that describes the relationship
between the k independent variables and y we
find the set of slopes (betas) that minimizes
Σi=1 to nei2
Re-written in linear algebra we seek to min e'e
Rearranging the regression model equation, we get e = y - Xb
So e'e = (y-Xb)'(y-Xb) = y'y - 2b'X'y + b'X'Xb (see Judge et al (1985) p14 )
Differentiating by b we get 0 = - 2X'y + X'Xb -> 2X'Xb=2X'y
Rearranging, dividing both sides by 2 -> b = X'X-1X'y
So to obtain the elements of the (kx1) vector b we need the elements
of the (kxk) matrix X'X-1 and of the (kx1) matrix X'y.
Caclulating X'y is easy (see (1) below) but X'X-1 requires
first calculation of X'X then finding cofactors -- see (4) -- and
the deteminant - see (3) - in order to invert.
(1) X'y Matrix (3x1)
(2) X'X Matrix (3x3)
5
| 15
| 25
|
15
| 55
| 81
|
25
| 81
| 129
|
(3) Determinant Det(X'X)≡|X'X| i.e. the determinant of matrix of X'X
Det(X'X) = 20
Det(X'X) = 5*55*129 - 5*81*81
... - 15*15*129 + 15*81*25
... + 25*15*81 - 25*55*25
(4) Cofactors(X'X) i.e. cofactor matrix of X 'X (3x3)
53490-160
9020-30
-160-3050
| | | | | | | | |
(5) Adj(X'X) i.e. adjugate matrix of X'X, this is just the transpose of the cofactor matrix. (3x3) For a symmetric matrix, will be same as cofactor matrix.
53490-160
9020-30
-160-3050
| | | | | | | | |
(6) Inverse Matrix, inv(X'X)≡(X'X)-1 = adj(X'X)/|X'X| = adj(X'X)/20 (3x3)
26.704.500-8
4.5001-1.500
-8-1.5002.500
| | | | | | | | |
(7) Beta Matrix (β)
b = [X'X-1].[X'y] , this is (3x1).
Finally we can calculate b through matrix multiplication.
Betas
alpha | 4
| β 1 | 2.500
| β 2 | -1.500
|
| =
| X'X-1
26.70 | 4.500 | -8
| 4.500 | 1 | -1.500
| -8 | -1.500 | 2.500
|
| X
| X'y
|
Yhat1= + 4x1 + 2.500x3 + -1.500x5 = 4.0000
Yhat2= + 4x1 + 2.500x1 + -1.500x4 = 0.5000
Yhat3= + 4x1 + 2.500x5 + -1.500x6 = 7.5000
Yhat4= + 4x1 + 2.500x2 + -1.500x4 = 3.0000
Yhat5= + 4x1 + 2.500x4 + -1.500x6 = 5.0000
ESS
=(4 - 4)^2
=(0.5000 - 4)^2
=(7.500 - 4)^2
=(3 - 4)^2
=(5 - 4)^2
=26.5
REPORT
obs
| calculation of yhatobs yhatobs = Σβixi,obs
| yhatobs
| a
| yobs (data)
| Meany
| (yobs - yhatobs)2
| (yhatobs - My)2
| (yobs - My)2
| a
| eobs=yobs-yhatobs
| eobs2
|
1
| Yhat1 = Σβixi,14x1 = 2.500x3 + -1.500x5 | = 4 | 3 | 4 | 1 | 0 | 1 | e1 = 3 - 4 = -1 | 1
|
2
| Yhat2 = Σβixi,2 + 4x1 = 2.500x1 + -1.500x4 | = 0.5000 | 1 | 4 | 0.2500 | 12.25 | 9 | e2 = 1 - 0.5000 = 0.5000 | 0.2500
|
3
| Yhat3 = Σβixi,3 + 4x1 = 2.500x5 + -1.500x6 | = 7.500 | 8 | 4 | 0.2500 | 12.25 | 16 | e3 = 8 - 7.500 = 0.5000 | 0.2500
|
4
| Yhat4 = Σβixi,4 + 4x1 = 2.500x2 + -1.500x4 | = 3 | 3 | 4 | 0 | 1 | 1 | e4 = 3 - 3 = 0 | 0
|
5
| Yhat5 = Σβixi,5 + 4x1 = 2.500x4 + -1.500x6 | = 5 | 5 | 4 | 0 | 1 | 1 | e5 = 5 - 5 = 0 | 0 | | | | | | RSS = Σ(yobs - yhatobs)2 | ESS = Σ(yhatobs - My)2 | TSS = Σ(yobs - My)2 | | e'e=Σeobs2 | sum-> | | | | | 1.500 | 26.50 | 28 | | 1.500
|
(11) Betas and their t-Stats
from the covar matrix of b=σ2(X'X)-1
the var(βi) = σ2vii where vii is the ith diag element of X'X-1
where σ2 = e'e / n-k (k=num of ind vars plus 1 for the intercept if present).
and where vii is the ith diag element of X'X-1
Std(βi) = sqr root of Var(βi)
TStat(βi) = βi / Std(βi)
Estimate of σ2 = 0.75
| Coef value
| StD(β)
| tStat(β)
|
alpha =
| 26.70 * 20 + 4.500 * 76 + -8 * 109 = 4
| (0.7500 * 26.70)1/2 = 4.475
| 4 / 4.475 = 0.8939
|
β1 =
| 4.500 * 20 + 1 * 76 + -1.500 * 109 = 2.500
| (0.7500 * 1)1/2 = 0.8660
| 2.500 / 0.8660 = 2.887
|
β2 =
| -8 * 20 + -1.500 * 76 + 2.500 * 109 = -1.500
| (0.7500 * 2.500)1/2 = 1.369
| -1.500 / 1.369 = -1.095
|
(12) Table of Outputs: yobs = | alpha | + | β1 | X obs,1 + | β2 | X obs,2 + | eobs | | 4 | | 2.500 | | -1.500 | | | | (0.8939) | | (2.887) | | (-1.095) | | <- tstats | r2 = 0.946429 | adj r2 = 0.892857 |
(13) RSS = Sum{y - y_hat }^2 = 1.5
TSS = Sum{y - y_avg }^2 = 28
ESS(a)= Sum{y_hat - y_avg }^2 = 26.5
we use the ESSb (below) cuz smthn wrng w ESS when no intercept.
ESS(b)= TSS-RSS 26.5
note: TSS = ESS + RSS
(14) r2 = ESS/TSS = 0.946428571428571
(15) adjusted r2 = ESS/TSS = 0.892857142857143
(16) F-stat = [ESS/(k-1)] / [RSS/(n-k)] = 17.6666666666667
see Johnston(1984) p186
F measures the joint significance of
all explanatory variables.
Alternatively: F-stat = r2/(k-1) / (1-r2)/(n-k)
(17) Durbin-Watson Statistic (DW or d) measures autocorrelation.
DW = 1
________________________________________________________
Note, RSS, ESS and TSS stand for ...
Residual Sum of Squares (RSS),
Explained Sum of Squares (ESS), and
Total Sum of Squares (TSS).
However ESS is sometimes referred to as the Regression Sum of Squares.
and RSS is sometimes referred to as the Sum of Squares Rresidual.
Note, an alternative way of calculating TSS, ESS is...
TSS = y'Ay
ESS = bv'Xv'Ay where bv' Xv' are b' & X' wo intercept row col
RSS = TSS-ESS
Bibliography
J. Johnston (1984) Econometric Methods, 3rd ed.
Judge et al (1985) The Theory and Practice of Econometrics 2rd ed, Wiley, New York.
Donald F. Morrison (1990) Multivariate Statistical Methods, 3rd edition, McGraw Hill, New York.
A. H. Studenmund (1997) Using Econometrics: A Practical Guide, 3rd edition. Addison-Wesley, Reading.
|
|