Hi @Bob_Carpenter,
Happy new year! Thank you so much for your reply and my apologies for the late response.
In my problem, the function f is implied by some economic theory and is a complicated non-linear function of both parameters \theta and a K by 1 unobservable e_i. The K by 1 vector Y_i is observed:
Y_i=f(e_i; \theta),
where e_i follows a known distribution such as independent standard normal.
We only know the following about the function f:
- It is invertible for each \theta, i.e. f^{-1}(Y_i; \theta) exists.
- There is no closed form for f^{-1}(Y_i; \theta).
The statistical goal is to learn about the posterior distribution of the parameter \theta given some prior. (I need to impose the functional relationship above when learning about \theta, so I cannot directly specify a distribution over Y_i.)
By change of variable, the density for the observed Y_i is
p(Y_i; \theta)=p_e\left(f^{-1}(Y_i; \theta)\right) \bigg|det \left( \frac{d f^{-1}(Y_i;\theta)}{d Y_i}\right) \bigg|,
where p_e is the density of e_i (e.g. the independent standard normal density). The data consists of n iid observations \{Y_1,...,Y_n\}. Given the prior density \pi(\theta), the posterior density is proportional to
\pi(\theta) \cdot \prod_{i=1}^n p(Y_i;\theta),
where the second term is the likelihood function. The prior is standard e.g. normal.
Evaluating the likelihood involves, for a given \theta, (1) computing the inverse f^{-1}(Y_i; \theta) and (2) computing the Jacobian term \bigg|det \left( \frac{d f^{-1}(Y_i;\theta)}{d Y_i}\right) \bigg|.
Q: It seems that we would have to manually code the likelihood function in Stan, including coding a function that would numerically invert f (perhaps, using Algebraic Equation Solver) and a function that would compute the Jacobian term using the inverse function theorem. Before trying to do that we wanted to check if there is an easier/automatic way to handle this type of model in Stan. Also, do you think this estimation problem could be feasible at all in STAN?
Thank you for your help!