Hello professor!
I really appreciate the help!
My reading of the priordens
function was that it returns the density of the prior. However, using the code you provided, I believe:
bounds = prior_bounds(bayestopt_, options_.prior_trunc);
[fval,info] = dsge_likelihood(xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
lik = fval
gives me the likelihood evaluated at each draw in the posterior_function
! Thank you so much.
Related: I would also like to be able to get the likelihood at each draw in a prior_function
. However, running the same code above in dynare 5.5
and Matlab R2023a
gives me the error:
EXECUTE_POSTERIOR_FUNCTION: Execution of prior/posterior function led to an error. Execution cancelled.
Unrecognized field name "kstate".
Error in stochastic_solvers (line 196)
kstate = dr.kstate;
Error in resol (line 119)
[dr,info] = stochastic_solvers(dr,check_flag,M,options,oo);
Error in compute_decision_rules (line 34)
[dr,info,M_,oo_] = resol(0,M_,options_,oo_);
Error in dynare_resolve (line 36)
[dr,info,M_,oo_] =compute_decision_rules(M_,options_,oo_);
Error in dsge_likelihood (line 216)
[T,R,SteadyState,info,Model,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults,'restrict');
Error in PC_slope_prior (line 61)
[fval,info,exit_flag,DLIK,Hess,SteadyState,trend_coeff,M_,options_,bayestopt_,oo_] = dsge_likelihood(xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
Error in execute_prior_posterior_function (line 90)
junk=functionhandle(parameter_mat(1,:),M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info);
Error in Smets_Wouters_2007_45.driver (line 624)
oo_ = execute_prior_posterior_function('PC_slope', M_, options_, oo_, estim_params_, bayestopt_, dataset_, dataset_info, 'prior');
Error in dynare (line 281)
evalin('base',[fname '.driver']);
Error in Smets_Wouters_2007 (line 2)
dynare Smets_Wouters_2007_45.mod
Do you know of a way to get the likelihood evaluated at the draw for a function passed into the prior_function
as well?