the matrix

37
UnB - Financial Econometr ics I Otavio Medeiros 1 The Matrix Otavio R. de Medeiros UnB Programa de Pós-Graduação em Administração Programa Multiinstitucional e Interregional de Pós-Graduação em Ciências Contábeis UnB-UFPB-UFRN Financial Econometrics I

Upload: gotzon

Post on 08-Jan-2016

46 views

Category:

Documents


1 download

DESCRIPTION

UnB Programa de Pós-Graduação em Administração Programa Multiinstitucional e Interregional de Pós-Graduação em Ciências Contábeis UnB-UFPB-UFRN Financial Econometrics I. The Matrix. Otavio R. de Medeiros. Matrices. A Matrix is a collection or array of numbers - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

1

The Matrix

Otavio R. de Medeiros

UnB

Programa de Pós-Graduação em Administração

Programa Multiinstitucional e Interregional de Pós-Graduação em Ciências Contábeis UnB-UFPB-UFRN

Financial Econometrics I

Page 2: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

2

Matrices• A Matrix is a collection or array of numbers• Size of a matrix is given by number of rows

and columns R x C• If a matrix has only one row, it is a row

vector• If a matrix has only one column, it is a

column vector• If R = C the matrix is a square matrix

Page 3: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

3

Definitions• Matrix is a rectangular array of real

numbers with R rows and C columns.

are matrix elements.

11 12 1

21 22 2

1 2

...

...A

...

n

n

m m mn

a a a

a a a

a a a

( 1, ; 1, )ija i m j n

Page 4: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

4

Definitions

• Dimension of a matrix: R x C.• Matrix 1 x 1 is a scalar.• Matrix R x 1 is a column vector.• Matrix 1 x C is a row vector.• If R = C, the matrix is square.• Sum of elements of leading diagonal = trace.• Diagonal matrix : square matrix with all elements off the leading

diagonal equal to zero.• Identity matrix: diagonal matrix with all elements in the leading

diagonal equal to one.• Zero matrix: all elements are zero.

Page 5: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

5

Definitions

• Rank of a matrix: is given by the maximum number of linearly independent rows or columns contained in the matrix, e.g.:

3 42

7 9

3 61

2 4

rank

rank

Page 6: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

6

Matrix Operations

• Equality: A = B if and only if A and B have the same size and aij = bij i, j.

• Addition of matrices: A+B= C if and only if A and B have the same size and aij + bij = cij i, j.

2 4 1 2 1 6

3 5 4 1 7 6

Page 7: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

7

Matrix operations

• Multiplication of a scalar by a matrix:

k.A = k.[aij], i.e. every element of the matrix is multiplied by the scalar.

Page 8: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

8

Matrix operations• Multiplication of matrices: if A is m x n and B is n x p,

then the product of the 2 matrices is A.B = C, where C is a m x p matrix with elements:

• Example:

Note: A.BB.A

1

n

ij ik kjk

c a b

2 4 1 2 2 ( 1) 4 4 2 2 4 1 14 8

3 5 4 1 3 ( 1) 5 4 3 2 5 1 17 11

Page 9: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

9

Transpose of a matrix

• matrix transpose: if A is m x n, then the transpose of A is n x m, i.e.:

11 12 1 11 21 1

21 22 2 12 22 2

1 2 1 2

... ...

... ...A ; A '

... ...

n m

n m

m m mn n n mn

a a a a a a

a a a a a a

a a a a a a

Page 10: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

10

Properties of transpose matrices

• (A+B)+C=A+(B+C)

• (A.B).C=A(B.C)

i. (A')'=A

ii. (A+B)'=A'+B'

iii. (A.B)'=B'.A'

iv. If A is square and if A=A', then A is symmetrical.

Page 11: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

11

• Propriedades:

PROJEÇÕES

1

( )́´

( )´ ´ ´

( )´ ´ ´

( )

-1 -1

-1 -1

-1 -1

-1 -1

A A

A B A B

AB B A

AA = A A = I

(A ) = A

AB B A

(A´) = (A )´

Page 12: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

12

Square matrices :

• Identity matrix I:

Note: A.I = I.A = A, where A has the same size as I.

1 0 0 0

0 1 0 0I

0 0 1 0

0 0 0 1

Page 13: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

13

Square matrices :

• Diagonal matrix:

1

2

0 ... 0

0 ... 0

0 0 ... n

Page 14: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

14

Square matrices:

• Scalar matrix = diagonal matrix, when

n .

• Zero matrix: A + 0 = A; A x0 = 0.

Page 15: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

15

• Trace of a matrix:

If A is m x n and B is n x m, then AB and BA are square matrices and tr(AB) = tr (BA)

1

(A)

( A) ( (A))

n

iii

tr a

tr c c tr

Page 16: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

16

Determinants

• matrix 2 x 2:

3 13 2 2 1 6 2 4

2 2

Page 17: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

17

Determinants • matrix 3 x 3:

2 3 2

1 1 2

3 2 2

1 2 1 2 1 12 3 2

2 2 3 2 3 2

2(2 4) 3(2 6) 2(2 3)

4 12 2 6

Page 18: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

18

Determinants

• Matrix 3 x 3:

2 3 2 2 3 2 2 3

1 1 2 1 1 2 1 1

3 2 2 3 2 2 3 2

2 1 2 3 2 3 2 1 2 2 1 3 2 2 2 3 1 2

4 18 4 6 8 6 6

Page 19: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

19

Inverse matrix• The inverse of a square matrix A, named A-1, is the matrix

which pre or post multiplied by A gives the identity matrix.• B = A-1 if and only if BA = AB = I• Matrix A has an inverse if and only if det A 0 (i.e. A is

non singular).• (A.B)-1 = B-1.A-1

• (A-1)’=(A’)-1 if A é symmetrical and non singular, then A-1 is symmetrical.

• If det A 0 and A is a square matrix of size n, then A has rank n.

Page 20: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

20

Steps for finding an inverse matrix

• Calculation of the determinant: Kramer’s rule or cofactor matrix.

• Minor of the element aij is the determinant of the

submatrix obtained after exclusion of the i-th row and j-th column.

• Cofactor is the minor multiplied by (-1)i+j,

Page 21: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

21

Steps for finding an inverse matrix

• Laplace expansion: take any row or column and get the determinant by multiplying the products of each element of row or columns by its respective cofactor.

• Cofactor matrix: matrix where each element is substituted by its cofactor.

Page 22: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

22

i. Adjunct matrix is the transpose of the cofactor matrix, i.e. adj A = C’.

ii. Inverse matrix: 1 1A A

Aadj

11 12 11 12

21 22 21 22

11 11 12 12

22 12

21 11

1

11 22 12 21 11 22 12 2

11 22 11 22

12 21 12 21A

21 12 21 12

22 11 22 11

A =

adj A = C'=

1A

m a c a

m a c aa a a aC

m a c aa a a a

m a c c

a c a c

a a

a a

adjA

a a a c a a a c

22 12

1 21 11

a a

a a

Page 23: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

23

Example2 x 2 matrix :

-1

4 3A A 4 3 2 3 12 6 6

2 3

3 2 3 -3C A = C' =

3 4 -2 4

3 -3 0,5 0,51 1A A=

-2 4 0,33 0,66A 6

adj

adj

Page 24: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

24

Example• 3 x 3 matrix :

1 2 1 2 1 1

2 2 3 2 3 22 3 2 2 4 1

3 2 2 2 2 31 1 2 det 6 2 2 5

2 2 3 2 3 23 2 2 4 2 1

3 2 2 2 2 3

1 2 1 2 1 1

2 2 4

6 6 64 2 2

6 6 61 5 1

6 6 6

A A cofactor matrix

Inverse

Page 25: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

25

Matrix differentiation:The derivative of a scalar (1 x 1) w.r.t. a column vector (n x 1) is a column

vector the elements of which are the derivatives of the scalar w.r.t each

element of the column vector, i.e.

Let be a scaly

1

2

1

2

ar and a column vector . Hence:

( )

( )( )

( )

n

n

x

x

x

y

x

yy

x

y

x

x x

x

Page 26: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

26

Matrix differentiation:1 1

2 2

1 1 2 2

1

Let be a column vector and a column vector . Hence, we can write:

´

The derivative of ´ w.r.t. vector will be:

( ´ )

( ´ )

n n

n n

a x

a x

a x

a x a x a x

x

a a x x

a x

a x x

a x

a x

x

1 1 2 2

11

1 1 2 22

2 2

1 1 2 2

( )

( ´ ) ( )

( ´ ) ( )

n n

n n

nn n

n n

a x a x a x

xa

a x a x a xa

x x

aa x a x a x

x x

a x

a

a x

Page 27: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

27

Matrix differentiation:

11 12 1 1

12 22 2 2

1 2

2 211 1 12 1 2 13 1 3 1 1 22 2 23 2 3 2 2

Let A be a symmetric matrix and x a column vector .

Hence:

´ 2 2 2 2 2

n

n

n n nn n

n n n n

a a a x

a a a x

a a a x

a x a x x a x x a x x a x a x x a x x

A x

x Ax

2

111 1 12 2 1

12 1 22 2 22

1 1 2 2

The derivative of ´ w.r.t. vector will be:

( ´ )

2( )( ´ )

2( )( )2

2( )( ´ )

nn n

n n

n n

n n nn n

n

a x

xa x a x a x

a x a x a xx

a x a x a x

x

x Ax x

x Ax

x Axx´Ax

x

x Ax

11 12 1 1

21 22 2 2

1 2

2 ´

n

n

n n nn n

a a a x

a a a x

a a a x

Ax 2x A

Page 28: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

28

Y X1 1 1 X' = 1 1 1 1 12 1 2 1 2 2 3 31 1 22 1 3 X'X = 5 112 1 3 11 27 |X'X| = 14

cofactor m. 27 -11 Adj(X'X) = 27 -11-11 5 -11 5

(X'X)^(-1)= 1,929 -0,79 X'Y = 8 B = 0,50-0,79 0,357 19 0,50

Since = 0.5 e = 0.5, the regression equation is yt = 0.5 + 0.5xt

Solution:

Linear regression, example 1: Perform a linear regression, given that the data for the dependent variable are 1, 2, 1, 2, 2 and for the independent variable are 1, 2, 2, 3, 3.

Page 29: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

29

y = 0.5x + 0.5

R2 = 0,5833

0

0,5

1

1,5

2

2,5

3

0 0,5 1 1,5 2 2,5 3 3,5 4 4,5

Page 30: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

30

• Linear regression, example 2: a firm manufacturing bikes is preparing a project and wishes to find out what is the relationship between bike sales and national income (GDP). In the last 5 years, bike sales increased by 5%, 9%, 5%, 6% and 10%, whereas GDP increased by 2,5%, 4%, 3%, 2,5%, 4%. What is the relationship between bike sales and GDP?

Page 31: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

31

The past relationship between bike sales growth and GDP growth is given by: yt = -0.0204 + 2.826xt

Example 2:Solution 1

Y X5% 1 2,50% X' = 1 1 1 1 19% 1 4% 0,025 0,04 0,03 0,025 0,045% 1 3%6% 1 2,50% X'X = 5 0,16

10% 1 4% 0,16 0,01 |X'X| = 0,00115

cofactor m. 0,005 -0,16 Adj(X'X) = 0,005 -0,16-0,16 5 -0,16 5

(X'X)^(-1)= 4,652 -139,1 X'Y = 0,35 B = -0,020-139,13 4348 0,012 2,826

Page 32: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

32

Hint: to avoid working with decimals, we can multiply y and x by 100. To find the correct final result, divide by 100. doesn’t change.

Example 2:Solution 2

Y X5 1 2,5 X' = 1 1 1 1 19 1 4,0 2,5 4 3 2,5 45 1 3,06 1 2,5 X'X = 5 16

10 1 4,0 16 53,5 |X'X| 11,5

cofactor m 54 -16 Adj(X'X) = 53,5 -16-16 5 -16 5

(X'X)^(-1)= 4,65 -1,391 X'Y = 35 B = -2,0435 -0,02043-1,39 0,4348 119 2,8261 2,82609

Page 33: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

33

y = 2,8261x - 0,0204

R2 = 0,835

-15%

-10%

-5%

0%

5%

10%

15%

20%

25%

30%

-4% -2% 0% 2% 4% 6% 8% 10%

GDP growth

Sal

es g

row

th

Graph (Excel):

Page 34: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

34

Goodness of fit:• A measure of the goodness of fit of a regression is

the coefficient of determination R2, which is defined as:

2

2 1

2 2

1 1

´1 1

( ) ( )

where:

= regression residuals

values of the dependent variable

= mean of the values of the dependent variable

n

ii

n n

i ii i

i

i

ee e

Ry y y y

e

y

y

Page 35: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

35

Goodness of fit:

• When all the residuals are equal to nil, R2 = 1, meaning that the regression is perfect, with all data points located on the line.

• When

then R2 = 0, meaning that there is no regression.

• Hence, the range for R2 will be: 0 < R2 < 1

• Values of R2 close to 1 indicate a good regression, while low values of R2 indicate a bad or inexisting regression.

2

1

´ ( )n

ii

y y

e e

Page 36: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

36

Calculation of R2 – Example 1:

52 2

1

1 1 1 1 1 0

2 1 2 2 1,5 0,50,5

1 1 2 1 1,5 0,50,5

2 1 3 2 2 0

2 1 3 2 2 0

1´ 0,5 ( 0,5) 0,5; (1 2 1 2 2) / 5 1,6

5 ii

y y

Y = XB + e e = Y XB

e

e e

52 2 2 2 2 2

1

2

1 1,6 0,6

2 1,6 0,4

; ( ) 0,6 0,4 0,6 0,4 0,4 1,21 1,6 0,6

2 1,6 0,4

2 1,6 0,4

0,51 0,5833

1,2

ii

y y y y

R

Page 37: The Matrix

UnB - Financial Econometrics I Otavio Medeiros

37

Calculation of R2 – Example 2:

2

0,05 1 0,025

0,09 1 0,040,0204

0,05 1 0,032,8261

0,06 1 0,025

0,10 1 0,04

0,835R

Y = XB + e e = Y XB

e