-2

Has anyone tried running Markov Switching Model with 'MSwM' and setting more than 2 regimes? With three it does not seem to work

Data (r_t)

[1]  0.0000000000 -0.0101170400 -0.0016032060 -0.0071256520  0.0007075710 -0.0021212120  0.0021257210 -0.0013131310 -0.0003034290 -0.0014164310  0.0026342450  0.0014147130
[13]  0.0039354190 -0.0019097400 -0.0018126890 -0.0015133170 -0.0059614020 -0.0055905670  0.0049064700 -0.0009663310  0.0000509087 -0.0146609650  0.0007232900 -0.0010325250
[25]  0.0043410850 -0.0027271790  0.0031474120  0.0004114800 -0.0002056560 -0.0016455830  0.0044297930 -0.0138461540  0.0017680710  0.0021802330 -0.0063203150 -0.0039605960
[37] -0.0036633870 -0.0042021220  0.0033231350 -0.0078334470 -0.0027554050 -0.0010626990 -0.0079787230 -0.0007506700 -0.0004561060  0.0008857870 -0.0026818280 -0.0034419710
[49]  0.0012951970 -0.0012935220 -0.0024284940 -0.0154179060  0.0032967030  0.0029572840  0.0160532930  0.0049441100  0.0033689840 -0.0026115230  0.0023511810  0.0021324230
[61] -0.0034046180  0.0002135160  0.0001601020  0.0020809990 -0.0115015970 -0.0068950660  0.0070514210 -0.0066788750 -0.0012471530  0.0017916280 -0.0028181230  0.0039130430
[73]  0.0015158080  0.0000000000  0.0023243240 -0.0023189340  0.0019459460 -0.0002157960 -0.0014569390 -0.0056741420  0.0054347830 -0.0054054050  0.0010869570  0.0014115090
[85]  0.0018432180 -0.0064935060  0.0032679740  0.0043431050 -0.0008648650 -0.0011902190  0.0021666130 -0.0055129180  0.0000000000  0.0000000000 -0.0367391300 -0.0230196340
[97] -0.0600600600  0.0788891620  0.0127562640 -0.0008996850

Code

model=glm(r_t ~ 1)
mod = msmFit(model, k = 3, p = 1, sw = rep(TRUE, 3))

Error message

Error in std[i] = summary(mod1)$sigma : replacement has length zero
Community
  • 1
  • 1
Lodyk Vovchak
  • 133
  • 2
  • 12

1 Answers1

0

This has nothing to do with the number of states. msmFit(model, k = 2, p = 1, sw = rep(TRUE, 3)) does not work either.

The problem here is that the wrong method for msmFit is used. Instead of the method for glm, the method for lm objects is used because class(model) is c("glm", "lm").

The easiest way to fix your problem is to use lm instead of glm.

Alternatively, if you prefer the glm method, you can explicitly call it:

msmFit.glm <- selectMethod(msmFit, c("glm","numeric","logical","ANY","missing","ANY"))
mod = msmFit.glm(model, k = 3, p = 1, sw = rep(TRUE, 2))

NOTE that the glm and the lm methods are very different! See ?"MSM.lm-class" and ?"MSM.glm-class" for more details.

shadow
  • 21,823
  • 4
  • 63
  • 77
  • Thanks, it works for this input. In fact it is only first 100 observations of my real data. And trying to do the same thing for whole data using `lm` doesn't help. Error `Error in solve.default(res$Hessian) : Lapack routine dgesv: system is exactly singular: U[7,7] = 0`. It seems there is uninvertable matrix somewhere, but isn't there some option for MSwM fixing it. – Lodyk Vovchak May 19 '15 at 15:21