Calculates and outputs AIC value for some models including ARMA, ARIMA, SARIMA, ARMAX, ARIMAX, SARIMAX, ARCH and GARCH. To classify and extracts the best model by AIC values.
Usage
PrintAIC(DataTimeSeries, order = c(p, d = NULL, q = NULL),
seas = list(order = c(P = NULL, D = NULL, Q = NULL), frequency = NULL),
type = NULL,xreg=NULL)
Arguments
DataTimeSeries
Observation series.
order
If type="ARMA" (or ARMAX) then 'order' is a vector contain two positive integer which are order of ARMA model (or ARMAX model).
If type="ARIMA" (or ARIMAX) then 'order' is a vector contain three positive integer which are order of ARIMA model (or ARIMAX model).
If type="SARIMA" (or SARIMAX) then 'order' is a vector contain three positive integer which are order of ARIMA model (or ARIMAX model) of the non-seasonal part of the SARIMA model (or SARIMAX model).
If type="ARCH" then 'order' is a positive integer which are order of ARCH model.
If type="GARCH" then 'order' is a vector contain two positive integer which are order of GARCH model.
seas
A list contain two part which are 'order' and 'frequency'.
'order' part is a vector contain three positive integer which are order of ARIMA model of the seasonal part of the SARIMA model (or SARIMAX model).
'frequency' part is frequency of observation series.
type
Type of models.
xreg
Optionally, a vector or matrix of external regressors, which must have the same number of rows as x.
Details
The first, function identify type of models according to 'type' parameter. The next, test other parameters. All of parameters are reasonable, function will combine orders of models. And then, to calculate AIC value of each model. The last step, performing ranked
and extracting the best model.
Value
mohinh
Calculation results.
best
The best model following AIC value.
Note
You must be careful with 'order' and 'type' parameter of models.
Author(s)
Tran Thi Ngoc Han <tranthingochan01011994@gmail.com>
Mai Thi Hong Diem <maidiemks@gmail.com>
Hong Viet Minh <hongvietminh@gmail.com>
References
Nguyen Thi Diem My va Hong Viet Minh, Phan tich chuoi thoi gian voi su ho tro cua package AnalyzeTS.
Hong Viet Minh, Luan van tot nghiep dai hoc: Phan tich so lieu thong ke voi ngon ngu R.
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(AnalyzeTS)
Loading required package: MASS
Loading required package: TSA
Loading required package: leaps
Loading required package: locfit
locfit 1.5-9.1 2013-03-22
Loading required package: mgcv
Loading required package: nlme
This is mgcv 1.8-12. For overview type 'help("mgcv-package")'.
Loading required package: tseries
Attaching package: 'TSA'
The following objects are masked from 'package:stats':
acf, arima
The following object is masked from 'package:utils':
tar
Loading required package: TTR
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/AnalyzeTS/PrintAIC.Rd_%03d_medium.png", width=480, height=480)
> ### Name: PrintAIC
> ### Title: Print AIC Values
> ### Aliases: PrintAIC
> ### Keywords: PrintAIC
>
> ### ** Examples
>
> sl<-c(180,165,110,126,125,134,163,153,122,171,171,155
+ ,175,248,99,187,173,147,184,108,171,195,192,163)
> PrintAIC(sl,order=c(1,4),type="ARMA")
$Models
ARMA models AIC values Sort by AIC
Model 1 ARMA(0,1) ...AIC = 241.72 .......... 2
Model 2 ARMA(0,2) ...AIC = 243.61 .......... 3
Model 3 ARMA(0,3) ...AIC = 244.9 .......... 5
Model 4 ARMA(0,4) ...AIC = 246.78 .......... 8
Model 5 ARMA(1,0) ...AIC = 241.7 .......... 1
Model 6 ARMA(1,1) ...AIC = 243.7 .......... 4
Model 7 ARMA(1,2) ...AIC = 245.41 .......... 6
Model 8 ARMA(1,3) ...AIC = 246.52 .......... 7
Model 9 ARMA(1,4) ...AIC = 248.46 .......... 9
$Best
The best ARMA model
ARMA(1,0) ...AIC = 241.7
> PrintAIC(sl,order=c(1,1,4),type="ARIMA")
$Models
ARIMA models AIC values Sort by AIC
Model 1 ARIMA(0,1,1) ...AIC = 234.01 .......... 1
Model 2 ARIMA(0,1,2) ...AIC = 235.42 .......... 2
Model 3 ARIMA(0,1,3) ...AIC = 237.42 .......... 4
Model 4 ARIMA(0,1,4) ...AIC = 238.77 .......... 6
Model 5 ARIMA(1,1,0) ...AIC = 240.62 .......... 8
Model 6 ARIMA(1,1,1) ...AIC = 235.48 .......... 3
Model 7 ARIMA(1,1,2) ...AIC = 237.42 .......... 5
Model 8 ARIMA(1,1,3) ...AIC = 239.32 .......... 7
Model 9 ARIMA(1,1,4) ...AIC = 240.78 .......... 9
$Best
The best ARIMA model
ARIMA(0,1,1) ...AIC = 234.01
> PrintAIC(sl,order=c(1,1,4),seas=list(order=c(0,0,1),frequency=4),
+ type="SARIMA")
$Models
SARIMA models AIC values Sort by AIC
Model 1 SARIMA(0,1,1)*(0,0,1),s=4 ...AIC = 235.74 .......... 2
Model 2 SARIMA(0,1,2)*(0,0,1),s=4 ...AIC = 237.42 .......... 3
Model 3 SARIMA(0,1,3)*(0,0,1),s=4 ...AIC = 238.77 .......... 5
Model 4 SARIMA(0,1,4)*(0,0,1),s=4 ...AIC = 240.72 .......... 7
Model 5 SARIMA(1,1,0)*(0,0,1),s=4 ...AIC = 235.48 .......... 1
Model 6 SARIMA(1,1,1)*(0,0,1),s=4 ...AIC = 237.55 .......... 4
Model 7 SARIMA(1,1,2)*(0,0,1),s=4 ...AIC = 239.36 .......... 6
Model 8 SARIMA(1,1,3)*(0,0,1),s=4 ...AIC = 240.78 .......... 8
Model 9 SARIMA(1,1,4)*(0,0,1),s=4 ...AIC = 242.76 .......... 9
$Best
The best SARIMA model
SARIMA(1,1,0)*(0,0,1),s=4 ...AIC = 235.48
> PrintAIC(sl,order=c(4),type="ARCH")
$Models
ARCH models AIC values Sort by AIC
Model 1 ARCH(1) ...AIC = 305.25 .......... 4
Model 2 ARCH(2) ...AIC = 292.7 .......... 3
Model 3 ARCH(3) ...AIC = 281.79 .......... 2
Model 4 ARCH(4) ...AIC = 271.12 .......... 1
$Best
The best ARCH model
ARCH(4) ...AIC = 271.12
Warning messages:
1: In sqrt(pred$e) : NaNs produced
2: In sqrt(pred$e) : NaNs produced
3: In sqrt(pred$e) : NaNs produced
4: In sqrt(pred$e) : NaNs produced
> PrintAIC(sl,order=c(1,4),type="GARCH")
$mohinh
GARCH models AIC values Sort by AIC
Model 1 GARCH(1,0) ...AIC = 303.16 .......... 4
Model 2 GARCH(1,1) ...AIC = 305.16 .......... 5
Model 3 GARCH(1,2) ...AIC = 295.36 .......... 3
Model 4 GARCH(1,3) ...AIC = 285.56 .......... 2
Model 5 GARCH(1,4) ...AIC = 275.69 .......... 1
$best
The best GARCH model
GARCH(1,4) ...AIC = 275.69
Warning messages:
1: In garch(DataTimeSeries, order = c(i1, i2), trace = FALSE) :
singular information
2: In garch(DataTimeSeries, order = c(i1, i2), trace = FALSE) :
singular information
3: In sqrt(pred$e) : NaNs produced
4: In sqrt(pred$e) : NaNs produced
5: In sqrt(pred$e) : NaNs produced
>
>
> #The ARIMAX models
> #A factor
> date<-as.factor(c("Tue","Wed","Thu","Fri","Mon","Tue","Wed",
+ "Thu","Fri","Mon","Tue","Wed","Thu","Fri","Mon","Tue","Wed",
+ "Thu","Fri","Mon","Tue","Wed","Thu","Fri","Mon","Tue","Wed",
+ "Thu","Fri","Mon","Tue","Wed","Thu"))
>
> #Observation series.
> coffee<-c(5,6,8,4,3,7,6,0,3,2,3,4,9,1,3,8,7,8,2,3,8,6,4,
+ 4,6,7,6,5,2,3,8,4,4)
> coffee<-ts(coffee,start=c(1,2),frequency=5)
> Mon<-1*(date=="Mon")
> event<-data.frame(Mon)
> PrintAIC(coffee,order=c(2,2),xreg=event,type="ARMAX")
$Models
ARMAX models AIC values Sort by AIC
Model 1 ARMAX(0,1) ...AIC = 153.47 .......... 3
Model 2 ARMAX(0,2) ...AIC = 152.25 .......... 2
Model 3 ARMAX(1,0) ...AIC = 153.48 .......... 4
Model 4 ARMAX(1,1) ...AIC = 154.12 .......... 6
Model 5 ARMAX(1,2) ...AIC = 154.21 .......... 7
Model 6 ARMAX(2,0) ...AIC = 152 .......... 1
Model 7 ARMAX(2,1) ...AIC = 153.82 .......... 5
Model 8 ARMAX(2,2) ...AIC = 155.82 .......... 8
$Best
The best ARMAX model
ARMAX(2,0) ...AIC = 152
>
>
>
>
>
> dev.off()
null device
1
>