I'm trying to learn Stan via rstan (since I'm familiar with R). I've tried running a simple mixed Pareto and Normal model. It compiles fine (as far as I can tell), but it fails to sample, giving me the error:
"Initialization between (-2, 2) failed after 100 attempts. Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
error occurred during calling the sampler; sampling not done"
Suffice to say I've tried various ways to parameterize things, and tried setting initial values, but all to no avail.
My R+rstan code is below:
library(rstan)
rpareto = function(n, location, shape){location/runif(n)^(1/shape)}
sdvec=runif(1e3,0.1,1)
HMFtest=list(x=rpareto(1e3,10,2)+rnorm(1e3,0,sdvec), sdev=sdvec, N=1e3)
HMF.stan <- "
data {
int<lower=0> N;
real x[N];
real sdev[N];
}
parameters {
real<lower=0,upper=20> y_min;
real<lower=0,upper=4> alpha;
real xtrue[N];
}
model {
y_min ~ lognormal(1, 1);
alpha ~ lognormal(1, 1);
xtrue ~ pareto(y_min, alpha);
for(i in 1:N){
x[i] ~ normal(xtrue[i], sdev[i]);
}
}
"
stan.test <- stan(model_code=HMF.stan, data=HMFtest, pars=c('y_min','alpha'), chains=1, iter=30000, warmup=10000)
This example works fine with JAGS (hence I've tagged JAGS too) and I can post that code is it is helpful.
Incidentally, if I change the Pareto distribution to an additional normal distribution it runs fine (but gives me a nonsense answer, of course).
Any suggestions as to what I'm doing wrong would be much appreciated! I fear somehow I'm still thinking JAGS not Stan, but I couldn't find any examples of people fitting Pareto models with Stan, so it has been hard for me to cross validate my approach.