{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Chp5 - Matrix Approach to Simple Linear Regression Analysis...

This preview shows pages 1–6. Sign up to view the full content.

Matrix Approach to Simple Linear Regression Analysis Matrix Overview Matrix Approach to Linear Regression 1 Matrix Definition A matrix is a rectangular array of elements arranged in rows and columns. The dimension of the matrix is n × p , where n is the number of rows and p the number of columns. A matrix with n rows and p columns is usually represented using bold- face letters, say A, which can be represented as A = a 11 a 12 · · · a 1 j · · · a 1 p . . . . . . . . . . . . a i 1 a i 2 · · · a ij · · · a ip . . . . . . . . . . . . a n 1 a n 2 · · · a nj · · · a np 2

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
or A = [ a ij ] , i = 1 , · · · , n ; j = 1 , · · · , p, where a ij is the element in the i th row and j th column. Two matrices A = B , if and only if their corresponding elements are equal, a ij = b ij . When n = p , matrix A is called a square matrix. When p = 1, A is called a column vector or simply a vector. When n = 1, A is called a row vector. column vector: Y 1 Y 2 Y 3 , X 1 X 2 X 3 , row vector: [1 , X 1 ] square matrix: 3 3 i =1 X i 3 i =1 X i 3 i =1 X 2 i , (design) matrix: 1 X 1 1 X 2 1 X 3 3 R commands for creating matrix ## simulate data for a regression model n = 25; p = 2 x = rnorm(n); y = 1 + 2*x + rnorm(n) ## or use real data toluca = read.table("toluca.txt", head=TRUE) x = toluca\$LotSize; y = toluca\$WorkHours ### create a matrix A = matrix( c(rep(1,n),x), n,p, byrow=FALSE ) dim(A); nrow(A); ncol(A) ### column/row vector: R indexing cmd A[,1]; A[,2] ## jth column A[1,]; A[n,] ## ith row 4
### Create matrix by binding columns/rows together cbind(1, x); rbind(1, x) ### Extact the (i,j)th element ## Matrix is a special vector with "dim" attribute A[1,1]; A[n,p]; A[1]; A[n*p] # Not Recommended!!! 5 Matrix Transpose For A = [ a ij ], the transpose A = [ a ji ]; i = 1 , · · · , n ; j = 1 , · · · , p, (1) column vector: Y 1 Y 2 . . . Y n , (transpose) row vector: Y 1 Y 2 · · · Y n . 6

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
A is called a symmetric matrix if A = A , which implies n = p and a ij = a ji . symmetric matrix: n n i =1 X i n i =1 X i n i =1 X 2 i , R commands for transposing a matrix ### t() for matrix transpose t(x); t(y) Ap = t(A) ### checking the dim and individual elements dim(A); dim(Ap) A[2,1]; Ap[1,2] A[n,p]; Ap[p,n] 7 Matrix Summation and Subtraction Element-wise summation and subtraction C = A ± B ; c ij = a ij ± b ij . (2) R commands ## create a random matrix B B = matrix( rnorm(n*p), n, p ) ## Summation and subtraction A + B; A - B 8
Matrix Multiplication Inner product of two R n vectors, x = ( x 1 , · · · , x n ); y = ( y 1 , · · · , y n ) is defined as x, y = n k =1 x k y k (3) The product of a scalar (an ordinary number) and matrix A is λA = [ λa ij ] . 9 The product of matrix A and B is determined by the inner products of matrix rows and columns C = AB ; c ij = ( a i 1 , · · · , a in ) , ( b 1 j , · · · , b nj ) = n k =1 a ik b kj (4) i.e. the ij th element of the product matrix is the inner product of the i th row of A and the j th column of B (viewed as vectors in R n ). So A must have the same number of columns as the number of rows of B.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 20

Chp5 - Matrix Approach to Simple Linear Regression Analysis...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online