Upload
lieu
View
38
Download
2
Tags:
Embed Size (px)
DESCRIPTION
Matrix Algebra. Methods for Dummies FIL November 17 2004 Mikkel Wallentin [email protected]. 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 - PowerPoint PPT Presentation
Citation preview
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/
Design matrix …
=
+
= +Y X
data v
ecto
r
design
mat
rix
param
eters
erro
r vec
tor
= the b
etas (
here :
1 to
9)
Scalars, vectors and matrices • Scalar: Variable described by a single
number – e.g. Image intensity (pixel value)
e
n
v
vv
• Vector: Variable described by magnitude and direction
476
145
321
A
Square (3 x 3) Rectangular (3 x 2) d i j : ith row, jth column
83
72
41
C 3
2• Matrix: Rectangular array of scalars
333231
232221
131211
ddd
ddd
ddd
D
z
y
x
v
v
v
v
vczbyax vbyax
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.
• Addition (matrix of same size)
– Commutative: A+B=B+A– Associative: (A+B)+C=A+(B+C)
• Eg.
Matrix addition
33
33
11
11
22
22BA
Matrix multiplication
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.
Multiplication of a matrixand a constant:
…Each parameter (the betas) assigns a weight to a single column in the design matrix …
=
+
= +Y X
data v
ecto
r
design
mat
rix
param
eters
erro
r vec
tor
= the b
etas (
here :
1 to
9)
Transposition
9
4
3Td
2
1
1
b 211Tb 943d
column → row row → column
476
145
321
A
413
742
651TA
332313
322212
312111
321
3
2
1
yxyxyx
yxyxyx
yxyxyx
yyy
x
x
xTxy
Outer product = matrix
ii
iT yxyxyxyx
y
y
y
xxx
3
1332211
3
2
1
321yx
Inner product = scalar
Two vectors:
3
2
1
x
x
x
x
3
2
1
y
y
y
y
Example
Note: (1xn)(nx1) -> (1X1)
Note: (nx1)(1xn) -> (nXn)
…A contrast estimate is obtained by multiplying the parameter estimates by a transposed contrast vector …
=
+
= +Y X
data v
ecto
r
design
mat
rix
param
eters
erro
r vec
tor
cont
rast
vecto
r
c
SPM{t}
A contrast = a linear combination of parameters: cT
cT = 1 0 0 0 0 0 0 0
divide by estimated standard deviation
T test - one dimensional contrasts - SPM{t}
T =
contrast ofestimated
parameters
varianceestimate
T =
ss22ccT (X(XTX)X)++cc
ccTbb
box-car amplitude > 0 ?=
> 0 ? =>
Compute 1xb + 0xb + 0xb + 0xb + 0xb + . . . and
b b b b b ....
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
H0: 3-9 = (0 0 0 0 ...)
cT =
SPM{F}
tests multiple linear hypotheses. Ex : does DCT set model anything?
F-test (SPM{F}) : a reduced model or ...multi-dimensional contrasts ?
test H0 : cT b = 0 ?
X1 (3-9)X0
This model ? Or this one ?
H0: True model is X0
X0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 00 0 0 0 1 0 0 00 0 0 0 0 1 0 00 0 0 0 0 0 1 00 0 0 0 0 0 0 1
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
Recall that for 2x2 matrices:
•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 2x2 matrix A, det(A) = ad-bc. Lets have at closer look at that:
And generally :
Matrix Inverse - Calculations
dc
baA IAA
10
01
43
211
dc
ba
xx
xx
43
211
xx
xxA
ac
bd
bcad )(
11A
A general matrix can be inverted using methods such as the Gauss-Jordan elimination, Gaussian elimination or LU decomposition
1
0
0
1
43
43
21
21
dxbx
cxax
dxbx
cxax
bbcadadbc
bxdx
a
cxb
a
cxx
)(
1
)(0
1
1
222
21
ac
bd
A)det(
11Ai.e. Note: det(A)≠0
System of linear equationsImagine a drink made of egg, milk and orange juice. Some of the propertiesof these ingredients are described in this table:
If we now want to make a drink with 540 calories and 25 gof protein, the problem of finding the right amount of the ingredientscan be formulated like this:
z
y
x
692
11016080
25
540or
A similar problem …
=
+
= +Y X
data v
ecto
r
design
mat
rix
param
eters
erro
r vec
tor
= the b
etas (
here :
1 to
9)
Cramer’s rule• Consider the linear system (in matrix form)
• A X = 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!