Dear Stan expert, I am trying to use Behrens volatility model in Stan, and it is always failed in the Initialization steps. Can someone check my code? Thank you very much.
The math detail of volatility model can be found in here:https://static-content.springer.com/esm/art%3A10.1038%2Fnn1954/MediaObjects/41593_2007_BFnn1954_MOESM7_ESM.pdf
page 5 and 6 formula 1 and 2
data {
int<lower=0> N; // trial number
int y[N];
}
parameters {
real k;
}
model {
real r[N]; //reward probability
real v[N]; //volatility
k~cauchy(0,3);
for(t in 1:N){
if(t == 1){
r[t] ~ uniform(0,1);
v[t] ~ uniform(0,1);
}
else{
v[t] ~ normal(v[t-1],exp(k));
r[t] ~ beta_proportion(r[t-1],exp(k));
}
y[t] ~ bernoulli_logit(r[t]);
}
}
And if I fit the model with some simulate data, there always some warning
o/AppData/Local/Temp/RtmpWqbkxV/model-8a54e281649.stan', line 27, column 6 to column 35)
Chain 2 Rejecting initial value:
Chain 2 Error evaluating the log probability at the initial value.
Chain 2 Exception: normal_lpdf: Random variable is nan, but must be not nan! (in 'C:/Users/lenovo/AppData/Local/Temp/RtmpWqbkxV/model-8a54e281649.stan', line 27, column 6 to column 35)
Chain 2 Exception: normal_lpdf: Random variable is nan, but must be not nan! (in 'C:/Users/lenovo/AppData/Local/Temp/RtmpWqbkxV/model-8a54e281649.stan', line 27, column 6 to column 35)
Chain 2 Rejecting initial value:
Chain 2 Error evaluating the log probability at the initial value.
Chain 2 Exception: normal_lpdf: Random variable is nan, but must be not nan! (in 'C:/Users/lenovo/AppData/Local/Temp/RtmpWqbkxV/model-8a54e281649.stan', line 27, column 6 to column 35)
Chain 2 Exception: normal_lpdf: Random variable is nan, but must be not nan! (in 'C:/Users/lenovo/AppData/Local/Temp/RtmpWqbkxV/model-8a54e281649.stan', line 27, column 6 to column 35)
Chain 2 Rejecting initial value:
Chain 2 Error evaluating the log probability at the initial value.
Chain 2 Exception: normal_lpdf: Random variable is nan, but must be not nan! (in 'C:/Users/lenovo/AppData/Local/Temp/RtmpWqbkxV/model-8a54e281649.stan', line 27, column 6 to column 35)
Chain 2 Exception: normal_lpdf: Random variable is nan, but must be not nan! (in 'C:/Users/lenovo/AppData/Local/Temp/RtmpWqbkxV/model-8a54e281649.stan', line 27, column 6 to column 35)
Chain 2 Rejecting initial value:
Chain 2 Error evaluating the log probability at the initial value.
Chain 2 Exception: normal_lpdf: Random variable is nan, but must be not nan! (in 'C:/Users/lenovo/AppData/Local/Temp/RtmpWqbkxV/model-8a54e281649.stan', line 27, column 6 to column 35)
Chain 2 Exception: normal_lpdf: Random variable is nan, but must be not nan! (in 'C:/Users/lenovo/AppData/Local/Temp/RtmpWqbkxV/model-8a54e281649.stan', line 27, column 6 to column 35)
Chain 2 Rejecting initial value:
Chain 2 Error evaluating the log probability at the initial value.
Chain 2 Exception: normal_lpdf: Random variable is nan, but must be not nan! (in 'C:/Users/lenovo/AppData/Local/Temp/RtmpWqbkxV/model-8a54e281649.stan', line 27, column 6 to column 35)
Chain 2 Exception: normal_lpdf: Random variable is nan, but must be not nan! (in 'C:/Users/lenovo/AppData/Local/Temp/RtmpWqbkxV/model-8a54e281649.stan', line 27, column 6 to column 35)
Chain 2 Rejecting initial value:
Chain 2 Error evaluating the log probability at the initial value.
Chain 2 Exception: normal_lpdf: Random variable is nan, but must be not nan! (in 'C:/Users/lenovo/AppData/Local/Temp/RtmpWqbkxV/model-8a54e281649.stan', line 27, column 6 to column 35)
Chain 2 Exception: normal_lpdf: Random variable is nan, but must be not nan! (in 'C:/Users/lenovo/AppData/Local/Temp/RtmpWqbkxV/model-8a54e281649.stan', line 27, column 6 to column 35)
Chain 2 Rejecting initial value:
Chain 2 Error evaluating the log probability at the initial value.
Chain 2 Exception: normal_lpdf: Random variable is nan, but must be not nan! (in 'C:/Users/lenovo/AppData/Local/Temp/RtmpWqbkxV/model-8a54e281649.stan', line 27, column 6 to column 35)
Chain 2 Exception: normal_lpdf: Random variable is nan, but must be not nan! (in 'C:/Users/lenovo/AppData/Local/Temp/RtmpWqbkxV/model-8a54e281649.stan', line 27, column 6 to column 35)
Chain 2 Initialization between (-2, 2) failed after 100 attempts.
Chain 2 Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
Chain 2 Initialization failed.
Warning: Chain 2 finished unexpectedly!
Warning: Use read_cmdstan_csv() to read the results of the failed chains.
Fitting failed. Unable to print.
= Warning messages:
1: All chains finished unexpectedly! Use the $output(chain_id) method for more information.
2: No chains finished successfully. Unable to retrieve the fit.