E C O N S T A T S     About EconStatsTM     Calendar     Data     Regression Examples     Links  
      EXAMPLE:   One-Variable Regression Example   |   With Intercept
From J. Johnston (1984) p19.

I. Data and Summary Stats 
One-Variable Regression Example
Observations :  n=5
Independent Variables :  k=1
With Intercept 


Data Table 
obsyi intcptxi,1
1. 412
2. 713
3. 311
4. 915
5. 1719
sum 40520
mean 814
StD ≡ σ 5.5680 3.162
Means and Standard Deviations
 Mean 
 Var 
 StD 
 Mx= Σxi/n   
 Varx≡σx2 = Σ(x-Mx)2 / n-1 
 StDx≡σx=Varx1/2
y 8 31.00 5.568
x1 4 10.00 3.162
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
y3117.50
x117.5010
Correlation Matrix -- Corr(xi,xj)=Σ[(xi-Mxi)(xj-Mxj)] / (n-1)σiσj
y x1
y 1.000 0.994
x1 0.994 1.000
The basic input matrices are:
  y =  
(5x1)  
4
7
3
9
17
 
  X = 
(5x2)
12
13
11
15
19
 
   X' = 
(2x5)  
11111
23159



II. Regression Calculations yi = alpha + b1 xi,1 + 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 (5x2) b (betas) is (kx1) or (2x1) 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 (2x1)
    40
    230

(2) X'X Matrix (2x2)
    5 20
    20 120
(3) Determinant Det(X'X)≡|X'X|
i.e. the determinant of matrix of X'X Det(X'X) = 200 Det(X'X) = 5*120 - 20*20 (4) Cofactors(X'X) i.e. cofactor matrix of X 'X (2x2)
    120
    -20
    
    -20
    5
    
(5) Adj(X'X) i.e. adjugate matrix of X'X, this is just the
transpose of the cofactor matrix. (2x2)
For a symmetric matrix, will be same as cofactor matrix.
    120
    -20
    
    -20
    5
    

(6) Inverse Matrix, inv(X'X)≡(X'X)-1
= adj(X'X)/|X'X| = adj(X'X)/200 (2x2)
    0.6000
    -0.1000
    
    -0.1000
    0.02500
    
(7) Beta Matrix (β) b = [X'X-1].[X'y] , this is (2x1). Finally we can calculate b through matrix multiplication.
    Betas
    alpha 1.0000
    β 1 1.750
  =   X'X-1
0.6000 -0.1000
-0.1000 0.02500
  X   X'y
40
230

Yhat1= + 1.0000x1 + 1.750x2 = 4.5000
Yhat2= + 1.0000x1 + 1.750x3 = 6.2500
Yhat3= + 1.0000x1 + 1.750x1 = 2.7500
Yhat4= + 1.0000x1 + 1.750x5 = 9.7500
Yhat5= + 1.0000x1 + 1.750x9 = 16.7500


ESS
=(4.500 - 8)^2
=(6.250 - 8)^2
=(2.750 - 8)^2
=(9.750 - 8)^2
=(16.75 - 8)^2
=122.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,11.0000x1 = 1.750x2 = 4.500480.250012.2516 e1 = 4 - 4.500 = -0.50000.2500
2 Yhat2 = Σβixi,2 = 1.0000x1 = 1.750x3 = 6.250780.56253.0631 e2 = 7 - 6.250 = 0.75000.5625
3 Yhat3 = Σβixi,3 = 1.0000x1 = 1.750x1 = 2.750380.0625027.5625 e3 = 3 - 2.750 = 0.25000.06250
4 Yhat4 = Σβixi,4 = 1.0000x1 = 1.750x5 = 9.750980.56253.0631 e4 = 9 - 9.750 = -0.75000.5625
5 Yhat5 = Σβixi,5 = 1.0000x1 = 1.750x9 = 16.751780.0625076.5681 e5 = 17 - 16.75 = 0.25000.06250
RSS =
Σ(yobs - yhatobs)2
ESS =
Σ(yhatobs - My)2
TSS =
Σ(yobs - My)2
e'e=Σeobs2
sum->1.500122.51241.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.5
    Coef value StD(β) tStat(β)
    alpha = 0.6000 * 40
    + -0.1000 * 230
    = 1.0000
    (0.5000 * 0.6000)1/2
    = 0.5477
    1.0000 / 0.5477
    = 1.826
    β1 = -0.1000 * 40
    + 0.02500 * 230
    = 1.750
    (0.5000 * 0.02500)1/2
    = 0.1118
    1.750 / 0.1118
    = 15.65
(12) Table of Outputs:
    yobs = alpha + β1 X obs,1 + eobs
    1.0000 1.750
    (1.826)(15.65) <- tstats
    r2 = 0.987903 | adj r2 = 0.983871
(13) RSS = Sum{y - y_hat }^2 = 1.5 TSS = Sum{y - y_avg }^2 = 124 ESS(a)= Sum{y_hat - y_avg }^2 = 122.5 we use the ESSb (below) cuz smthn wrng w ESS when no intercept. ESS(b)= TSS-RSS 122.5 note: TSS = ESS + RSS (14) r2 = ESS/TSS = 0.987903225806452 (15) adjusted r2 = ESS/TSS = 0.983870967741936 (16) F-stat = [ESS/(k-1)] / [RSS/(n-k)] = 245 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 = 3.27272727272727 ________________________________________________________ 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.