Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When Y has class "mts" #2

Open
jacobbien opened this issue Apr 2, 2017 · 5 comments
Open

When Y has class "mts" #2

jacobbien opened this issue Apr 2, 2017 · 5 comments

Comments

@jacobbien
Copy link

The line

if(class(Y)!="matrix"){Y=matrix(Y,ncol=1)}

assumes that class(Y) has length 1. However, commonly we have

class(Y)
[1] "mts" "ts" "matrix"

and applying "as.matrix" as suggested in https://arxiv.org/pdf/1702.07094.pdf on page 10 doesn't convert this to have class "matrix" since this is an inherited class from "matrix"...

class(as.matrix(Y))
[1] "mts" "ts" "matrix"

So it leads to a warning when the above "if" statement is called, and worse -- it converts the multivariate ts into a (nrow(Y) * ncol(Y))-by-1 matrix.

@wbnicholson
Copy link
Owner

wbnicholson commented Apr 2, 2017

I changed the class(Y)!="matrix" calls to is.vector(Y). That should resolve this issue, let me know if it doesn't.

@Neil-Schneider
Copy link

Doesn't it make more sense to look for matrix in the class list?

if (!"matrix" %in% class(Y)) {
  ...
}

A time series object is not a vector and assume you would want to convert those to a matrix also.

tmp = ts(c(1,2,3,4,5))
is.vector(tmp)

@jacobbien
Copy link
Author

Yes, exactly. I agree that

!"matrix" %in% class(Y)

is better.

@wbnicholson
Copy link
Owner

I've updated all is.vector tests to !"matrix" %in% class(Y). These errors should be resolved.

@bdemeshev
Copy link

For me the following code still fails (I've tested both CRAN and github versions):

library(BigVAR)

data(Y)
y_st <- apply(Y, 2, FUN = scale)
y_st_ts <- ts(y_st, start = 1, frequency = 1)

model_spec <- constructModel(y_st_ts, p = 1, 
                             struct = "OwnOther", 
                             ownlambdas = TRUE,
                             gran = 10)
model_est <- BigVAR.est(model_spec)

Without ts() function everything seems fine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants