0

My simple code is yielding: Error in dimnames<-.data.frame(*tmp*, value = list(n)) : invalid 'dimnames' given for data frame

Any help appreciated

library(bvarsv)
library(tidyverse)
library(janitor)
library(readxl)

set.seed(1)

test = read_excel("Desktop/test.csv")

bvar.sv.tvp(test, p = 2, tau = 40, nf = 10, pdrift = TRUE, nrep = 50000, 
            nburn = 5000, thinfac = 10, itprint = 10000, save.parameters = TRUE, 
            k_B = 4, k_A = 4, k_sig = 1, k_Q = 0.01, k_S = 0.1, k_W = 0.01, 
            pQ = NULL, pW = NULL, pS = NULL)
NoobNation
  • 21
  • 3

1 Answers1

1

Edit:

The documentation specifies:

Y - Matrix of data, where rows represent time and columns are different variables.Y must have at least two columns.

So when you read in your dataset, time will be a column at first, meaning you have to transform the dataframe that the time column will be your rownames. (Maybe you also want to use the lubridate package to parse your time column first).

tst <- read.csv("Desktop/tst.csv", TRUE, ",") 
# tst_df <- data.frame(tst) # Should not be necassary
rownames(tst_df) <- tst_df[,1]
tst_df[,1] <- NULL

bvar.sv.tvp(tst_df, ...)

You can also the usmacro dataset as an example to see how the input data of bvar.sv.tvp() should look like.

data(usmacro)
print(usmacro)

Original Post:

I don't know how your csv looks like. So it is hard to tell what the actual issue is. But you can try wrapping your data in "as.data.frame(test)" like this:

bvar.sv.tvp(as.data.frame(test), p = 2, tau = 40, nf = 10, pdrift = TRUE, nrep = 50000, 
        nburn = 5000, thinfac = 10, itprint = 10000, save.parameters = TRUE, 
        k_B = 4, k_A = 4, k_sig = 1, k_Q = 0.01, k_S = 0.1, k_W = 0.01, 
        pQ = NULL, pW = NULL, pS = NULL)
David
  • 116
  • 2
  • 10
  • Thank you for your response David! In short, my CSV is just one column of dates (with header) and seven columns of variables (starting with 1 dependent variable column). I've made some improvements and incorporated your suggestions, but now I get: Error in tcrossprod(x, y) : requires numeric/complex matrix/vector arguments. FYI, my updated script is now: library(bvarsv) library(tidyverse) library(janitor) library(readxl) set.seed(1) tst <- read.csv("Desktop/tst.csv", TRUE, ",") bvar.sv.tvp(tst, ... etc.) – NoobNation Mar 16 '22 at 00:51
  • 1
    Ok according to bvarsv documentation the time variable must be your rownames not your first column! So basically you need to transform your dataset to fit that. I updated the answer please take a look and see if that helps. – David Mar 16 '22 at 02:39
  • Thank you David! As an FYI, a friend has helped to reformat that date and introduce the xts package, which seems to have resolved most of the issues – NoobNation Mar 17 '22 at 22:41
  • 1
    You are welcome. Great to hear you resolved the issues. Happy Coding! – David Mar 18 '22 at 01:47