Monday, January 2, 2012

Monetary Policy & Credit Easing pt. 8: Econometrics Tests in R

Hello, folks its time to cover some important econometrics tests you can do in R.

The Akaike information criterion is a measure of the relative goodness of fit of a statistical model.  If you have 10 models and order them by AIC, the one with the smallest AIC is your best model, ceterus paribus.
The following code can figure the AIC and a similar version called BIC:



> AIC(srp1.gls)
[1] 100.7905


> BIC(srp1.gls)
[1] 140.7421

Say we wish to see if our model has an error term that follows a relatively normal distribution. For this we can perform the Jarque-Bera which tests kurtosis as well as skewness. This function requires that you load the FitAR package.


> JarqueBeraTest(srp1.gls$res[-(1)])
$LM
[1] 19.2033


$pvalue
[1] 6.761719e-05

To see if the mean of the residual values is 0 and to see the standard deviation the following code works:


> mean(srp1.gls$res[-(1)])
[1] 0.003354243
> sd(srp1.gls$res[-(1)])
[1] 0.3666269

Other tests like the Breusch-Pagan and Goldfeld-Quandt provide facts like wether autocorrelation is present and give us a hint as to wether our residual variance is stable or not. In order for these to work you have to load the lmtest package. Also you can only run these for the lm objects or for your Ordinary Least Squares Regressions for any Generalized Least Squares regressions you'll have to perform these test manually, and if you know of an easier or softer way please share.


> bptest(srp1.lm)


studentized Breusch-Pagan test


data:  srp1.lm 
BP = 48.495, df = 12, p-value = 2.563e-06


> gqtest(srp1.lm)


Goldfeld-Quandt test


data:  srp1.lm 
GQ = 0.1998, df1 = 40, df2 = 40, p-value = 1


You can also use the Durbin-Watson to test for first order autocorrelation:


> dwtest(srp1.lm)


Durbin-Watson test


data:  srp1.lm 
DW = 1.4862, p-value = 0.0001955
alternative hypothesis: true autocorrelation is greater than 0 

Wish to get confidence intervals for your parameter estimates? Then use the confint() function as shown below for the Generalized Least Squares regression on long-term risk premia from 2001-2011.


> confint(p2lrp.gls)
                                    2.5 %                               97.5 %
yc                                -0.1455727340         0.1498852728
default                      0.2994818014             1.0640354237
Volatility                   0.0336077958             0.0617798767
CorporateProfit      -0.0010916473             0.0006628209
FF                               -0.1788624533             0.0931406285
ER                              0.0001539035                        0.0016060804
Fedmbs                      -0.0061554994             0.0085638593
Support                     -0.1499342096             0.1615652273
FedComm                     -0.0108567077             0.0750407328
FedGdp                      -0.1347070955             0.2528217710
ForeignDebt                 -0.0441198164             0.1042805549
govcredit                    0.1090847204             0.6796839003
FedBalance                  -2.0940925835             0.0370114069
UGAP                        -0.4821566147             0.3188891550
OGAP                        -0.2239749029             0.1073611677

Another nice feature is finding the log-likelihood of your estimation:

> logLik(lrp2.lm)
'log Lik.' 23.05106 (df=17)

Want to see if you have a unit-root in your residual values? Then perform the augmented Dickey-Fuller. For this you'll have to load the 'tseries' package.

> adf.test(lrp2.gls$res[-(1:4)])

                              Augmented Dickey-Fuller Test

data:  lrp2.gls$res[-(1:4)]
Dickey-Fuller = -7.4503, Lag order = 3, p-value = 0.01
alternative hypothesis: stationary

Warning message:
In adf.test(lrp2.gls$res[-(1:4)]) : p-value smaller than printed p-value
> adf.test(lrp2.lm$res)




I hope this mini-series has been informative to all that tuned in. For more info on anything you see here please don't be shy to comment and keep dancin',

Steven J.

4 comments:

  1. QE 1 2 and 3 is a joke their is no benefit to it at all. Inflation is going to be the end result of all this money printing.

    ReplyDelete
  2. Are You In Need Of A Private Or Business Loans At 2% Rate For Various Purposes? If Yes; Contact us: opploansllc@gmail.com

    *Full Name:_________
    *Address:_________
    *Phone number:_________
    *loan amount:_________
    *Loan duration:_________
    *Country:_________
    *Purpose of loan:_________
    *Occupation__________

    Best regards
    Managements
    Contact us: opploansllc@gmail.com

    ReplyDelete
  3. Are you in need of a loan?
    Do you want to pay off your bills?
    Do you want to be financially stable?
    All you have to do is to contact us for
    more information on how to get
    started and get the loan you desire.
    This offer is open to all that will be
    able to repay back in due time.
    Note-that repayment time frame is negotiable
    and at interest rate of 2% just email us:
    reply to us (Whats App) number: +919394133968
    patialalegitimate515@gmail.com
    Mr Jeffery

    ReplyDelete
  4. URGENT LOAN IS AVAILABLE NOW

    TODAY I GOT MY DESIRED LOAN AMOUNT $760K FROM A RELIABLE,TRUSTED AND REGISTERED PRIVATE LOAN COMPANY LAST WEEK,BUSINESS/HOME/COMPANY/PROJECT/PERSONAL LOAN? ARE NOW AFFORDABLE HERE FOR YOU TODAY CONTACT Call/Text +1(315)256-0479 Email profdorothyinvestments@gmail.com

    Hello, I'm here to testify of how i got my real estate business loan from PROF. MRS.DOROTHY JEAN INVESTMENTS (profdorothyinvestments@gmail.com) I don't know if you are in need of an urgent loan to pay bills, start business or build a house, they offer all kinds of loan Ranging from $5,000.00USD to $2,000,000.00USD with a low interest rate of 2% and loan duration of 1 to 33 years to pay back the loan secure and unsecured. Are you losing sleep at nights worrying how to get a Legit Loan Lender?
    MRS.DOROTHY JEAN holds all of the information about how to obtain money quickly and painlessly without cost/stress via Contacts Call/Text +1(315)256-0479
    Email profdorothyinvestments@gmail.com


    ReplyDelete