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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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 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: h Y 1 Y 2 Y n i . 6 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 h x, y i = n X 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...
View Full Document

This note was uploaded on 10/30/2011 for the course AMS 578 taught by Professor Finch,s during the Spring '08 term at SUNY Stony Brook.

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 Right Arrow Icon
Ask a homework question - tutors are online