How to convert "standata" to "json"?

I am trying to run brms models in “cmdstanr” as,

custom_model = cmdstan_model("Code/custom_code.stan")
time0 = system.time(fit <- custom_model$sample(custom_standat,
                                             chains = 4,
                                             parallel_chains = 4,
                                             refresh = 1000))

The error is,

Error: No method asJSON S3 class: standata

How to convert standata to json?

Can you specify a bit more what is custom_standat and how do you construct it?

In general, data for cmdstanr is just a list.

fit <- custom_model$sample(list(N=5, y = c(0,1,2,3,4)),...

I have used “make_standata(Formula, Data)” in the brms library. It returns a list[N] (S3: standata).

I have unpacked the data from the “list[N] (S3: standata)” format and packed it again to a normal “list[N]” using for loops in R. The code runs fine.

1 Like

Yes, was just meaning to write that. For future reference, below code does the job.

library(brms)

standata <- make_standata(count ~ zAge + zBase * Trt + (1|patient), 
            data = epilepsy, family = poisson())

data <- list()
for (t in names(standata)) {
  data[[t]] <- standata[[t]]
}
4 Likes