#First example: fit exact MLE to AR(4)
set.seed(3323)
phi<-c(2.7607,-3.8106,2.6535,-0.9238)
z<-SimulateGaussianAR(phi,1000)
ans<-FitAR(z,4,MeanMLEQ=TRUE)
ans
coef(ans)
## Not run: #save time building package!
# #Second example: compare with sample mean result
# ans<-FitAR(z,4)
# coef(ans)
#
# #Third example: fit subset ARz and ARp models
# z<-log(lynx)
# FitAR(z, c(1,2,4,7,10,11))
# #now obtain exact MLE for Mean as well
# FitAR(z, c(1,2,4,7,10,11), MeanMLE=TRUE)
# #subset ARp using exact MLE
# FitAR(z, c(1,2,4,7,10,11), ARModel="ARp", MLEQ=TRUE)
# #subset ARp using LS
# FitAR(z, c(1,2,4,7,10,11), ARModel="ARp", MLEQ=FALSE)
# #or
# FitAR(z, c(1,2,4,7,10,11), ARModel="ARp")
#
#
# #Fourth example: use UBIC model selection to fit subset models
# z<-log(lynx)
# #ARz case
# p<-SelectModel(z,ARModel="ARz")[[1]]$p
# ans1<-FitAR(z, p)
# ans1
# ans1$ARModel
#
# #ARp case
# p<-SelectModel(z,ARModel="ARp")[[1]]$p
# ans2<-FitAR(z, p, ARModel="ARp")
# ans2
# ans2$ARModel
#
# #Fifth example: fit a full AR(p) using AIC/BIC methods
# z<-log(lynx)
# #BIC
# p<-SelectModel(z,ARModel="AR")[1,1]
# ans1<-FitAR(z, p)
# ans1
# #AIC
# p<-SelectModel(z, ARModel="AR", Criterion="AIC")[1,1]
# ans2<-FitAR(z, p)
# ans2
# ## End(Not run)
#Sixth Example: Subset autoregression depends on lag.max!
#Because least-squares is used, P=lag.max observations are
# are deleted. This causes different results depending on lag.max.
#This phenomenon does not happen with "ARz" subset models
#ARp models depend on lag.max
SelectModel(z,lag.max=15,ARModel="ARp", Criterion="BIC", Best=1)
SelectModel(z,lag.max=20,ARModel="ARp", Criterion="BIC", Best=1)
#ARz models do NOT depend in this way on lag.max.
#Obviously if some lags beyond the initial value of lag.max are
# found to be important, then there is a dependence but this
# is not a problem!
SelectModel(z,lag.max=15,ARModel="ARz", Criterion="BIC", Best=1)
SelectModel(z,lag.max=20,ARModel="ARz", Criterion="BIC", Best=1)
Run the code above in your browser using DataLab