I'm trying to understand some functionalities of the MSwM package so I can use it in a paper I'm writing. There are two things I just don't get while reproducing the example provided by the authors.
The first one is related to the summary method used in the package: why the logLikel
is a positive number when I call mod.mswm@Fit@logLikel
and a negative number when I call summary(mod.mswm)
? Is it possible to get logLik (and not the logLikel), AIC and BIC directly from the summary object?
The second one has to do with the AIC and BIC information criteria. The documentation for the package says that for us to get those values we should use the AIC function, choosing the appropriate value for k to get AIC or BIC. So for AIC, k should be 2 and for BIC, I think it should be log(length(y))
, where y is my univariate time series. The problem is that when I do this procedure the values for AIC and BIC that I get are different from those that are in the summary
. Why is that? What am I missing??
This is the code I'm using:
library(MSwM)
data(example)
mod=lm(y~x,example)
mod.mswm=msmFit(mod,k=2,p=1,sw=c(T,T,T,T),control=list(parallel=F))
summary(mod.mswm)
The first lines of the result are:
Markov Switching Model
Call: msmFit(object = mod, k = 2, sw = c(T, T, T, T), p = 1, control = list(parallel = F))
AIC BIC logLik
637.0736 693.479 -312.5368
However, if I try to calculate AIC and BIC using a function or by hand I get different results:
#Akaike
AIC(mod.mswm,k=2) #using function. Result:641.0736
8*2-((-1)*2*mod.mswm@Fit@logLikel)#by hand. Result:641.0736
#Bayesian
AIC(mod.mswm,k=log(length(example$y))) #using function. Result: 670.7039
8*log(length(example$y))-((-1)*2*mod.mswm@Fit@logLikel) #by hand. Result: 670.7039
Thank you very much in advance!