I got an error like this:
SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1).
Chain 1: Rejecting initial value:
Chain 1: Error evaluating the log probability at the initial value.
Chain 1: Exception: von_mises_lpdf: Scale parameter is -1.49167e-154, but must be nonnegative! (in 'anon_model', line 59, column 4 to column 64)
but it seemed strage to me because those variables were already constrained to positive values in tha parameters{} block.
Here is the whole stan code (all comments are masked):
data{
int N_W; //*
int N_P; //*
int N_I; //*
int K_W; //*
int K_P; //*
int K_I; //*
//*
real<lower=-pi(),upper=pi()> Y_W[N_W]; //*
real<lower=-pi(),upper=pi()> Y_P[N_P]; //*
real<lower=-pi(),upper=pi()> Y_I[N_I]; //*
int<lower=1,upper=K_W+K_P+K_I> person_W[N_W];
int<lower=1,upper=K_W+K_P+K_I> person_P[N_P];
int<lower=1,upper=K_W+K_P+K_I> person_I[N_I];
}
parameters{
real<lower=-pi(),upper=pi()> mu_W0; //*
real<lower=-pi(),upper=pi()> mu_P0; //*
real<lower=-pi(),upper=pi()> mu_I0; //*
real<lower=-pi(),upper=pi()> mu_W[K_W];
real<lower=-pi(),upper=pi()> mu_P[K_P];
real<lower=-pi(),upper=pi()> mu_I[K_I];
real<lower=0> sig_mu; //*
real<lower=0> kappa_W0; //*
real<lower=0> kappa_P0; //*
real<lower=0> kappa_I0; //*
real<lower=0> kappa_W[K_W];
real<lower=0> kappa_P[K_P];
real<lower=0> kappa_I[K_I];
real<lower=0> sig_kappa; //*
//*
}
model{
//*
//*
//*
for(k in 1:K_W){
mu_W[k] ~ normal(mu_W0, sig_mu);
kappa_W[k] ~ normal(kappa_W0, sig_kappa);
}
for(k in 1:K_P){
mu_P[k] ~ normal(mu_P0, sig_mu);
kappa_P[k] ~ normal(kappa_P0, sig_kappa);
}
for(k in 1:K_I){
mu_I[k] ~ normal(mu_I0, sig_mu);
kappa_I[k] ~ normal(kappa_I0, sig_kappa);
}
//*
for(n in 1:N_W){
Y_W[n] ~ von_mises(mu_W[person_W[n]], kappa_W[person_W[n]]);
}
for(n in 1:N_P){
Y_P[n] ~ von_mises(mu_P[person_P[n]], kappa_P[person_P[n]]);
}
for(n in 1:N_I){
Y_I[n] ~ von_mises(mu_I[person_I[n]], kappa_I[person_I[n]]);
}
}
Then WHY did negative values sampled?
When simplified this to the following model, it worked (The above one considers differences between three groups, βWβ, βPβ, and βIβ, and the below one doesnβt).
So perhaps the multilevel modeling part is OK but something in other parts goes wrong.
data{
int N;
int K;
real<lower=-pi(),upper=pi()> Y[N];
int<lower=1,upper=K> person[N];
}
parameters{
real<lower=-pi(),upper=pi()> mu0;
real<lower=-pi(),upper=pi()> mu[K];
real<lower=0> sig_mu;
real<lower=0> kappa0;
real<lower=0> kappa[K];
real<lower=0> sig_kappa;
}
model{
for(k in 1:K){
mu[k] ~ normal(mu0, sig_mu);
kappa[k] ~ normal(kappa0, sig_kappa);
}
for(n in 1:N){
Y[n] ~ von_mises(mu[person[n]], kappa[person[n]]);
}
}
Iβm really new to RStan, so I may have missed some very simple issue.