If A and B is 3 x 3 matrix, then AB is also a 3 x 3 matrix. However AB≠BA because matrix multiplication is not commutative.
As an illustration: matrixOLS.xlsm
A=[123456789]B=[111213141516171819]
Then,
AB=[1∗11+2∗14+3∗171∗12+2∗15+3∗181∗13+2∗16+3∗194∗11+5∗14+6∗174∗12+5∗15+6∗184∗13+5∗16+6∗197∗11+8∗14+9∗177∗12+8∗15+9∗157∗13+8∗16+9∗19]=[9096102216231246342366390]
and
BA=[11∗1+12∗4+13∗711∗2+12∗5+13∗811∗3+12∗6+13∗914∗1+15∗4+16∗714∗2+15∗5+16∗814∗3+15∗6+16∗917∗1+18∗4+19∗717∗2+18∗5+19∗817∗3+18∗6+19∗9]=[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=7a−5b2=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=ˆx−1ˆy
These are the steps applied to the example:
1. The linear equation was converted into its matrix form.
2. We got ˆx−1 by using Excel's function =MINVERSE(array)
3. The formula ˆb=ˆx−1ˆy is then applied using the Excel's function =MMULT(array).
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=ˆx−1ˆ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