0

I'm using the package fMarkovSwitching in R to do what I was trying to do here: Fitting Markov Switching Models to data in R.

However, I get another weird error message. I'm trying to replicate the example at page 12 (using my time series of log returns) of this paper: http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1714016

Here is the code I'm using:

library(tseries)

#Prices
ftse <- get.hist.quote(instrument="^FTSE", start="1984-01-03", end="2014-01-01", quote="AdjClose", compression="m")

#Log-returns
ftse.ret <- diff(log(ftse))
ftse.ret1 <- as.numeric(ftse.ret)

library(fMarkovSwitching)

dep <- ftse.ret1

constVec <- matrix(1,nrow=length(dep),ncol=1)

indep <- constVec

k <- 2

S <- c(1,1)

myModel<-MS_Regress_Fit(dep=dep,indep=indep,S=S,k=k,distIn = "Normal")

The error message I get is the following:

Error in MS_Regress_Fit(dep = dep, indep = indep, S = S, k = k, distIn = "Normal") : The number of columns at indep should match the number of columns at S

The code I wrote is just a "translation" of the MATLAB example in the paper. If I modify S to have a match for the number of columns I still get the same error message, whereas if I modify indep the output I get is wrong.

Edit: The package can be installed in R using the following command: install.packages("fMarkovSwitching", repos="http://R-Forge.R-project.org")

Community
  • 1
  • 1
Egodym
  • 453
  • 1
  • 8
  • 23
  • 1
    As you defined it, "S" is not a matrix, it is a vector. You need something like `S <- matrix(1, 1, 1)`. Off course, you have to check whether a 1x1 matrix make sense, as well as the accuracy of the result. –  May 18 '15 at 05:43
  • Defining `S` as you suggest (or simply assigning to it the value 1) the function seems to work properly. – Egodym May 18 '15 at 06:13
  • 1
    I wasn't sure whether the function needs a `numeric` (dimension NULL) or a `matrix` (dimension 1 1). –  May 18 '15 at 07:17

0 Answers0