1

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@logLikeland 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!

Fer
  • 11
  • 4

1 Answers1

1

I encounterd the same problem. I cannot explain, why the developers choose a slightly different formula, but I can show you, which one was used.

# Extracted from package ---------------------------------------------------
object <- mod.mswm
(swi   <- object@switch[-length(object@switch)])
(np    <- object["k"]*sum(swi)+sum(!swi))

(AIC=2*object["Fit"]["logLikel"]+2*np)
#[1] 637.0736
(BIC=2*object["Fit"]["logLikel"]+2*np*log(nrow(object@model$model)))
#[1] 693.479

I found this snippet in their source code on the internet. As you can see the results is the same.

So I extracted the following formula:

'#':= Number of ...

AIC = 2 * LogLikelihood + 2 * ( #parameters incl. constant ) * ( #regimes )

BIC = 2 * LogLikelihood + 2 * ( #parameters incl. constant ) * ( #regimes ) * ln( #observations )

With best regards.

Alexander
  • 11
  • 1