E C O N S T A T S     About EconStatsTM     Calendar     Data     Regression Examples     Links  
      EXAMPLE:   Three-Independent Variables Regression Example   |   No Intercept

I. Data and Summary Stats 
Three-Independent Variables Regression Example
Observations :  n=10
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
sum 61677887
mean 6.1006.7007.8008.700
StD ≡ σ 2.726 3.268 2.860 3.592
Means and Standard Deviations
 Mean 
 Var 
 StD 
 Mx= Σxi/n   
 Varx≡σx2 = Σ(x-Mx)2 / n-1 
 StDx≡σx=Varx1/2
y 6.100 7.433 2.726
x1 6.700 10.68 3.268
x2 7.800 8.178 2.860
x3 8.700 12.90 3.592
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
y7.4332.0331.4672.367
x12.03310.68-0.40006.344
x21.467-0.40008.1785.489
x32.3676.3445.48912.90
Correlation Matrix -- Corr(xi,xj)=Σ[(xi-Mxi)(xj-Mxj)] / (n-1)σiσj
y x1 x2 x3
y 1.000 0.228 0.188 0.242
x1 0.228 1.000 -0.043 0.541
x2 0.188 -0.043 1.000 0.534
x3 0.242 0.541 0.534 1.000
The basic input matrices are:
  y =  
(10x1)  
5
4
9
3
5
5
8
5
5
12
 
  X = 
(10x3)
454
453
498
587
559
8108
9713
51414
14612
999
 
   X' = 
(3x10)  
44455895149
559851071469
4387981314129



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 (10x1) X (independent vars) is (nxk) or (10x3) b (betas) is (kx1) or (3x1) 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 (3x1)
    427
    489
    552

(2) X'X Matrix (3x3)
    545 519 640
    519 682 728
    640 728 873
(3) Determinant Det(X'X)≡|X'X|
i.e. the determinant of matrix of X'X Det(X'X) = 4769697 Det(X'X) = 545*682*873 - 545*728*728 ... - 519*519*873 + 519*728*640 ... + 640*519*728 - 640*682*640 (4) Cofactors(X'X) i.e. cofactor matrix of X 'X (3x3)
    65402
    12833
    -58648
    
    12833
    66185
    -64600
    
    -58648
    -64600
    102329
    
(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.
    65402
    12833
    -58648
    
    12833
    66185
    -64600
    
    -58648
    -64600
    102329
    

(6) Inverse Matrix, inv(X'X)≡(X'X)-1
= adj(X'X)/|X'X| = adj(X'X)/4769697 (3x3)
    0.01371
    0.002691
    -0.01230
    
    0.002691
    0.01388
    -0.01354
    
    -0.01230
    -0.01354
    0.02145
    
(7) Beta Matrix (β) b = [X'X-1].[X'y] , this is (3x1). Finally we can calculate b through matrix multiplication.
    Betas
    β 1 0.3833
    β 2 0.4581
    β 3 -0.03071
  =   X'X-1
0.01371 0.002691 -0.01230
0.002691 0.01388 -0.01354
-0.01230 -0.01354 0.02145
  X   X'y
427
489
552

Yhat1= + 0.3833x4 + 0.4581x5 + -0.03071x4 = 3.7009
Yhat2= + 0.3833x4 + 0.4581x5 + -0.03071x3 = 3.7316
Yhat3= + 0.3833x4 + 0.4581x9 + -0.03071x8 = 5.4104
Yhat4= + 0.3833x5 + 0.4581x8 + -0.03071x7 = 5.3663
Yhat5= + 0.3833x5 + 0.4581x5 + -0.03071x9 = 3.9306
Yhat6= + 0.3833x8 + 0.4581x10 + -0.03071x8 = 7.4017
Yhat7= + 0.3833x9 + 0.4581x7 + -0.03071x13 = 6.2572
Yhat8= + 0.3833x5 + 0.4581x14 + -0.03071x14 = 7.8999
Yhat9= + 0.3833x14 + 0.4581x6 + -0.03071x12 = 7.7464
Yhat10= + 0.3833x9 + 0.4581x9 + -0.03071x9 = 7.2962


ESS
=(3.701 - 6.100)^2
=(3.732 - 6.100)^2
=(5.410 - 6.100)^2
=(5.366 - 6.100)^2
=(3.931 - 6.100)^2
=(7.402 - 6.100)^2
=(6.257 - 6.100)^2
=(7.900 - 6.100)^2
=(7.746 - 6.100)^2
=(7.296 - 6.100)^2
=26.1857781112721

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.3833x4 + 0.4581x5 + -0.03071x4 = 3.70156.1001.6885.7561.210 e1 = 5 - 3.701 = 1.2991.688
2 Yhat2 = Σβixi,2 = 0.3833x4 + 0.4581x5 + -0.03071x3 = 3.73246.1000.072055.6094.410 e2 = 4 - 3.732 = 0.26840.07205
3 Yhat3 = Σβixi,3 = 0.3833x4 + 0.4581x9 + -0.03071x8 = 5.41096.10012.890.47568.410 e3 = 9 - 5.410 = 3.59012.89
4 Yhat4 = Σβixi,4 = 0.3833x5 + 0.4581x8 + -0.03071x7 = 5.36636.1005.5990.53839.610 e4 = 3 - 5.366 = -2.3665.599
5 Yhat5 = Σβixi,5 = 0.3833x5 + 0.4581x5 + -0.03071x9 = 3.93156.1001.1444.7061.210 e5 = 5 - 3.931 = 1.0691.144
6 Yhat6 = Σβixi,6 = 0.3833x8 + 0.4581x10 + -0.03071x8 = 7.40256.1005.7681.6951.210 e6 = 5 - 7.402 = -2.4025.768
7 Yhat7 = Σβixi,7 = 0.3833x9 + 0.4581x7 + -0.03071x13 = 6.25786.1003.0370.024723.610 e7 = 8 - 6.257 = 1.7433.037
8 Yhat8 = Σβixi,8 = 0.3833x5 + 0.4581x14 + -0.03071x14 = 7.90056.1008.4093.2401.210 e8 = 5 - 7.900 = -2.9008.409
9 Yhat9 = Σβixi,9 = 0.3833x14 + 0.4581x6 + -0.03071x12 = 7.74656.1007.5432.7111.210 e9 = 5 - 7.746 = -2.7467.543
10 Yhat10 = Σβixi,10 = 0.3833x9 + 0.4581x9 + -0.03071x9 = 7.296126.10022.131.43134.81 e10 = 12 - 7.296 = 4.70422.13
RSS =
Σ(yobs - yhatobs)2
ESS =
Σ(yhatobs - My)2
TSS =
Σ(yobs - My)2
e'e=Σeobs2
sum->68.2726.1966.9068.27


(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 = 9.75302773800037
    Coef value StD(β) tStat(β)
    β1 = 0.01371 * 427
    + 0.002691 * 489
    + -0.01230 * 552
    = 0.3833
    (9.753 * 0.01371)1/2
    = 0.3657
    0.3833 / 0.3657
    = 1.048
    β2 = 0.002691 * 427
    + 0.01388 * 489
    + -0.01354 * 552
    = 0.4581
    (9.753 * 0.01388)1/2
    = 0.3679
    0.4581 / 0.3679
    = 1.245
    β3 = -0.01230 * 427
    + -0.01354 * 489
    + 0.02145 * 552
    = -0.03071
    (9.753 * 0.02145)1/2
    = 0.4574
    -0.03071 / 0.4574
    = -0.06714
(12) Table of Outputs:
    yobs = β1 X obs,1 + β2 X obs,2 + β3 X obs,3 + eobs
    0.3833 0.4581 -0.03071
    (1.048)(1.245)(-0.06714) <- tstats
    r2 = -0.020496 | adj r2 = -0.530744
(13) RSS = Sum{y - y_hat }^2 = 68.2711941660026 TSS = Sum{y - y_avg }^2 = 66.9 ESS(a)= Sum{y_hat - y_avg }^2 = 26.1857781112721 we use the ESSb (below) cuz smthn wrng w ESS when no intercept. ESS(b)= TSS-RSS -1.37119416600258 note: TSS = ESS + RSS (14) r2 = ESS/TSS = -0.020496175874478 (15) adjusted r2 = ESS/TSS = -0.530744263811717 (16) F-stat = [ESS/(k-1)] / [RSS/(n-k)] = -4.68638800461949E-02 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.47500522305087 ________________________________________________________ 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.