






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







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.
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.
[ 1 2 3 4
]
[C] A scalar is a matrix (or row-vector or column-vector) that has only a single element.
[ 1
] or
[ a
] or
[ σ
] are all scalars.
Let’s build “up” from scalar arithmetic:
You’ve known how to perform these operations for a long time...
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
[ 1 2 3
] ·
More generally, if R =
[ r 1 r 2 r 3
] and C =
c 1 c 2 c 3
then
∑ ri ∗ ci
For example, if A =
and^ B^ =
then
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
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).
If A =
a^ b c d
then A− (^1) = 1 ad−bc
d^ −b −c 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 0 0 1
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.
In addition to generalizing scalar arithmetic, there are other operations specific to matrices.
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.
, then^ A′^ =
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.
[A] Compute Statement
[B] Print Statement
[C] To access parts of a matrix, use parentheses after the matrix name.
[A] Addition COMPUTE C = B + A.
[B] Subtraction COMPUTE C = A - B.
[C] Multiplication COMPUTE C = B * A.
[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).
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:
[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.
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.