'R noob: running a simple 7-variable CSV through a bvarsv model

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)


Solution 1:[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)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1