+ - 0:00:00
Notes for current slide
Notes for next slide

Foundation of Matrices

High Dimensional Data Analysis

Anastasios Panagiotelis & Ruben Loaiza-Maya

Lecture 7

1

Why?

2

Why vectors and matrices?

  • To understand methods like MDS, PCA and Factor Modelling it helps to understand vectors and matrices.
3

Why vectors and matrices?

  • To understand methods like MDS, PCA and Factor Modelling it helps to understand vectors and matrices.
  • In this lecture we cover some basic rules of matrices
3

Why vectors and matrices?

  • To understand methods like MDS, PCA and Factor Modelling it helps to understand vectors and matrices.
  • In this lecture we cover some basic rules of matrices
  • Later on we will cover the geometric intuition behind matrices.
3

Matrices

  • A matrix is an array of numbers. If a matrix has r rows and c columns then we say it is a r×c matrix.
4

Matrices

  • A matrix is an array of numbers. If a matrix has r rows and c columns then we say it is a r×c matrix.
  • A vector is just a special case of a matrix with either a single column r×1 or a single row 1×c.
4

Matrices

  • A matrix is an array of numbers. If a matrix has r rows and c columns then we say it is a r×c matrix.
  • A vector is just a special case of a matrix with either a single column r×1 or a single row 1×c.
  • These are called a column vector and row vector respectively
4

Matrices

  • A matrix is an array of numbers. If a matrix has r rows and c columns then we say it is a r×c matrix.
  • A vector is just a special case of a matrix with either a single column r×1 or a single row 1×c.
  • These are called a column vector and row vector respectively
  • A matrix with a single column and a single row is called a scalar.
4

Adding Matrices

  • To add two matrices simply add the corresponding elements

(123345)+(624256)=(7475911)

  • Only matrices with the same dimensions can be added together
5

Scalar Multiplication

  • To multiply a matrix and a scalar, simply multiply each element of the matrix by the scalar

3×(123345)=(36991215)

6

Matrix Transpose

  • Another important matrix operation is the transpose.
  • Every row becomes a column
  • Every column becomes a row.

(123345)=(134235)

7

Matrix multiplication

8

Matrix multiplication

  • A more confusing operation is matrix multiplication.
9

Matrix multiplication

  • A more confusing operation is matrix multiplication.
  • It does NOT involve simply multiplying corresponding elements.
9

Matrix multiplication

  • A more confusing operation is matrix multiplication.
  • It does NOT involve simply multiplying corresponding elements.
  • The intuition behind matrix multiplication will become clearer when we look at the geometry.
9

Row times column

  • First learn to multiply a row by a column

(134)×(645)=

10

Row times column

  • First learn to multiply a row by a column

(134)×(645)=1×6+...

11

Row times column

  • First learn to multiply a row by a column

(134)×(645)=6+...

12

Row times column

  • First learn to multiply a row by a column

(134)×(645)=6+3×4+...

13

Row times column

  • First learn to multiply a row by a column

(134)×(645)=6+12+...

14

Row times column

  • First learn to multiply a row by a column

(134)×(645)=6+12+4×5

15

Row times column

  • First learn to multiply a row by a column

(134)×(645)=6+12+20

16

Row times column

  • First learn to multiply a row by a column

(134)×(645)=38

17

Things to note

  • We multiplied a 1×3 vector by a 3×1 vector
18

Things to note

  • We multiplied a 1×3 vector by a 3×1 vector
  • The result is a single number (scalar)
18

Things to note

  • We multiplied a 1×3 vector by a 3×1 vector
  • The result is a single number (scalar)
  • Let z=(z1 z2  zn)
18

Things to note

  • We multiplied a 1×3 vector by a 3×1 vector
  • The result is a single number (scalar)
  • Let z=(z1 z2  zn)
  • What is zz?
18

Sum of squares

zz=(z1z2zn)(z1 z2  zn) =z12+z22+zn2 =i=1nzi2

19

Matrix Multiplication

  • To multiply two matrices
20

Matrix Multiplication

  • To multiply two matrices
  • Multiply every row from the first matrix by every column in the second matrix
20

Matrix Multiplication

  • To multiply two matrices
  • Multiply every row from the first matrix by every column in the second matrix
  • Now an example

(abcdef)×(ghijkl)

20

Matrix Multiplication

(abcdef)×(ghijkl)=(ag+bi+ck.........)

21

Matrix Multiplication

(abcdef)×(ghijkl)=(ag+bi+ckah+bj+cl......)

22

Matrix Multiplication

(abcdef)×(ghijkl)=(ag+bi+ckah+bj+cldg+ei+fk...)

23

Matrix Multiplication

(abcdef)×(ghijkl)=(ag+bi+ckah+bj+cldg+ei+fkdh+ej+fl)

24

Multiplication checklist

When multiplying matrices check two things

X(a×b)Y(b×c)=Z(a×c)

  1. First check dimensions on the ‘inside’ (blue). If equal the multiplication is conformable
  2. Then check the dimensions on the ‘outside’ (red). These give the dimensions of the result (they do not have to be equal).
25

Be careful!

  • Not all matrices can be multplied!
26

Be careful!

  • Not all matrices can be multplied!
  • Often two matrices can be added but NOT multiplied.
    • Consider the very first example of addition in these slides.
  • Sometimes XY is possible but not YX.
26

Be careful!

  • Not all matrices can be multplied!
  • Often two matrices can be added but NOT multiplied.
    • Consider the very first example of addition in these slides.
  • Sometimes XY is possible but not YX.
  • Even when both XY and YX are both conformable they may still not be equal, i.e XYYX.
26

Some special matrices

27

Regression

In a regression model

y1=β1x11+β2x12++βkx1k+ϵ1 y2=β1x21+β2x22++βkx2k+ϵ2 =++++ yn=β1xn1+β2xn2++βkxnk+ϵn

28

Regression Model

  • All these equations can be written as

y=Xβ+ϵ

  • The vector y is n×1
    • yi is the ith observation of the dependent variable
  • The matrix X is n×k
    • xij is the ith observation of the jth dependent variable.
    • For an intercept set xi1=1 for all i
29

Regression Model

  • The vector β is k×1
    • βj is the jth observation of the dependent variable
  • The vector ϵ is n×1
    • ϵi is the ith error term.
30

Regression Model

  • The vector β is k×1
    • βj is the jth observation of the dependent variable
  • The vector ϵ is n×1
    • ϵi is the ith error term.
  • Check for yourselves that all multiplication is conformable.
30

Variance Covariance matrix

  • Another important matrix to understand is the variance covariance matrix.
  • To start we will revise variance for scalar valued y which is

σ2=E[(yμ)2]

  • Or the sample equivalent

s2=1n1i=1n[(yiy¯)2]

31

Variance Covariance matrix

  • What about when y=(y1 y2) where y1 and y2 are different variables?
  • The equivalent formulas are

Σ=E[(yμ)(yμ)] and

S=1n1i=1n[(yiy¯)(yy¯)]

32

Variance Covariance matrix

  • To unpack this, keep things simple by looking at the expected variance and assume μ=0
  • What are the dimensions of yy?
33

Variance Covariance matrix

  • To unpack this, keep things simple by looking at the expected variance and assume μ=0
  • What are the dimensions of yy?
  • Since y is a 2×1 matrix yy will be a 2×1 vector multiplied by a 1×2 vector.
33

Variance Covariance matrix

  • To unpack this, keep things simple by looking at the expected variance and assume μ=0
  • What are the dimensions of yy?
  • Since y is a 2×1 matrix yy will be a 2×1 vector multiplied by a 1×2 vector.
  • This is a 2×2 matrix.
33

Variance Covariance matrix

  • To unpack this, keep things simple by looking at the expected variance and assume μ=0
  • What are the dimensions of yy?
  • Since y is a 2×1 matrix yy will be a 2×1 vector multiplied by a 1×2 vector.
  • This is a 2×2 matrix.
  • What is in this 2×2?
33

Variance Covariance matrix

E[yy]=E[(y1 y2)(y1y2)] =E[(y12y1y2 y2y1y22)] =(E[y12]E[y1y2] E[y2y1]E[y22])

34

Variance Covariance matrix

Σ=(E[y12]E[y1y2] E[y2y1]E[y22])

  • The diagonal elements are variances.
  • The off-diagonal elements are covariances.
35

In general

  • For a p-dimensional vector, the variance covariance matrix is a p×p matrix.
  • The element in the row i and column j for ij is the covariance between yi and yj.
  • The element in the row i and column i is a diagonal element and is the variance of yi.
36

Inverses

37

Can we divide by matrices?

  • We can add and multiply matrices. Can we divide them?
  • Strictly speaking we cannot.
  • However it is possible to multiply bu a matrix inverse.
  • What is a matrix inverse?
38

Inverses for scalars

  • In scalar algebra dividing a by b is the same as multiplying a by 1/b
39

Inverses for scalars

  • In scalar algebra dividing a by b is the same as multiplying a by 1/b
  • The inverse has the property that multiplying a number by its inverse yields an answer of 1.
39

Inverses for scalars

  • In scalar algebra dividing a by b is the same as multiplying a by 1/b
  • The inverse has the property that multiplying a number by its inverse yields an answer of 1.
  • In scalar algebra this means b×1/b=1
39

Inverses for scalars

  • In scalar algebra dividing a by b is the same as multiplying a by 1/b
  • The inverse has the property that multiplying a number by its inverse yields an answer of 1.
  • In scalar algebra this means b×1/b=1
  • What is the equivalent of 1 in matrix algebra?
39

Identity Matrix

The Identity Matrix is

(100 01 0 001)

Multiplying any matrix by the identity matrix gives the same matrix. I.e. AI=IA=A.

40

Matrix Inverse

  • The matrix inverse of X denoted X1 is defined so that X1X=XX1=I
  • This is only possible when X is a square matrix
  • A square matrix has the same number of rows as columns.
41

Rotation

  • A very special matrix is a rotation matrix.
  • If R is a rotation matrix then it has the following property

R1=R

  • Another way of stating this is that RR=I
  • The reason we call this a rotation will be covered later on.
42

Conclusions

  • In factor modelling matrices are used heavily.
  • Make sure you understand how multiplication works.
  • In particular understand when multiplication is possible and when it is not possible.
43

Why?

2
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow