Вы находитесь на странице: 1из 21

Tento projekt je podpořen v rámci OP Praha Adaptabilita a je spolufinancován Evropským sociálním fondem,

státním rozpočtem ČR a rozpočtem hlavního města Prahy. Praha & EU: Investujeme do vaší budoucnosti

Czech University of Life Sciences Prague

Department of Economics

Subject: Econometrics

Examples and practising

1st LESSON:
Operations with a Matrix;
Regression and Correlation

2011 ©
Introduction
In this document you can found the examples which are related with 1st econometric lesson.
The content is shown below. Every subchapter has one example which is solved. Other
exercises are for practising, solution is in the end of the main chapters.

Content
1 OPERATIONS WITH A MATRIX.................................................................................... 2
1.1 Addition and scalar multiplication ................................................................................... 2
1.2 Matrix multiplication – Size of a Matrix......................................................................... 3
1.3 Matrix multiplication....................................................................................................... 3
1.4 Rank of a Matrix ............................................................................................................. 5
1.5 Determinant of a Matrix.................................................................................................. 6
1.6 Inverse of a Matrix .......................................................................................................... 8
1.7 Transposition of a Matrix................................................................................................ 9
1.8 Results of practising exercises ...................................................................................... 11
2 REGRESSION AND CORRELATION........................................................................... 14
2.1 Simple Linear Regression ............................................................................................. 14
2.2 Correlation analysis....................................................................................................... 16
2.3 Practising exercises ....................................................................................................... 17
2.4 Results of practising exercises ...................................................................................... 19

1
1 Operations with a Matrix
1.1 Addition and scalar multiplication
Solved Example:

2 4   8 2 
  
2 ⋅ 3 1  +  4 13 
5 10 − 2 − 13

2 4   8 2  4 8  8 2  12 10
  
2 ⋅ 3 1  +  4    
13  =  6 2  +  4 13  = 10 15
5 10 − 2 − 13 10 20 − 2 − 13  8 7 

Practising Exercises:
i)
5 10 5 5 10 5
4⋅  − 3⋅  
8 2 1 8 2 1

ii)
3 6 1 6 8 
− 5⋅   + ⋅ 
8 4 2 7 10

iii)
1 3
2 4 
10 ⋅   + 5 ⋅ 5 5
7 11 1 2

iv)
 3 2 4 36 24 6   21 4 8 
 5 10 3 + 1 ⋅ 12 48 78 − 1 ⋅  8 3 10
  6   2  
12 5 3  6 36 12  40 6 18

2
1.2 Matrix multiplication – Size of a Matrix
A matrix has m rows and n columns. The size of the matrix is [m x n].
The rule for matrix multiplication is follows: Two matrices can be multiplied only when the
number of columns in the first matrix equals the number of rows in the second matrix. In
other words n in the first matrix has to be equal m in the second matrix.

Solved Example:
We have two matrices, the A with size [3x2] and the B with size [2x4]. Can we multiply these
matrices, what size will have the final matrix?
A = [3x2] B = [2x4] A*B = ?

Yes, we can multiply these matrices, because first matrix has 2 columns and second matrix
has 2 rows. After multiplication we gained the matrix with size [3x4].

A*B = [3x2] * [2x4] = [3x4]

Practising Exercises:
C = [3x1] D = [1x5] E = [1x2] F = [1x3] H = [4x1]

C*D = ? E*F = ? C*E = ? D*E = ? E*D = ?


C*F = ? F*C = ? D*H = ? H*D = ? F*C*D = ?

1.3 Matrix multiplication


Solved Example:
2 3 5 6 2 1 
A = 4 1 2 B = 3 7 2 A* B = ?
5 3 1  1 4 2

 2 3 5  6 2 1   2 * 6 + 3 * 3 + 5 * 1 2 * 2 + 3 * 7 + 5 * 4 2 * 1 + 3 * 2 + 5 * 2 
A * B = 4 1 2 * 3 7 2 =  4 * 6 + 1* 3 + 2 *1 4 * 2 + 1* 7 + 2 * 4 4 *1 + 1* 2 + 2 * 2  =
5 3 1 1 4 2  5 * 6 + 3 * 3 + 1*1 5 * 2 + 3 * 7 + 1* 4 5 *1 + 3 * 2 + 1* 2 

12 + 9 + 5 4 + 21 + 20 2 + 6 + 10 26 45 18


= 24 + 3 + 2 8 + 7 + 8 4 + 2 + 4  = 29 23 10
 30 + 9 + 1 10 + 21 + 4 5 + 6 + 2  40 35 13

3
Practising Exercises:
i)
2 3 5 6 2 1 
A = 4 1 2 B = 3 7 2 B* A = ?
5 3 1  1 4 2

ii)
1 4 5 3
C=  D=  C*D = ? D *C = ?
5 7 2 1

iii)
1 3 9 4 7 1 
E = 5 2 1  F = 3 2 3 E*F = ? F *E = ?
6 3 4 1 1 2

iv)
 3 8
G = [5 2 − 1] H = − 2 5 G*H = ? H *G = ?
 4 1

v)
2 3 
 − 1 5 2
I = 1 2  J =  I *J =? J *I = ?
4 − 5  3 1 4

4
1.4 Rank of a Matrix
The rank of a matrix is the maximum number of linearly independent row vectors of the
matrix, which is the same as the maximum number of linearly independent column vectors.

Solved Example:
Task: Determine the rank of a matrix.

1 2 4 2
− 2 1 − 2 − 2
A=  h( A) = ?
1 4 6 3
 
3 6 10 2 

1 2 4 2  *2 1 2 24 1 2 4 2  *(-3)
− 2 1 − 2 − 2 (+) 0 5 2
6 0 5 6 2 
 (-)
∼  ∼ 
1 4 6 3 1 4 36 0 − 2 − 2 − 1
     
3 6 10 2  3 6 10 2 3 6 10 2 

1 2 4 2 1 2 4 2 1 2 4 2
0 5 6 2  *2 0 5 6 2  0 5 6 2 
∼  ∼  ∼ 
0 − 2 − 2 − 1  *5 0 0 2 − 1 0 0 2 − 1
(+)
     
0 0 − 2 − 4  0 0 − 2 − 4 0 0 0 − 5

Conclusion: h( A) = 4

Practising Exercises:
i)
2 6 10 
B = − 4 − 6 − 10
 h( B ) = ?
 − 1 − 2 − 3 

ii)
2 2 8
C =  4 2 − 6 h(C ) = ?
− 2 0 14 

iii)
1 2 3 4
− 2 3 5 0 
D= h( D) = ?
− 3 1 2 − 4
 
 4 − 6 − 10 0 

5
iv)
2 4 8 2
− 1 − 1 2 1
E= h( E ) = ?
2 6 0 4
 
 2 8 12 5

v)
1 3 2 1 5
− 2 − 2 4 3 − 4

F = 1 2 −2 1 1 h( F ) = ?
 
 −1 1 6 4 1
 3 5 0 8 19 

1.5 Determinant of a Matrix


Determinant of matrix A is marked as det(A) or |A|. Calculate determinants in following
exercises.

Solved Example, Matrix 2x2:


2 3
A=  det( A) = ?
5 9 

det( A) = (2 * 9) − (3 * 5) = 18 − 15 = 3

Solved Example, Matrix 3x3:


8 3 5 
B = 2 1 1  det( B ) = ?
6 2 4

8 3 5  8 3
B = 2 1 1 2 1
6 2 4 6 2

det( B) = [(8 *1* 4) + (3 *1* 6) + (5 * 2 * 2)] − [(5 *1* 6) + (8 *1* 2) + (3 * 2 * 4)]

det( B) = [32 + 18 + 20] − [30 + 16 + 24]

det( B ) = 70 − 70 = 0

Note:
If a matrix´s determinant is equal to zero, then the matrix is singular (degenerate).
If a matrix´s determinant is not equal to zero, then the matrix is invertible (nonsingular).
Only for invertible matrix it is possible to express an inverse of matrix.

6
Practising Exercises:
i)
 4 2
C=  det(C ) = ?
8 4 

ii)
25 5
D=  det( D) = ?
 3 2

iii)
1 3 − 1
E = 4 2 5  det( E ) = ?
4 5 5 

iv)
 1 4 2
F = − 1 3 5 det( F ) = ?
 3 1 2

7
1.6 Inverse of a Matrix
Solved Example:
1 4 1
A = 1 2 2 A −1 = ?
0 2 1

1 4 1 1 0 0 1 4 1 1 0 0 1 4 1 1 0 0
  (-)    
1 2 2 0 1 0 ∼ 0 2 − 1 1 − 1 0  ∼ 0 2 − 1 1 − 1 0  ∼
0 2 1 0 0 1  0 2 1 0 0 1  (-) 0 0 − 2 1 − 1 − 1 /(-2)

1 4 1 1 0 0  1 4 1 1 0 0 
   
0 2 − 1 1 −1 0  ∼ 0 2 0 1 / 2 − 1 / 2 1 / 2 /(2) ∼
0 0 1 − 1 / 2 1 / 2 1 / 2 (+) 0 0 1 − 1 / 2 1 / 2 1 / 2

1 4 1 1 0 0  1 4 0 3 / 2 − 1 / 2 − 1 / 2
   
0 1 0 1 / 4 − 1 / 4 1 / 4  (-) ∼ 0 1 0 1 / 4 − 1 / 4 1 / 4  *(-4) ∼
0 0 1 − 1 / 2 1 / 2 1 / 2 0 0 1 − 1 / 2 1 / 2 1 / 2 

1 0 0 1 / 2 1 / 2 − 3 / 2
 
0 1 0 1 / 4 − 1 / 4 1 / 4 
0 0 1 − 1 / 2 1 / 2 1 / 2 

 1/ 2 1 / 2 − 3 / 2  0.5 0.5 − 1.5


A =  1 / 4 − 1 / 4 1 / 4  also A =  0.25 − 0.25 0.25 
−1  −1 
− 1 / 2 1 / 2 1 / 2  − 0.5 0.5 0.5 

Verification:
A * A−1 = Ι

1 4 1  0.5 0.5 − 1.5 1 0 0


1 2 2 *  0.25 − 0.25 0.25  = 0 1 0
     
0 2 1 − 0.5 0.5 0.5  0 0 1 

8
Practising Exercises:
i)
 2 4
B=  B −1 = ?
− 1 3

ii)
 1 − 3 3
C = − 1 1 0 C −1 = ?
 0 1 1

iii)
1 0 1 
D = 2 1 0 D −1 = ?
0 − 1 1

iv)
 1 3 0
E = − 3 1 2 E −1 = ?
 0 0 1

v)
 2 1 1
F =  0 2 1 F −1 = ?
− 2 1 1

1.7 Transposition of a Matrix


Solved Example:
 1 4 5
A =  7 3 6 AT = ?
− 2 8 9

1 7 − 2 
AT = 4 3 8 
5 6 9 

9
Practising Exercises:
i)
2 3 5 − 5
B = 8 2 − 3 3  BT = ?
1 4 9 11 
ii)
 2 3 1 5
− 5 7 − 9 6
C=  CT = ?
 4 8 11 7
 
 10 12 13 2

iii)
1 4 2 
D = 4 3 5 DT = ?
2 5 7

10
1.8 Results of practising exercises
 1.1 Addition and scalar multiplication
i)
− 10 34 11 
 5 20 − 17

ii)
 − 12 − 26
− 36.5 − 15 
 

iii)
we cannot solve this example, matrices do not have same size

iv)
− 1.5 4 1 
 3 16.5 11 

 − 7 8 − 4

 1.2 Matrix multiplication – Size of a Matrix


C*D = [3x5] E*F = ∅ C*E = [3x2] D*E = ∅ E*D = ∅
C*F = [3x3] F*C = [1x1] D*H = ∅ H*D = [4x5] F*C*D = [1x5]

 1.3 Matrix multiplication


i)
 25 23 35
B * A = 44 22 31
 28 13 15 

ii)
13 7  20 41
C*D =   D *C =  
39 22  7 15

iii)
 22 22 28 45 29 47
E * F = 27 40 13  F * E =  31 22 41
37 52 23 18 11 18 

iv)
G * H = [7 49]
H *G = ∅

11
We cannot multiply these matrices, because the rule for matrix multiplication is not fulfilled.
v)
 7 13 16 
I * J =  5 7 10 
− 19 15 − 12

J *I =∅
We cannot multiply these matrices, because the rule for matrix multiplication is not fulfilled.

 1.4 Rank of a Matrix


i) h( B ) = 3

ii) h(C ) = 2

iii) h( D) = 2

iv) h( E ) = 4

v) h( F ) = 4

 1.5 Determinant of a Matrix


i) det(C ) = 0

ii) det( D) = 35

iii) det( E ) = −27

iv) det( F ) = 49

 1.6 Inverse of a Matrix


i)
3 / 10 − 2 / 5 0.3 − 0.4
B −1 =  = 
1 / 10 1 / 5   0.1 0.2 

ii)
− 0.2 − 1.2 0.6
C −1
= − 0.2 − 0.2 0.6
 0.2 0.2 0.4

iii)
− 1 1 1
D =  2 − 1 − 2
 −1

 2 − 1 − 1

12
iv)
 0.1 − 0.3 0.6 
E −1 = 0.3 0.1 − 0.2
 0 0 1 

v)
 0.25 0 − 0.25
F −1
= − 0.5 1 − 0.5 
 1 −1 1 

 1.7 Transposition of a Matrix


i)
2 8 1
3 2 4 
B =
T 
 5 −3 9
 
− 5 3 11

ii)
2 − 5 4 10
3 7 8 12
C =
T 
1 − 9 11 13
 
5 6 7 2 

iii)
1 4 2 
D = 4 3 5
T

2 5 7

13
2 Regression and Correlation

2.1 Simple Linear Regression


Regression is a way of describing how one variable is numerically related to others variables.
Simple regression analysis describe dependency of two variables which one is a cause
(exogenous, explanatory variable, denote x ) and second is an effect (endogenous, explained
variable, denote y ).

Example:
Final consumption expenditure of household on foodstuff in milliard CZK and nominal wage
in thousand CZK are shown in the table below. Derive a simple linear regression function
between these variables.

Final consumption Nominal


Period
expenditure on foodstuff wage
y x
2000 191.95 13.219
2001 206.41 14.378
2002 203.78 15.524
2003 203.32 16.430
2004 211.99 17.466
2005 213.95 18.344
2006 222.12 19.546
2007 241.50 20.957
2008 272.66 22.592
2009 262.11 23.344

Solving:
The simple linear regression function is: y = a + bx , where a is the intercept and b is the slope.

The method least squares are used to fit the regression equation. For simple regression it is
possible to use the following two formulas:

n ∑ x i y i − ∑ xi ∑ y i xy − x ⋅ y
b= =
n∑ x − (∑ xi )
2
2
i x2 − x 2

a = y −b⋅x

where:
n

∑x
i =1
i
x is the arithmetic mean of variable x, i.e. x =
n

14
n

∑y
i =1
i
y is the arithmetic mean of variable y, i.e. y =
n
n

∑x y
i =1
i i
xy is the arithmetic mean of product of variables x and y, i.e. xy =
n
2
 n 
 ∑ xi 
x is the arithmetic mean of power on two, i.e. x =  i =1
2 2 
 n 
 
 
n

∑x
i =1
2
i
x 2 is the arithmetic mean of x square, i.e. x 2 =
n

Calculations:
y x xy x2
2000 191.95 13.219 2 537.44 174.74
2001 206.41 14.378 2 967.78 206.73
2002 203.78 15.524 3 163.42 240.99
2003 203.32 16.430 3 340.47 269.94
2004 211.99 17.466 3 702.67 305.06
2005 213.95 18.344 3 924.66 336.50
2006 222.12 19.546 4 341.48 382.05
2007 241.50 20.957 5 061.20 439.20
2008 272.66 22.592 6 160.00 510.40
2009 262.11 23.344 6 118.79 544.94
Sum 2 229.79 181.800 41 317.90 3 410.55
Mean 222.98 18.180 4 131.79 341.06

x = 18.180 y = 222.98 xy = 4 131.79 x 2 = 18.1082 = 330.51 x 2 = 341.06

4 131.79 − 18.18 ⋅ 222.98 78.0136


b= = = 7.395
341.06 − 330.51 10.55

a = y − b ⋅ x = 222.98 − 7.395 ⋅18.18 = 88.539

Final simple regression equation is: y = 88.539 + 7.395 x

Interpretation: If the nominal wage increases by 1 thousand CZK, then the final
consumption expenditure of household on foodstuff will increase by 7.395 milliard CZK.

15
2.2 Correlation analysis
A correlation coefficient indicates how much are two variables associated. The Pearson
correlation coefficient takes values <-1; 1> The correlation is +1 in the case of a perfect
positive (increasing) linear relationship, -1 in the case of a perfect negative (decreasing) linear
relationship. If the correlation coefficient is equal to zero, there isn’t linear dependence
between the variables.

Example:
Consider the solved example from chapter 2.1 Simple Linear Regression. Compute
correlation coefficient between variables final consumption expenditure and nominal wage.

Final consumption Nominal


Period
expenditure on foodstuff wage
y x
2000 191.95 13.219
2001 206.41 14.378
2002 203.78 15.524
2003 203.32 16.430
2004 211.99 17.466
2005 213.95 18.344
2006 222.12 19.546
2007 241.50 20.957
2008 272.66 22.592
2009 262.11 23.344

Solving:
The formula for computing the correlation coefficient is given by:
xy − x ⋅ y s xy
ryx = =
( )(
x2 − x 2 y2 − y 2 )
sx sy

A lot of statistics from the formula above were computed in the case of linear regression.
We know that:
x = 18.180 y = 222.98 xy = 4 131.79 x 2 = 18.1082 = 330.51 x 2 = 341.06

We have to count the y 2 and the y 2

16
Calculations:
2 2
y x xy x y
2000 191.95 13.219 2 537.44 174.74 36 846
2001 206.41 14.378 2 967.78 206.73 42 606
2002 203.78 15.524 3 163.42 240.99 41 525
2003 203.32 16.430 3 340.47 269.94 41 337
2004 211.99 17.466 3 702.67 305.06 44 941
2005 213.95 18.344 3 924.66 336.50 45 774
2006 222.12 19.546 4 341.48 382.05 49 336
2007 241.50 20.957 5 061.20 439.20 58 324
2008 272.66 22.592 6 160.00 510.40 74 345
2009 262.11 23.344 6 118.79 544.94 68 704
Sum 2 229.79 181.800 41 317.90 3 410.55 503 736.83
Mean 222.98 18.180 4 131.79 341.06 50 373.68

y 2 = 222.982 = 49 720.08 y 2 = 50 373.68

4 131.79 − 18.18 ⋅ 222.98 78.0136 78.0136


ryx = = = = 0.9396
(341.06 − 330.51)(50 373.68 − 49 720.08) 10.55 ⋅ 653.6 83.0390

2.3 Practising exercises


i)
In the next table are observations of unemployment rate in % and GDP per capita at current
prices in thousand CZK. Derive a single regression equation to determine a dependency
unemployment rate on GDP. Also compute the correlation coefficient.

GDP per capita


Unemployment rate
at current prices
in %
in thousand CZK
1997 4.79 176
1998 6.45 194
1999 8.70 202
2000 8.76 213
2001 8.13 230
2002 7.28 242
2003 7.78 253
2004 8.30 276
2005 7.93 292
2006 7.14 314
2007 5.32 342
2008 4.39 354

17
ii)
Evaluate the effect of total investment for environmental protection on the carbon monoxide
(CO) reduction. Use the simple regression function. It is true, that growth of investment leads
to reduction of polluting matter and how large is this change? The necessary data are in the
next table. Also compute the correlation coefficient.

Carbon
Total investment for
monoxide (CO)
environmental protection
in thousand tons
in milliard CZK
per year
2000 539 21.399
2001 539 19.892
2002 517 14.919
2003 529 19.383
2004 509 20.208
2005 491 18.248
2006 481 22.470
2007 435 19.900
2008 445 20.327

iii)
Evaluate a correlation between final expenditure of households on higher education and
number of students at universities. Also create a simple linear model where final expenditure
will be depended on number of students. The time series of final expenditure is in million
CZK and number of students is in thousands.

Final expenditure Number of


on higher students at
education universities
in million CZK in thousands
1995 217 148.43
1996 299 166.12
1997 383 177.72
1998 408 187.15
1999 435 198.96
2000 548 215.21
2001 481 203.51
2002 575 220.27
2003 590 243.81
2004 1783 265.07
2005 2216 289.64
2006 2543 316.50
2007 3645 344.62
2008 3855 369.62

18
2.4 Results of practising exercises
i)
y ... Unemployment rate in %
x ... GDP per capita in thousand CZK

x = 257.33 y = 7.08 xy = 1 794.95 x 2 = 257.332 = 66 218.73 x 2 = 69 381.17

1 794.95 − 257.33 ⋅ 7.08 − 26.9464


b= = = −0.0085
69 381.17 − 66 218.73 3 162.44

a = y − b ⋅ x = 7.08 − (−0.0085) ⋅ 257.33 = 9.27

The final simple regression equation is: y = 9.27 − 0.0085 x

Interpretation: If the GDP per capita at current prices increases by 1 thousand CZK, then the
unemployment rate will decrease by 0.0085 %.

y 2 = 7.082 = 50.13 y 2 = 52.24

1 794.95 − 257.33 ⋅ 7.08 − 26.9464 − 26.9464


ryx = = = = - 0,33
(69 381.17 − 66 218.73)(52.24 − 50.13) 3162.44 ⋅ 2.11 81.6869

ii)
y ... CO in tons per year
x ... Total investment for environmental protection in milliard CZK

x = 19.64 y = 498.33 xy = 9 775.37 x 2 = 19.642 = 385.73 x 2 = 389.70

9 775.37 − 19.64 ⋅ 498.33 − 11.8312


b= = = −2.98
389.70 − 385.73 3.97

a = y − b ⋅ x = 498.33 − (−2.98) ⋅ 19.64 = 556.86

The final simple regression equation is: y = 556.86 − 2.98 x

Interpretation: If the total investment for environmental protection increases by 1 milliard


CZK, then the carbon monoxide will be reduced by 2.98 tons per year.

y 2 = 498.332 = 248 332.79 y 2 = 249 660.56

9 775.37 − 19.64 ⋅ 498.33 − 11.8312 − 11.8312


ryx = = = = - 0,163
(389.70 − 385.73)(249 660.56 − 248 332.79) 3.97 ⋅ 1327.77 72.6034

19
iii)
y ... The final expenditure on higher education in million CZK
x ... Number of students at universities in thousands

x = 239.05 y = 1 284.14 xy = 385 680.27 x 2 = 239.052 = 57 144.90 x 2 = 61 515.95

385 680.27 − 239.05 ⋅ 1 284.14 78 706.603


b= = = 18
61 515.95 − 57 144.9 4 371.05

a = y − b ⋅ x = 1 284.14 − 18 ⋅ 239.05 = −3 018.76

The final simple regression equation is: y = −3 018.76 + 18 x

Interpretation: If the number of students at universities increases by 1 thousand, then the


final expenditure of households on higher education will increase by 18 million per year.

y 2 = 1 284.142 = 1 649 015.54 y 2 = 3 182 350.14

385 680.27 − 239.05 ⋅ 1 284.14 78 706.603 78 706.603


ryx = = =
(61 515.95 − 57 144.9)(3 182 350.14 − 1 649 015.54) 4 371.05 ⋅ 1 533 334.6 81 867.467

ryx = 0.961

Author:
Ing. Petra Bubáková, CULS, FEM, Department of Economics

Note:
This material has not undergone editorial or language editing. If you found some mistakes,
don’t hesitate to contact me by e-mail: bubakova@pef.czu.cz

20

Вам также может понравиться