I have a model which requires input data row_vector[K] x[T]. There is one such row_vector[,] per data sample, and there are N data samples. So, basically I have an array[N} of array[T] of array[K]. How do I feed this using a data.R file? is it
list(list(list( , , , ,))) or
c(c(c( , , , ,)
or something else?
array(, dims = c(N, T, K))
I am not asking about declaration, but how to feed the data in a file like model.data.R. With lines like
x <- …
how do I fill in the right side, replacing the …
By naming such an array in a call to rstan::stan_rdump
, which ultimately calls
if (is.matrix(vv) || is.array(vv)) {
l2 <- c(l2, v)
vvdim <- dim(vv)
cat(v, " <- \\n", file = file, sep = "")
if (length(vv) == 0) {
str <- paste0("structure(integer(0), ")
}
else {
str <- paste0("structure(c(", paste(as.vector(vv),
collapse = ", "), "),")
}
str <- gsub(addnlpat, "\\\\1\\n", str)
cat(str, ".Dim = c(", paste(vvdim, collapse = ", "),
"))\\n", file = file, sep = "")
next
}
I think I was being too brief. I am following the method shown in Bernoulli example, where you enter the command
examples/bernoulli/bernoulli sample data file=examples/bernoulli/bernoulli.data.R
and the bernoulli.data.R content is
N <- 10
y <- c(0,1,0,0,0,0,0,0,0,1)
Can I use the same approach by defining x <- in an data.R file?
You could, but it is easier to use rstan::stan_rdump
.
I read the stan_rdump manual. It is expecting an R object as input and will dump out the content to a file. I don’t have an R object to start with, so I am jumping thru more hoops.
Maybe if you tell me this. What is an R object that is equivalent to row_vector[K] x[T], I will create such R object, do a dump, and see what I get.
I think its dim
T <- 60
K <- 5
b <- array(1:300, dim = c(T, K))
it works up to here. then
stan_rdump(b, file="") gets
Error in FUN(X[[i]], …) : invalid first argument
stan_rdump("b", file = "")
yeah, I just got that too. Thanks.