Hello
Is there any way of seeing what my program evaluates the log posterior to for a given value of the parameters? (ideally with print out of intermediate values of target) I call program from rstan.
Thanks
Jonathan
Hello
Is there any way of seeing what my program evaluates the log posterior to for a given value of the parameters? (ideally with print out of intermediate values of target) I call program from rstan.
Thanks
Jonathan
RStan has log_prob
function that can evaluate the target at any point. Printing intermediate values is only possible with print()
statements in the model.
log_prob
takes input on the unconstrained parameters so you’d call it something like
u <- unconstrain_pars(fit, list(x=...,y=...))
lp <- log_prob(fit, u)
You need a stanfit object first. The fasted way to create one is
fit <- stan(file=..., data=..., algorithm="Fixed_param", iter=1, chains=1)
@Jonathan_Myles welcome to the Stan forums!
In addition to @nhuurre’s suggestions (print statements or rstan::log_prob()
) there’s one other option I can think of. You could define a function in the functions block that computes the target and then expose it to R and test it out for different parameter values using rstan::expose_stan_functions()
.
Thank you both very much for your help. I will try out both solutions (when I’ve got my around constrained/unconstrined parameters)
Jonathan
I think you only really need to worry about that if going the rstan::unconstrain_pars route. If you code up a function in Stan and then expose it to R you can input parameters how you regularly would.