Closed goldingn closed 6 years ago
This function will do the bulk of the work:
# given a vector of dimensions, return a vector of strings giving the row,
# column, etc. indices for each element, columnwise, in the format "[i,j]"
get_indices_text <- function (dims, name = "") {
vec <- seq_len(prod(dims))
indices <- arrayInd(vec, dims)
mid_text <- apply(indices, 1, paste, collapse = ",")
paste0(name, "[", mid_text, "]")
}
a <- greta:::ones(2, 3)
get_indices_text(dim(a), "a")
[1] "a[1,1]" "a[2,1]" "a[1,2]" "a[2,2]" "a[1,3]" "a[2,3]"
Done on the dev branch
When MCMC sampling greta arrays with 2+ dimensions, the columns names in the coda::mcmc objects returned are a bit cryptic; it's not clear to which element of the array they belong. For example:
greta returns the elements columnwise (like you usually get in R by coercing to a vector), though that isn't clear to users.
In JAGS, the coda mcmc output has the same format, but the column names are more informative:
greta should add useful column names like these