E C O N S T A T S     About EconStatsTM     Calendar     Data     Regression Examples     Links  
      EXAMPLE:   Three-variables, 20 observations   |   No Intercept

I. Data and Summary Stats 
Three-variables, 20 observations
Observations :  n=20
Independent Variables :  k=3
No Intercept


Data Table 
obsyixi,1xi,2xi,3
1. 5454
2. 4453
3. 9498
4. 3587
5. 5559
6. 58108
7. 89713
8. 551414
9. 514612
10. 12999
11. 46127
12. 8957
13. 10111119
14. 168614
15. 291214
16. 912717
17. 91295
18. 35810
19. 1112107
20. 21172223
sum 154168180210
mean 7.7008.400910.50
StD ≡ σ 4.736 3.719 4.039 5.186
Means and Standard Deviations
 Mean 
 Var 
 StD 
 Mx= Σxi/n   
 Varx≡σx2 = Σ(x-Mx)2 / n-1 
 StDx≡σx=Varx1/2
y 7.700 22.43 4.736
x1 8.400 13.83 3.719
x2 9 16.32 4.039
x3 10.50 26.89 5.186
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 x3
y22.4310.818.47413.11
x110.8113.836.68411.42
x28.4746.68416.3212.53
x313.1111.4212.5326.89
Correlation Matrix -- Corr(xi,xj)=Σ[(xi-Mxi)(xj-Mxj)] / (n-1)σiσj
y x1 x2 x3
y 1.000 0.614 0.443 0.534
x1 0.614 1.000 0.445 0.592
x2 0.443 0.445 1.000 0.598
x3 0.534 0.592 0.598 1.000
The basic input matrices are:
  y =  
(20x1)  
5
4
9
3
5
5
8
5
5
12
4
8
10
16
2
9
9
3
11
21
 
  X = 
(20x3)
454
453
498
587
559
8108
9713
51414
14612
999
6127
957
111119
8614
91214
12717
1295
5810
12107
172223
 
   X' = 
(3x20)  
44455895149691189121251217
559851071469125116127981022
43879813141297719141417510723



II. Regression Calculations yi = b1 xi,1 + b2 xi,2 + b3 xi,3 + ui The q.c.e. basic equation in matrix form is: y = Xb + e where y (dependent variable) is (nx1) or (20x1) X (independent vars) is (nxk) or (20x3) b (betas) is (kx1) or (3x1) e (errors) is (nx1) or (20x1) 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)
    1499
    1547
    1866

(2) X'X Matrix (3x3)
    1674 1639 1981
    1639 1930 2128
    1981 2128 2716
(3) Determinant Det(X'X)≡|X'X|
i.e. the determinant of matrix of X'X Det(X'X) = 142959642 Det(X'X) = 1674*1930*2716 - 1674*2128*2128 ... - 1639*1639*2716 + 1639*2128*1981 ... + 1981*1639*2128 - 1981*1930*1981 (4) Cofactors(X'X) i.e. cofactor matrix of X 'X (3x3)
    713496
    -235956
    -335538
    
    -235956
    622223
    -315413
    
    -335538
    -315413
    544499
    
(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.
    713496
    -235956
    -335538
    
    -235956
    622223
    -315413
    
    -335538
    -315413
    544499
    

(6) Inverse Matrix, inv(X'X)≡(X'X)-1
= adj(X'X)/|X'X| = adj(X'X)/142959642 (3x3)
    0.004991
    -0.001651
    -0.002347
    
    -0.001651
    0.004352
    -0.002206
    
    -0.002347
    -0.002206
    0.003809
    
(7) Beta Matrix (β) b = [X'X-1].[X'y] , this is (3x1). Finally we can calculate b through matrix multiplication.
    Betas
    β 1 0.5484
    β 2 0.1421
    β 3 0.1757
  =   X'X-1
0.004991 -0.001651 -0.002347
-0.001651 0.004352 -0.002206
-0.002347 -0.002206 0.003809
  X   X'y
1499
1547
1866

Yhat1= + 0.5484x4 + 0.1421x5 + 0.1757x4 = 3.6070
Yhat2= + 0.5484x4 + 0.1421x5 + 0.1757x3 = 3.4313
Yhat3= + 0.5484x4 + 0.1421x9 + 0.1757x8 = 4.8784
Yhat4= + 0.5484x5 + 0.1421x8 + 0.1757x7 = 5.1089
Yhat5= + 0.5484x5 + 0.1421x5 + 0.1757x9 = 5.0339
Yhat6= + 0.5484x8 + 0.1421x10 + 0.1757x8 = 7.2139
Yhat7= + 0.5484x9 + 0.1421x7 + 0.1757x13 = 8.2144
Yhat8= + 0.5484x5 + 0.1421x14 + 0.1757x14 = 7.1917
Yhat9= + 0.5484x14 + 0.1421x6 + 0.1757x12 = 10.6384
Yhat10= + 0.5484x9 + 0.1421x9 + 0.1757x9 = 7.7959
Yhat11= + 0.5484x6 + 0.1421x12 + 0.1757x7 = 6.2258
Yhat12= + 0.5484x9 + 0.1421x5 + 0.1757x7 = 6.8759
Yhat13= + 0.5484x11 + 0.1421x11 + 0.1757x19 = 10.9340
Yhat14= + 0.5484x8 + 0.1421x6 + 0.1757x14 = 7.6997
Yhat15= + 0.5484x9 + 0.1421x12 + 0.1757x14 = 9.1008
Yhat16= + 0.5484x12 + 0.1421x7 + 0.1757x17 = 10.5624
Yhat17= + 0.5484x12 + 0.1421x9 + 0.1757x5 = 8.7381
Yhat18= + 0.5484x5 + 0.1421x8 + 0.1757x10 = 5.6360
Yhat19= + 0.5484x12 + 0.1421x10 + 0.1757x7 = 9.2316
Yhat20= + 0.5484x17 + 0.1421x22 + 0.1757x23 = 16.4905


ESS
=(3.607 - 7.700)^2
=(3.431 - 7.700)^2
=(4.878 - 7.700)^2
=(5.109 - 7.700)^2
=(5.034 - 7.700)^2
=(7.214 - 7.700)^2
=(8.214 - 7.700)^2
=(7.192 - 7.700)^2
=(10.64 - 7.700)^2
=(7.796 - 7.700)^2
=(6.226 - 7.700)^2
=(6.876 - 7.700)^2
=(10.93 - 7.700)^2
=(7.700 - 7.700)^2
=(9.101 - 7.700)^2
=(10.56 - 7.700)^2
=(8.738 - 7.700)^2
=(5.636 - 7.700)^2
=(9.232 - 7.700)^2
=(16.49 - 7.700)^2
=174.584038870215

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,1 = 0.5484x4 + 0.1421x5 + 0.1757x4 = 3.60757.7001.94116.757.290 e1 = 5 - 3.607 = 1.3931.941
2 Yhat2 = Σβixi,2 = 0.5484x4 + 0.1421x5 + 0.1757x3 = 3.43147.7000.323518.2213.69 e2 = 4 - 3.431 = 0.56870.3235
3 Yhat3 = Σβixi,3 = 0.5484x4 + 0.1421x9 + 0.1757x8 = 4.87897.70016.997.9621.690 e3 = 9 - 4.878 = 4.12216.99
4 Yhat4 = Σβixi,4 = 0.5484x5 + 0.1421x8 + 0.1757x7 = 5.10937.7004.4476.71422.09 e4 = 3 - 5.109 = -2.1094.447
5 Yhat5 = Σβixi,5 = 0.5484x5 + 0.1421x5 + 0.1757x9 = 5.03457.7000.0011487.1087.290 e5 = 5 - 5.034 = -0.033890.001148
6 Yhat6 = Σβixi,6 = 0.5484x8 + 0.1421x10 + 0.1757x8 = 7.21457.7004.9020.23637.290 e6 = 5 - 7.214 = -2.2144.902
7 Yhat7 = Σβixi,7 = 0.5484x9 + 0.1421x7 + 0.1757x13 = 8.21487.7000.045980.26460.09000 e7 = 8 - 8.214 = -0.21440.04598
8 Yhat8 = Σβixi,8 = 0.5484x5 + 0.1421x14 + 0.1757x14 = 7.19257.7004.8040.25847.290 e8 = 5 - 7.192 = -2.1924.804
9 Yhat9 = Σβixi,9 = 0.5484x14 + 0.1421x6 + 0.1757x12 = 10.6457.70031.798.6347.290 e9 = 5 - 10.64 = -5.63831.79
10 Yhat10 = Σβixi,10 = 0.5484x9 + 0.1421x9 + 0.1757x9 = 7.796127.70017.670.00919018.49 e10 = 12 - 7.796 = 4.20417.67
11 Yhat11 = Σβixi,11 = 0.5484x6 + 0.1421x12 + 0.1757x7 = 6.22647.7004.9542.17313.69 e11 = 4 - 6.226 = -2.2264.954
12 Yhat12 = Σβixi,12 = 0.5484x9 + 0.1421x5 + 0.1757x7 = 6.87687.7001.2640.67920.09000 e12 = 8 - 6.876 = 1.1241.264
13 Yhat13 = Σβixi,13 = 0.5484x11 + 0.1421x11 + 0.1757x19 = 10.93107.7000.872310.465.290 e13 = 10 - 10.93 = -0.93400.8723
14 Yhat14 = Σβixi,14 = 0.5484x8 + 0.1421x6 + 0.1757x14 = 7.700167.70068.900.00000068.89 e14 = 16 - 7.700 = 8.30068.90
15 Yhat15 = Σβixi,15 = 0.5484x9 + 0.1421x12 + 0.1757x14 = 9.10127.70050.421.96232.49 e15 = 2 - 9.101 = -7.10150.42
16 Yhat16 = Σβixi,16 = 0.5484x12 + 0.1421x7 + 0.1757x17 = 10.5697.7002.4418.1931.690 e16 = 9 - 10.56 = -1.5622.441
17 Yhat17 = Σβixi,17 = 0.5484x12 + 0.1421x9 + 0.1757x5 = 8.73897.7000.068601.0781.690 e17 = 9 - 8.738 = 0.26190.06860
18 Yhat18 = Σβixi,18 = 0.5484x5 + 0.1421x8 + 0.1757x10 = 5.63637.7006.9494.26022.09 e18 = 3 - 5.636 = -2.6366.949
19 Yhat19 = Σβixi,19 = 0.5484x12 + 0.1421x10 + 0.1757x7 = 9.232117.7003.1272.34610.89 e19 = 11 - 9.232 = 1.7683.127
20 Yhat20 = Σβixi,20 = 0.5484x17 + 0.1421x22 + 0.1757x23 = 16.49217.70020.3477.27176.9 e20 = 21 - 16.49 = 4.51020.34
RSS =
Σ(yobs - yhatobs)2
ESS =
Σ(yhatobs - My)2
TSS =
Σ(yobs - My)2
e'e=Σeobs2
sum->242.2174.6426.2242.2


(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 = 14.249761617009
    Coef value StD(β) tStat(β)
    β1 = 0.004991 * 1499
    + -0.001651 * 1547
    + -0.002347 * 1866
    = 0.5484
    (14.25 * 0.004991)1/2
    = 0.2667
    0.5484 / 0.2667
    = 2.056
    β2 = -0.001651 * 1499
    + 0.004352 * 1547
    + -0.002206 * 1866
    = 0.1421
    (14.25 * 0.004352)1/2
    = 0.2490
    0.1421 / 0.2490
    = 0.5708
    β3 = -0.002347 * 1499
    + -0.002206 * 1547
    + 0.003809 * 1866
    = 0.1757
    (14.25 * 0.003809)1/2
    = 0.2330
    0.1757 / 0.2330
    = 0.7542
(12) Table of Outputs:
    yobs = β1 X obs,1 + β2 X obs,2 + β3 X obs,3 + eobs
    0.5484 0.1421 0.1757
    (2.056)(0.5708)(0.7542) <- tstats
    r2 = 0.431614 | adj r2 = 0.325042
(13) RSS = Sum{y - y_hat }^2 = 242.245947489152 TSS = Sum{y - y_avg }^2 = 426.2 ESS(a)= Sum{y_hat - y_avg }^2 = 174.584038870215 we use the ESSb (below) cuz smthn wrng w ESS when no intercept. ESS(b)= TSS-RSS 183.954052510848 note: TSS = ESS + RSS (14) r2 = ESS/TSS = 0.431614388810061 (15) adjusted r2 = ESS/TSS = 0.325042086711947 (16) F-stat = [ESS/(k-1)] / [RSS/(n-k)] = 4.3030907570008 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 = 2.60747380254565 ________________________________________________________ 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.