Docsity

Lecture Notes for Matrix Algebra - Multivariate Analysis | PSY 444.00, Study notes of Descriptive statistics

Toggle sidebar
bg1
PSY 444 — Fall, 2007 — Lecture Notes for Matrix Algebra Page 2
Matrix Algebra
§1 Basic Definitions
We need to talk about the arithmatic and algebra of scalars, vectors, and matrices. Many of the
operations are very similar, but each of these systems have their quirks.
We’ll start by talking about the relationship of scalars, vectors, and matrices.
[A] A matrix is a two-dimensional arrangement of elements.
•The elements of a matrix can be numbers, variables, or symbols.
•The elements are indexed by the row and then the column in which they occur.
•The size of a matrix is denoted by the number of rows and then the number of columns.
•For example, A2x3=
a b c
d e f
and B3x2=
1 2
3 4
5 6
[B] A vector is a matrix that has only a single row or a matrix that has only a single column.
•A row-vector has only a single row, such as R1x4=1 2 3 4
•A column-vector has only a signle column, such as C4x1=
1
2
3
4
•If we don’t specify row or column, we assume that a vector is a column vector.
[C] A scalar is a matrix (or row-vector or column-vector) that has only a single element.
•Scalars are non-dimensional numbers, variables, or symbols like you’re used to seeing and
have seen since grade school.
•You already know scalar arithmatic and algebra, but you may not have known that it was
scalar arithmatic and algebra. A scalar algebra by any other name would smell as sweet.. .
•For example, 1or aor σare all scalars.
§2 Arithmetic
Let’s build “up” from scalar arithmetic:
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Lecture Notes for Matrix Algebra - Multivariate Analysis | PSY 444.00 and more Study notes Descriptive statistics in PDF only on Docsity!

Matrix Algebra

§ 1 Basic Definitions

We need to talk about the arithmatic and algebra of scalars, vectors, and matrices. Many of the operations are very similar, but each of these systems have their quirks.

We’ll start by talking about the relationship of scalars, vectors, and matrices.

[A] A matrix is a two-dimensional arrangement of elements.

  • The elements of a matrix can be numbers, variables, or symbols.
  • The elements are indexed by the row and then the column in which they occur.
  • The size of a matrix is denoted by the number of rows and then the number of columns.
  • For example, A 2 x 3 =

  

a b c d e f

   and^ B 3 x 2 =

   

   

[B] A vector is a matrix that has only a single row or a matrix that has only a single column.

  • A row-vector has only a single row, such as R 1 x 4 =

[ 1 2 3 4

]

  • A column-vector has only a signle column, such as C 4 x 1 =

    

    

  • If we don’t specify row or column, we assume that a vector is a column vector.

[C] A scalar is a matrix (or row-vector or column-vector) that has only a single element.

  • Scalars are non-dimensional numbers, variables, or symbols like you’re used to seeing and have seen since grade school.
  • You already know scalar arithmatic and algebra, but you may not have known that it was scalar arithmatic and algebra. A scalar algebra by any other name would smell as sweet...
  • For example,

[ 1

] or

[ a

] or

[ σ

] are all scalars.

§ 2 Arithmetic

Let’s build “up” from scalar arithmetic:

 2.1 Scalar Arithmetic

You’ve known how to perform these operations for a long time...

  • Addition (& subtraction): 1 + 2 = 3
  • Multiplication: 2 ∗ 3 = 6
  • Division: 3/4 = 3 ∗ (1/4) = 3 ∗ (4)−^1

 2.2 Vector Arithmetic

For vector arithmatic, we have to make sure that the vectors are conformable for that particular operation.

[A] Addition (& Subtraction): To be conformable, the vectors must both be the “same size” (that is, they must both be row-vectors with the same number of columns or both be column-vectors with the same number of rows).    

   

   

   

   

   

[B] Multiplication: To be conformable, we can either multiply a row-vector times a column-vector or a column-vector times a row-vector, but we cannot multiply two row vectors or two column vectors. Unlike scalar multiplication, the order is important: RC 6 = CR

  • Inner Product: row-vector * column-vector = scalar In addition, to be conformable for inner-product multiplication, the number of columns in the row-vector must equal the num- ber of rows in the column-vector.

[ 1 2 3

] ·

   

   

More generally, if R =

[ r 1 r 2 r 3

] and C =

   

c 1 c 2 c 3

   

then

RC =

∑ ri ∗ ci

  • Outer Product: column-vector * row-vector = matrix The vectors may be of any size, but their sizes will determine the size of the matrix yielded by their outer product.

For example, if A =

  

   and^ B^ =

   

   

then

AB =

  1 2 3 4 5 6

  ·

   

   

  1 ∗^ 1 + 2^ ∗^ 1 + 3^ ∗^1 1 ∗^ 2 + 2^ ∗^ 2 + 3^ ∗^2 4 ∗ 1 + 5 ∗ 1 + 6 ∗ 1 4 ∗ 2 + 5 ∗ 2 + 6 ∗ 2

 

  

  

BA =

   

   

  1 2 3 4 5 6

  =

   

   

   

   

Clearly, AB 6 = BA, which is obvious because they are different sizes.

[C] Inverses: The matrix analogue of division is multiplying by an inverse (which is another way of thinking about division in scalar arithmetic).

  • Finding the inverse of a matrix is (relatively) easy for square matrices and (relatively) complex for rectangular matrices. Fortunately for us, we will only need to find the inverse of square matrices.
  • For scalars, the inverse of a number times that number is one. A matrix inverse times that matrix should be equal to “one” – but we need to find a matrix version of “one.”
  • The matrix equivalent of one is called the “Identity Matrix.” The identity matrix has one’s on the main diagonal (elements with row and column indices that are equal) and zeroes elsewhere.
  • For instance, I 4 x 4 =

     

     

  • Thus, for matrix inverses, A · A−^1 = I = A−^1 · A
  • We have a fairly simple formula for 2x2 matrices.

If A =

  a^ b c d

  then A− (^1) = 1 ad−bc

  d^ −b −c a

 

  • For example, if A =

  2 1 3 4

  then A− (^1) = 1 2 ∗ 4 − 1 ∗ 3

  4 −^1 − 3 2

  =

  4 /^5 −^1 /^5 − 3 / 5 2 / 5

 

Let’s check to make sure that AA−^1 = I   2 1 3 4

  ·

  0.^8 −^0.^2 − 0. 6 0. 4

  =

  1.^6 −^0.^6 −^0 .4 + 0.^4

  1. 4 − 2. 4 − 0 .6 + 1. 6

  =

  1 0 0 1

 

  • This formula applies only to 2x2 matrices, although there is a similar (but much more complicated) formula for 3x3 matrices. There are other methods for handling larger matrices in a more general way. Please see your instructor if you are interested.

 2.4 Relationships of Matrices, Vectors, & Scalars

If we look carefully at these matrix operations, we will see that all of the matrix operations still hold when applied to vectors (because vectors are a “special case” of matrices in that they only have a single row or a single column). The same is true of scalars.

§ 3 Additional Matrix Operations

In addition to generalizing scalar arithmetic, there are other operations specific to matrices.

 3.1 Transpose

To transpose a matrix (or vector), each row is made into a column, which means that each column will become a row in the transposed matrix.

  • If A =

  

  , then^ A′^ =

   

   

  • If A = A′, then we say that A is symmetric. Thus, only square matrices may be symmetric since the sizes would not work out for rectangular matrices.

 3.2 Determinants

Determinants are only defined for square matrices, and they are found using a recursive algorithm.

[A] The determinant of a scalar is that scalar:

∣∣ ∣∣ a

∣∣ ∣∣ = a.

 4.1 Defining & Accessing Matrices

[A] Compute Statement

  • Use the compute statement to define or redefine matrices.
  • The name of the matrix goes on the left of the equal size, and the elements go on the right, enclosed in curly braces { and }.
  • Each element is separated by a comma, and each row is separated by a semi-colon.
  • COMPUTE A = {1,2,3; 4,5,6}.

[B] Print Statement

  • Use the print statement to print matrices or matrix expressions (listed in parentheses).
  • PRINT A.

• PRINT (A+B).

[C] To access parts of a matrix, use parentheses after the matrix name.

  • To print the second element on the first row: PRINT A(1,2).
  • To print the first row, use a colon in lieu of the column index: PRINT A(1,:).
  • To print the first two rows, use a colon in lieu of the column index and to specify a range in the row index: PRINT A(1:2,:)
  • You can also create one matrix that is a sub-matrix of another: COMPUTE B = A(1:2,1:2). In this case, B would be the upper-left 2x2 corner of A.

 4.2 Matrix Arithmetic

[A] Addition COMPUTE C = B + A.

[B] Subtraction COMPUTE C = A - B.

[C] Multiplication COMPUTE C = B * A.

 4.3 Matrix Functions

[A] Determinants COMPUTE d = DET(A).

[B] Traces COMPUTE t = TRACE(A).

[C] Inverses COMPUTE B = INV(A).

[D] mdiag COMPUTE Lam = mdiag(vector).

[E] diag COMPUTE vector = diag(M).

§ 5 Statistical Matrix Applications

It’s all well and good to define these unary and binary matrix operators, but our initial purpose in learning matrix algebra was to apply these techniques to statistical problems Let us turn to computing the means, variances, and covariances of a univariate data set and then for a multivariate data set.

We will consider this data set:

COMPUTE X = {

COMPUTE X1 = X(:,1).

COMPUTE X2 = X(:,2).

COMPUTE X3 = X(:,3).

 5.1 Means

[A] We all remember how to compute means for a single variable (e.g., X 1 ): X¯ 1 =

∑ X 1 n =^

36 8 = 4.^5 [B] To generalize computing means to matrix algebra, we’ll use a row-vector with as many columns as there are rows in the data (cases) as a pre-multiplier to add up the observations:

COMPUTE N = nrow(X1). COMPUTE rowunit = make(1,N,1.00). COMPUTE SUMX1 = rowunitX1. COMPUTE meanx1 = (1/N)SUMX1.

 5.4 The Correlation Matrix

Although the variance-covariance matrix describes the degree to which a set of variables vary and co-vary together, it is unstandardized. We compute the correlation coefficient as a “standardized” covariance, and we can compute a whole matrix of correlation coefficients.

[A] We all remember the correlation coefficient forumula between X 1 and X 2 : r = (^) (covSX(X^1 ,X^2 ) 1 )(SX 2 ) [B] We can extend this formula by standardizing the variance-covariance matrix. Essentially, we will need to divide each element by the standard deviation of the row-variable and by the column- variable. So, we’ll find the inverse of the diagonal standard-deviation matrix. Premultiplying by this matrix will divide each element by the row-variable standard deviation, and postmultiplying by this matrix will divide each element by the column-variable standard deviation.

COMPUTE sdinv = INV(SD). COMPUTE R = sdinvSsdinv.