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

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


Data Table 
obsyi intcptxi,1xi,2xi,3
1. 11731127
2. 80115217090
3. 56114113262
4. 231533145
5. 73199172152
6. 741133108158
7. 391449784
8. 381438698
9. 38113349100
10. 46150114126
sum 46810921970942
mean 46.80192.109794.20
StD ≡ σ 24.710 44.43 54.53 42.90
Means and Standard Deviations
 Mean 
 Var 
 StD 
 Mx= Σxi/n   
 Varx≡σx2 = Σ(x-Mx)2 / n-1 
 StDx≡σx=Varx1/2
y 46.80 610.4 24.71
x1 92.10 1974 44.43
x2 97 2974 54.53
x3 94.20 1841 42.90
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
y610.4668.71225781.4
x1668.719741015399.1
x21225101529741428
x3781.4399.114281841
Correlation Matrix -- Corr(xi,xj)=Σ[(xi-Mxi)(xj-Mxj)] / (n-1)σiσj
y x1 x2 x3
y 1.000 0.609 0.909 0.737
x1 0.609 1.000 0.419 0.209
x2 0.909 0.419 1.000 0.610
x3 0.737 0.209 0.610 1.000
The basic input matrices are:
  y =  
(10x1)  
1
80
56
23
73
74
39
38
38
46
 
  X = 
(10x4)
1731127
115217090
114113262
1533145
199172152
1133108158
1449784
1438698
113349100
150114126
 
   X' = 
(4x10)  
1111111111
731521415399133444313350
1117013231172108978649114
279062451521588498100126



II. Regression Calculations yi = alpha + 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 (10x1) X (independent vars) is (nxk) or (10x4) b (betas) is (kx1) or (4x1) e (errors) is (nx1) or (10x1) 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 (4x1)
    468
    49121
    56421
    51118

(2) X'X Matrix (4x4)
    10 921 970 942
    921 102587 98473 90350
    970 98473 120856 104224
    942 90350 104224 105302
(3) Determinant Det(X'X)≡|X'X|
i.e. the determinant of matrix of X'X Det(X'X) = 40582798368264 Det(X'X) = 10*102587*120856*105302 - 10*102587*104224*104224 - 10*98473*98473*105302 ... + 10*98473*104224*90350 + 10*90350*98473*104224 - 10*90350*120856*90350 ... - 921*921*120856*105302 + 921*921*104224*104224 + 921*98473*970*105302 ... - 921*98473*104224*942 - 921*90350*970*104224 + 921*90350*120856*942 ... + 970*921*98473*105302 - 970*921*104224*90350 - 970*102587*970*105302 ... + 970*102587*104224*942 + 970*90350*970*90350 - 970*90350*98473*942 ... - 942*921*98473*104224 + 942*921*120856*90350 + 942*102587*970*104224 ... - 942*102587*120856*942 - 942*98473*970*90350 + 942*98473*98473*942 (4) Cofactors(X'X) i.e. cofactor matrix of X 'X (4x4)
    38095748040474
    -174282234420
    8070420582
    -199245278238
    
    -174282234420
    2782723496
    -1051886916
    212594812
    
    8070420582
    -1051886916
    2813520690
    -1954385802
    
    -199245278238
    212594812
    -1954385802
    3919752854
    
(5) Adj(X'X) i.e. adjugate matrix of X'X, this is just the
transpose of the cofactor matrix. (4x4)
For a symmetric matrix, will be same as cofactor matrix.
    38095748040474
    -174282234420
    8070420582
    -199245278238
    
    -174282234420
    2782723496
    -1051886916
    212594812
    
    8070420582
    -1051886916
    2813520690
    -1954385802
    
    -199245278238
    212594812
    -1954385802
    3919752854
    

(6) Inverse Matrix, inv(X'X)≡(X'X)-1
= adj(X'X)/|X'X| = adj(X'X)/40582798368264 (4x4)
    0.9387
    -0.004294
    0.000199
    -0.004910
    
    -0.004294
    0.000069
    -0.000026
    0.000005
    
    0.000199
    -0.000026
    0.000069
    -0.000048
    
    -0.004910
    0.000005
    -0.000048
    0.000097
    
(7) Beta Matrix (β) b = [X'X-1].[X'y] , this is (4x1). Finally we can calculate b through matrix multiplication.
    Betas
    alpha -11.38
    β 1 0.1637
    β 2 0.2697
    β 3 0.1798
  =   X'X-1
0.9387 -0.004294 0.000199 -0.004910
-0.004294 0.000069 -0.000026 0.000005
0.000199 -0.000026 0.000069 -0.000048
-0.004910 0.000005 -0.000048 0.000097
  X   X'y
468
49121
56421
51118

Yhat1= + -11.38x1 + 0.1637x73 + 0.2697x11 + 0.1798x27 = 8.3958
Yhat2= + -11.38x1 + 0.1637x152 + 0.2697x170 + 0.1798x90 = 75.5397
Yhat3= + -11.38x1 + 0.1637x141 + 0.2697x132 + 0.1798x62 = 58.4556
Yhat4= + -11.38x1 + 0.1637x53 + 0.2697x31 + 0.1798x45 = 13.7514
Yhat5= + -11.38x1 + 0.1637x99 + 0.2697x172 + 0.1798x152 = 78.5498
Yhat6= + -11.38x1 + 0.1637x133 + 0.2697x108 + 0.1798x158 = 67.9360
Yhat7= + -11.38x1 + 0.1637x44 + 0.2697x97 + 0.1798x84 = 37.0900
Yhat8= + -11.38x1 + 0.1637x43 + 0.2697x86 + 0.1798x98 = 36.4772
Yhat9= + -11.38x1 + 0.1637x133 + 0.2697x49 + 0.1798x100 = 41.5950
Yhat10= + -11.38x1 + 0.1637x50 + 0.2697x114 + 0.1798x126 = 50.2095


ESS
=(8.396 - 46.80)^2
=(75.54 - 46.80)^2
=(58.46 - 46.80)^2
=(13.75 - 46.80)^2
=(78.55 - 46.80)^2
=(67.94 - 46.80)^2
=(37.09 - 46.80)^2
=(36.48 - 46.80)^2
=(41.59 - 46.80)^2
=(50.21 - 46.80)^2
=5223.25946426799

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-11.38x1 = 0.1637x73 + 0.2697x11 + 0.1798x27 = 8.396146.8054.7014752098 e1 = 1 - 8.396 = -7.39654.70
2 Yhat2 = Σβixi,2 + -11.38x1 = 0.1637x152 + 0.2697x170 + 0.1798x90 = 75.548046.8019.89826.01102 e2 = 80 - 75.54 = 4.46019.89
3 Yhat3 = Σβixi,3 + -11.38x1 = 0.1637x141 + 0.2697x132 + 0.1798x62 = 58.465646.806.030135.984.64 e3 = 56 - 58.46 = -2.4566.030
4 Yhat4 = Σβixi,4 + -11.38x1 = 0.1637x53 + 0.2697x31 + 0.1798x45 = 13.752346.8085.541092566.4 e4 = 23 - 13.75 = 9.24985.54
5 Yhat5 = Σβixi,5 + -11.38x1 = 0.1637x99 + 0.2697x172 + 0.1798x152 = 78.557346.8030.801008686.4 e5 = 73 - 78.55 = -5.55030.80
6 Yhat6 = Σβixi,6 + -11.38x1 = 0.1637x133 + 0.2697x108 + 0.1798x158 = 67.947446.8036.77446.7739.8 e6 = 74 - 67.94 = 6.06436.77
7 Yhat7 = Σβixi,7 + -11.38x1 = 0.1637x44 + 0.2697x97 + 0.1798x84 = 37.093946.803.64894.2860.84 e7 = 39 - 37.09 = 1.9103.648
8 Yhat8 = Σβixi,8 + -11.38x1 = 0.1637x43 + 0.2697x86 + 0.1798x98 = 36.483846.802.319106.677.44 e8 = 38 - 36.48 = 1.5232.319
9 Yhat9 = Σβixi,9 + -11.38x1 = 0.1637x133 + 0.2697x49 + 0.1798x100 = 41.593846.8012.9227.0977.44 e9 = 38 - 41.59 = -3.59512.92
10 Yhat10 = Σβixi,10 + -11.38x1 = 0.1637x50 + 0.2697x114 + 0.1798x126 = 50.214646.8017.7211.620.6400 e10 = 46 - 50.21 = -4.21017.72
RSS =
Σ(yobs - yhatobs)2
ESS =
Σ(yhatobs - My)2
TSS =
Σ(yobs - My)2
e'e=Σeobs2
sum->270.352235494270.3


(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 = 45.0567559553338
    Coef value StD(β) tStat(β)
    alpha = 0.9387 * 468
    + -0.004294 * 49121
    + 0.000199 * 56421
    + -0.004910 * 51118
    = -11.38
    (45.06 * 0.9387)1/2
    = 6.504
    -11.38 / 6.504
    = -1.750
    β1 = -0.004294 * 468
    + 0.000069 * 49121
    + -0.000026 * 56421
    + 0.000005 * 51118
    = 0.1637
    (45.06 * 0.000069)1/2
    = 0.05558
    0.1637 / 0.05558
    = 2.946
    β2 = 0.000199 * 468
    + -0.000026 * 49121
    + 0.000069 * 56421
    + -0.000048 * 51118
    = 0.2697
    (45.06 * 0.000069)1/2
    = 0.05589
    0.2697 / 0.05589
    = 4.825
    β3 = -0.004910 * 468
    + 0.000005 * 49121
    + -0.000048 * 56421
    + 0.000097 * 51118
    = 0.1798
    (45.06 * 0.000097)1/2
    = 0.06597
    0.1798 / 0.06597
    = 2.726
(12) Table of Outputs:
    yobs = alpha + β1 X obs,1 + β2 X obs,2 + β3 X obs,3 + eobs
    -11.38 0.1637 0.2697 0.1798
    (-1.750)(2.946)(4.825)(2.726) <- tstats
    r2 = 0.950790 | adj r2 = 0.926185
(13) RSS = Sum{y - y_hat }^2 = 270.340535732003 TSS = Sum{y - y_avg }^2 = 5493.6 ESS(a)= Sum{y_hat - y_avg }^2 = 5223.25946426799 we use the ESSb (below) cuz smthn wrng w ESS when no intercept. ESS(b)= TSS-RSS 5223.259464268 note: TSS = ESS + RSS (14) r2 = ESS/TSS = 0.950789912674384 (15) adjusted r2 = ESS/TSS = 0.926184869011576 (16) F-stat = [ESS/(k-1)] / [RSS/(n-k)] = 38.6420737839032 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.97657903346925 ________________________________________________________ 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.