Processing math: 100%

Monday, January 28, 2013

Matrices in OLS

Matrix Multiplication

If A and B is 3 x 3 matrix, then AB is also a 3 x 3 matrix. However ABBA because matrix multiplication is not commutative.

As an illustration: matrixOLS.xlsm

A=[123456789]B=[111213141516171819]

Then,
AB=[111+214+317112+215+318113+216+319411+514+617412+515+618413+516+619711+814+917712+815+915713+816+919]=[9096102216231246342366390]

and
BA=[111+124+137112+125+138113+126+139141+154+167142+155+168143+156+169171+184+197172+185+198173+186+199]=[150186222186231276222276330]


In Excel, matrix multiplication is easier.
1. Select a n x n where you will put your answer.
2. Use the function =MMULT(1st array, 2nd array) and
3. Type ctrl+shift+enter.

Matrices in OLS: 

 Sample1: on matrixOLS.xlsm

Given: 12=7a5b2=7+9b

Find: b

There are many ways to solve for b. Though the solution we made involves the theoretical concepts on matrices.


Given:
y1=a+bx1y2=a+bx2

then in matrix form:
ˆb=[ab]ˆy=[y1y2]ˆx=[1x11x2]

and
ˆy=ˆxˆbˆb=ˆx1ˆy



These are the steps applied to the example:

1. The linear equation was converted into its matrix form.
2. We got ˆx1 by using Excel's function =MINVERSE(array)
3. The formula ˆb=ˆx1ˆy is then applied using the Excel's function =MMULT(array).



Sample2:  matrixOLS.xlsm

Given the following dataset, find b.



Solution 1: Matrix

Sample 2 involves a series of x's and y's. If that is the case, solving for b would involve some transformation. 

ˆb=ˆx1ˆyˆb=(ˆxTˆx)1ˆxTˆy


The image below shows the solution for Sample2.



Solution 2: Graphing

1. Select the data to regress. x must be on the first column followed by the y.
2. Click on "Insert" Ribbon -> "Charts" -> "Scatter" -> "Scatter with only Markers".
3. Right click on one of the data points of the Graph.
4. Select "Add Trendline" or "Format Trendline"
5. Check on the "Display Equation on Graph." The slope is b and the y-intercept is a.




No comments:

Post a Comment