Dear all, I am just started to use Stan and I am confusing whether we have to enter log of PDF function or the sum of the log of the PDF function in the functions block using the real _lpdf()
signature. I have found that some authors have entered _lpdf
with sum function in the functions block.(Extreme value analysis and user defined probability functions in Stan). I have shared my stan code below please suggest to me whether my code is correct or not.
functions{
real OLGE_lpdf(real y, real a, real b, real delta, real theta){
real z;
real w;
z = (1 - exp(-b*y))^a;
w = (log(a)+log(b)+ theta*log(delta)+log(theta)- b*(y) + (a-1)*(log1m(exp(-b*y)))-
2*log1m(z) - (theta+1)*log(delta + (z/(1-z)))); //this is my pdf just taking log
return w;
}
real OLGE_rng(real a, real b, real delta, real theta){
real u;
real v;
u = uniform_rng(0, 1);
v = (((1-u)*delta^(-theta))^(-1/theta) - delta);
return (-1/b)*log1m((v/(1+v))^(1/a));
}
}
data{
int N;
real y[N];
}
parameters{
real <lower=0> a;
real <lower=0> b;
real <lower=0> delta;
real <lower=0> theta;
}
model{
for(i in 1 : N){
y[i]~ OLGE(a, b, delta, theta);
}
a~ gamma(0.1, 0.1);
b~ gamma(0.01, 0.01);
delta~ gamma(0.2, 0.2);
theta~ gamma(0.1, 0.1);
}
generated quantities{
vector [N] yrep;
for(i in 1 : N){
yrep[i]= OLGE_rng(a, b, delta, theta);
}
}