Matrix Algebra Methods for Dummies FIL November 17
Matrix Algebra Methods for Dummies FIL November 17 2004 Mikkel Wallentin mikkel@pet. auh. dk
Sources • • www. sosmath. com www. mathworld. wolfram. com www. wikipedia. org Maria Fernandez’ slides (thanks!) from previous MFD course: http: //www. fil. ion. ucl. ac. uk/spm/doc/mfd 2004. html • Slides from SPM courses: http: //www. fil. ion. ucl. ac. uk/spm/course/
Y = X = = b 4 b 5 ´ b + r to ec rv ro er as ( s er et eb th x ri at et m m ra pa n or ct ve de sig ta da e: he r 1 to Design matrix … a m b 3 + b 6 b 7 b 8 b 9 e 9)
Scalars, vectors and matrices • Scalar: Variable described by a single number – e. g. Image intensity (pixel value) • Vector: Variable described by magnitude and direction • Matrix: Rectangular array of scalars 2 3 Square (3 x 3) Rectangular (3 x 2) d i j : ith row, jth column
Matrices • A matrix is defined by the number of Rows and the number of Columns (eg. a (mxn) matrix has m rows and n columns). • A square matrix of order n, is a (nxn) matrix.
Matrix addition • Addition (matrix of same size) – Commutative: A+B=B+A – Associative: (A+B)+C=A+(B+C) • Eg.
Matrix multiplication Multiplication of a matrix and a constant: Rule: In order to perform the multiplication AB, where A is a (mxn) matrix and B a (kxl) matrix, then we must have n=k. The result will be a (mxl) matrix.
r to ec rv ro et eb = th er s er m pa da ta de sig ra n ve ct m et at or ri x as ( he r e: 1 to 9) …Each parameter (the betas) assigns a weight to a single column in the design matrix … a m b 3 b 4 = b 5 + b 6 b 7 b 8 b 9 Y = X ´ b + e
Transposition column → row → column
Example Two vectors: Inner product = scalar Outer product = matrix Note: (1 xn)(nx 1) -> (1 X 1) Note: (nx 1)(1 xn) -> (n. Xn)
Y X a 1 m 0 b 3 0 b 4 0 b 5 0 b 6 0 b 7 0 b 8 0 b 9 0 b rv ve ro st er ra nt co ra pa ´ ec ct s er et m m n de sig = to or x ri at or ct ve ta da = r …A contrast estimate is obtained by multiplying the parameter estimates by a transposed contrast vector … c + + e
T test - one dimensional contrasts SPM{t} A contrast = a linear combination of parameters: c. T ´ b c. T = 1 0 0 0 0 box-car amplitude > 0 ? = b 1 > 0 ? => b 1 b 2 b 3 b 4 b 5. . Compute 1 xb 1 + 0 xb 2 + 0 xb 3 + 0 xb 4 + 0 xb 5 +. . . and divide by estimated standard deviation T= contrast of estimated parameters variance estimate c Tb T= s 2 c. T (XTX)+c SPM{t}
Identity matrices • Is there a matrix which plays a similar role as the number 1 in number multiplication? Consider the nxn matrix: • For any nxn matrix A, we have A In = In A = A • For any nxm matrix A, we have In A = A, and A Im = A
F-test (SPM{F}) : a reduced model or. . . multi-dimensional contrasts ? tests multiple linear hypotheses. Ex : does DCT set model anything? H 0: True model is X 0 H 0: b 3 -9 = (0 0 0 0. . . ) X 0 X 1 (b 3 -9) X 0 c. T test H 0 : c. T ´ b = 0 ? 00100000 000100001000 =0 0 0 1 0 0 00000010 00000001 SPM{F} This model ? Or this one ?
Inverse matrices • Definition. A matrix A is called nonsingular or invertible if there exists a matrix B such that: • Notation. A common notation for the inverse of a matrix A is A-1. So: • The inverse matrix is unique when it exists. So if A is invertible, then A-1 is also invertible and
Determinants • Determinants are mathematical objects that are very useful in the analysis and solution of systems of linear equations (i. e. GLMs). • The determinant is a function that associates a scalar det(A) to every square matrix A. • The fundamental geometric meaning of the determinant is as the scale factor for volume when A is regarded as a linear transformation. • A matrix A has an inverse matrix A-1 if and only if det(A)≠ 0. • Determinants can only be found for square matrices. • For a 2 x 2 matrix A, det(A) = ad-bc. Lets have at closer look at that: Recall that for 2 x 2 matrices: And generally :
Matrix Inverse - Calculations i. e. Note: det(A)≠ 0 A general matrix can be inverted using methods such as the Gauss-Jordan elimination, Gaussian elimination or LU decomposition
System of linear equations Imagine a drink made of egg, milk and orange juice. Some of the properties of these ingredients are described in this table: If we now want to make a drink with 540 calories and 25 g of protein, the problem of finding the right amount of the ingredients can be formulated like this: or
Y = X = = b 4 b 5 ´ b + r to ec rv ro er as ( s er et eb th x ri at et m m ra pa n or ct ve de sig ta da e: he r 1 to A similar problem … a m b 3 + b 6 b 7 b 8 b 9 e 9)
Cramer’s rule • Consider the linear system (in matrix form) • AX=B • where A is the matrix coefficient, B the nonhomogeneous term, and X the unknown column-matrix. We have: Theorem. The linear system AX = B has a unique solution if and only if A is invertible. In this case, the solution is given by the so-called Cramer's formulas: • • • where xi are the unknowns of the system or the entries of X, and the matrix Ai is obtained from A by replacing the ith column by the column B. In other words, we have • • • where the bi are the entries of B. Thank you Bent Kramer!
- Slides: 20