Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
in matrix terms
for i = 1,, n
Y1 0 1 x1 1
Y2 0 1 x 2 2
Yn 0 1 x n n
1 x1
1
1 x
2
2
0
1 xn
n
Y X
Definition of a matrix
An rc matrix is a rectangular array of symbols or
numbers arranged in r rows and c columns.
A matrix is almost always denoted by a single capital
letter in boldface type.
1 2
A
6
3
1 80 3.4
1 92 3.1
B 1 65 2.5
1 71 2.8
1 40 1.9
x12
x 22
x32
1 x 41
1 x51
1 x61
x 42
x52
x62
1 x11
1 x
21
1 x31
h 21 46 32 90
Matrix multiplication
Y X
The X in the regression function is an example of
matrix multiplication.
Two matrices can be multiplied together:
Only if the number of columns of the first matrix equals
the number of rows of the second matrix.
The number of rows of the resulting matrix equals the
number of rows of the first matrix.
The number of columns of the resulting matrix equals
the number of columns of the second matrix.
Matrix multiplication
If A is a 23 matrix and B is a 35 matrix
then matrix multiplication AB is possible.
The resulting matrix C = AB has rows
and columns.
Is the matrix multiplication BA possible?
If X is an np matrix and is a p1 column
vector, then X is
Matrix multiplication
3 2 1 5
1 9 7
90 101 106 88
C AB
5
4
7
3
41 38 27 59
8
1
2
6 9 6 8
The entry in the ith row and jth column of C is the inner
product (element-by-element products added together)
of the ith row of A with the jth column of B.
c11 1(3) 9(5) 7(6) 90
c24
The X multiplication in
simple linear regression setting
1 x1
1 x
2
0
1 xn
Matrix addition
Y X
The X+ in the regression function is an example
of matrix addition.
Simply add the corresponding elements of the two
matrices.
For example, add the entry in the first row, first column
of the first matrix with the entry in the first row, first
column of the second matrix, and so on.
Matrix addition
2 4 1 7 5 2 9 9 1
C A B 1 8 7 9 3 1 10 5 8
3 5 6 2 1 8 5 6 14
For example:
c11 2 7 9
c12 4 5 9
c23
Y
X
Yn
0 1 x n n
1 x11
1 x
21
1 x n1
x12
x 22
xn2
x13
x 23
xn3
Y X
1
2
n
b0
b
1
b p 1
X X X Y
1
Definition of
the transpose of a matrix
The transpose of a matrix A is a matrix, denoted
A' or AT, whose rows are the columns of A and
whose columns are the rows of A all in the same
original order.
1 5
A 4 8
7 9
A A
1
x2
1 x1
1 1 x2
xn
1 xn
1 0
I2
0 1
The identity matrix plays the same role as the
number 1 in ordinary arithmetic.
9 7 1 0
4 6 0 1
A A I AA
Find X'X.
yi
x i yi
suds so*su
33 132.0
42 189.0
45 225.0
51 280.5
53 318.0
61 396.5
62 434.0
--- ----347 1975.0
x i2
soap2
16.00
20.25
25.00
30.25
36.00
42.25
49.00
----218.75
b0
1
b X X X Y ?
b1
1
X X
x1
1 1
x 2 x n
1 x1
1 x
2
1 xn
X X X X
38.5
7
38
.
5
218
.
75
4.4643 0.78571
0.78571 0.14286
Therefore:
X X
38.5
7
38
.
5
218
.
75
4.4643 0.78571
0
.
78571
0
.
14286
Find X'Y.
yi
x i yi
suds so*su
33 132.0
42 189.0
45 225.0
51 280.5
53 318.0
61 396.5
62 434.0
--- ----347 1975.0
x i2
soap2
16.00
20.25
25.00
30.25
36.00
42.25
49.00
----218.75
b0
1
b X X X Y ?
b1
1
X Y
x1
1 1
x 2 x n
y1
y
2
yn
4.4643 0.78571
X Y
0.78571 0.14286
347
1975
0
.
78571
(
347
)
0
.
14286
(
1975
)
9
.
51
1
The regression equation is
suds = - 2.68 + 9.50 soap
Linear dependence
The columns of the matrix:
1 2 4 1
A 2 1 8 6
3 6 12 3
Linear dependence
is not always obvious
1 4 1
A 2 3 1
3 2 1
Formally, the columns a1, a2, , an of an nn matrix are
linearly dependent if there are constants c1, c2, , cn,
not all 0, such that:
c1a1 c2 a 2 cn a n 0
soap2 suds
8
33
9
42
10
45
11
51
12
53
13
61
14
62
Fitted values
y1 b0 b1 x1
y b b x
2
0
1 2
y n b0 b1 x n
Fitted values
The vector of fitted values
y Xb X X X X y
1
H X X X X
1
That is:
X X X
y
X y Hy
en yn y n
for i = 1,, n
e1
e
2
en
y1 y1
y y
2
2
yn y n
e1
e
2
y1 y1
y y
2
2
en
yn y n
Sum of squares
and the analysis of variance table
DF
SS
MS
p-1
SSR b X Y Y JY
n
SSR
p 1
MSR
MSE
Error
n-p
SSE Y Y bX Y
Total
n-1
SSTO Y Y
1
Y JY
n
SSE
n p
Sum of squares
In general, if you pre-multiply a vector by its transpose,
you get a sum of squares.
yy y1
y2
y1
y
n
2
yn y12 y22 yn2 yi2
i 1
yn
SSE yi y i
i 1
SSTO y i y yi
2
1
SSTO Y Y Y JY
n
where J is a (square) nn matrix containing all 1s.
An example of
total sum of squares
If n = 2:
i 1
Yi
1 1 Y1
2
2
Y2
2
Y
Y
Y
1
1 2
2
Y
1
1
DF
SS
MS
p-1
SSR b X Y Y JY
n
SSR
p 1
MSR
MSE
Error
n-p
SSE Y Y bX Y
Total
n-1
SSTO Y Y
1
Y JY
n
SSE
n p
Model assumptions
1
2
E 1 0
E 0
2
E
0
E n 0
Definition
Assumption
Definition
2
2 ( 1 , 2 ) 2
( 2 , n )
2
2
2
n ( 1 , n ) ( 2 , n ) n
1 2 0 0
2
2 0
0
2
n 0
0
1 4 0 2 8 0
2 7 6 5 14 12 10
1 3 2 2 6 4
2
0
0
2
2
0
0
Y X
where:
Y is a (
is a (
X is an (
is an (
) vector of independent, normal error
terms with mean 0 and (equal) variance 2I.