I fitting some data with power law distribution (I included the density function below as populationpow_lpdf) and was really having difficulty pass the sampling stage. I have tried to feed the initial value directly, which also failed. I have also included the R code I use to generate data and fit the model below.

I am not sure if I am missing something obvious here so I would really appreciate if someone can point me a direction!

FitpowerlawStan.R (455 Bytes)

```
functions{
real populationpow_lpdf(vector Mus,real xmin, real alpha){
vector[num_elements(Mus)] prob;
real lprob;
for (i in 1:num_elements(Mus)){
prob[i] = ((alpha-1)/xmin)*(Mus[i]/xmin)^(-alpha);
}
lprob = sum(log(prob));
return lprob;
}
}
data{
int Ntotal;
vector[Ntotal] Mus;
real xmin;
}
parameters{
real <lower=1.5, upper=7> alpha;
}
model{
real c;
real d;
c = 1.5;
d = 7;
alpha ~ uniform(c,d);
Mus ~ populationpow(alpha, xmin);
}
```