Exception: mismatch in number dimensions declared

I am thinking this my question is related to an earlier bug here. If so, I am just looking for some kind of work around.

I am getting the following error:

Error in new_CppObject_xp(fields$.module, fields$.pointer, …) :
Exception: mismatch in number dimensions declared and found in context; processing stage=data initialization; variable name=Y; dims declared=(92); dims found=(92,1) (in ‘model4234235eadc_model’ at line 16)

The stan code is on my github here. A csv of the data is here

Also, below is the R code I use to prepare the data for Stan,

clean_data <- read_csv("clean_data.csv")
media_data <- clean_data %>% select(contains("m_"))
# data Prep
N <- nrow(clean_data)
Y <- clean_data[,"sales"] %>% as.vector()
max_lag <- 13
num_media <- 3
lag_vec <- seq(0, max_lag - 1)
X_media <- array(data = media_data, dim = 3)
num_ctrl <- 1
X_ctrl <- clean_data %>% select(price) %>% as.matrix()

stan_data <- list(N=N, Y=Y, max_lag=max_lag, num_media=num_media,
                  lag_vec=lag_vec,X_media=X_media,
                  num_ctrl=num_ctrl,X_ctrl=X_ctrl)

I think you can just do Y <- clean_data$sales. Then look at dims(Y), which should be 92 only.

1 Like

Thanks! That fixed it!

Now I am getting an error

variable name=X_media; dims declared=(92,3,13); dims found=(92,3)

I don’t usually work with 3D arrays so I am not sure how people normally create them.

It would be X_media <- array(data = media_data, dim = c(92, 3, 13)) but I am not sure where the 13 comes from.

1 Like

Thanks, that code is useful. I know that 13 is max_lag, but I am not sure how to combine it here. I will look into it more.