The error says that you need to include a target += statement with the log absolute determinant of the Jacobian of the transform.
Thus I used the target formulation, and in my case, the error vanished.
As an example ( which is from the code ?rstan
),
use the former code rather than lator codes.
I tried to make a reproducible example to show the efficacy of the target formulation but I cannot.
target formulation
stanmodelcode <- "
data {
int<lower=0> N;
real y[N];
}
parameters {
real mu;
}
model {
target += normal_lpdf(mu | 0, 10);
target += normal_lpdf(y | mu, 1);
}
Non-target formulation
stanmodelcode <- "
data {
int<lower=0> N;
real y[N];
}
parameters {
real mu;
}
model {
mu ~ normal(0, 10);
y ~ normal(mu, 1);
}
To tell the truth, I do not understand the statement with the log absolute determinant of the Jacobian of the transform.
I do not use the Jacobian, thus I am not sure that this treatment is correct.
I am a very beginner, so you need to ask someone to get an obvious answer.
I guess the warning means the follwoig
Let f(y|\theta) be a likelihood for data y and model parameter \theta.
Let \theta' = \varphi(\theta) be a non-linear parameter transformation.
Then for any function \psi(y,\theta),
\int \psi(y,\theta')f(y,\theta')dy d\theta' =\int \psi(y, \varphi(\theta))f(y, \varphi(\theta))
|\det (\frac{\partial \varphi(\theta)}{\partial \theta} )|dy d\theta.
Thus, we obtain
f(y,\theta') is written by f(y, \varphi(\theta))
|\det (\frac{\partial \varphi(\theta)}{\partial \theta} )|,
from which,
\log f(y,\theta') is written by \log f(y, \varphi(\theta)) +
\log |\det (\frac{\partial \varphi(\theta)}{\partial \theta} )|.
In HMC calculation, Stan codes with Non-target transformations drop the constant term in the likelihood function. To include the canstant term for precise calculation of likelihood, we use target formulations. Furthermore , Stan cannot calculate the Jacobian, namely \log |\det (\frac{\partial \varphi(\theta)}{\partial \theta} )|. Thus we have to calculate it by hands and add it in the mode block. This is my guess, but I am not sure that it is correct. But I am not sure why the worning restrict the case in non-linear. Can Stan calculates the Jacobian in case of linear transformation?
I’m embarrassing because my English in the previous posts was crazy :’-D