Say I'm using a model with both parameters and transformed parameters. How do I find the total number of parameters in each block separately in RStan? Using the model_pars or even things like the inits attribute, it couples the two sets of parameters so you can't distinguish the two.
get_stan_params <- function(object) {
stopifnot(is(object, "stanfit"))
params <- grep("context__.vals_r", fixed = TRUE, value = TRUE,
x = strsplit(get_cppcode(get_stanmodel(object)), "\n")[[1]])
params <- sapply(strsplit(params, "\""), FUN = function(x) x[[2]])
params <- intersect(params, object@model_pars)
return(params)
}
--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Cool, this is fine. So to get the number of pars, I would do something likemodel <- stan(file, data = data, iter = 1, chains = 1)pars <- get_stan_params(model)length(unlist(attributes(model)$inits[[1]][pars]))
sum(sapply(model@par_dims[pars], prod))