This is a simple function that I ended up using quite often.
InfoCrit() returns a vector containing the AICs or BICs for autoregressive models of a given variable for lags 0:n .
1.Download a copy of this function onto your machine
2.Pull the function into your R environment with source("your\path\InfoCrit")
3.The function can now be called like any other InfoCrit(data_, column, lags, Type)
- data_
Expects a dataframe containing atleast 1 named variable
- column
String - Name of the column of the dataframe to be used in the AR model.
- lags
int - Number of lags in the highest order model you want to run.
- Type
String - Default = "AIC" , but also allows "BIC".At some point I may add others.
Formula used to calculate the AIC:
Formula used to calculate the BIC:
Where
This may not agree with other R functions used to calculate Information criterion as they sometimes use different formulas.
Wesely Bundell Ph.D. http://www.wesleyblundell.com/ for assigning the homework that made this necessary.