Monday, January 28, 2013

OLS Macro I


Code lies on matrixOLS.xlsm

Sub olsmaker()
' this solves for regression calling on fixed number of dataset
' Also matrix form is defined by the user.

    'calling for x and y
    x = Range("A105:B114").Value
    y = Range("C105:C114").Value
    
    'solving for b=(xT x)^-1 (xT y)
    xT = Application.WorksheetFunction.Transpose(x)
    xTx = Application.WorksheetFunction.MMult(xT, x)
    xTxinv = Application.WorksheetFunction.MInverse(xTx)
    xTxinvxT = Application.WorksheetFunction.MMult(xTxinv, xT)
    sol = Application.WorksheetFunction.MMult(xTxinvxT, y)

    'returning it back to the sheet
    Range("F106") = "b="
    Range("F107:F108").Value = sol

End Sub

Notes:
1. How do I make it dynamic? Update this program.
2. Review on Matrix and OLS. Work on how did this happened. And is there a way to shorten the form?
 \[ \hat{b} = \hat{x}^{-1}\hat{y} \to \hat{b} = (\hat{x}^T \hat{x})^{-1} \hat{x}^T \hat{y} \]
3. Very interested in programming numerical methods. Add it to the List to program.
4. Read the book: VB for Dummies.

No comments:

Post a Comment