Beta distribution as likelihood with different prior

Beta distribution as likelihood with different prior(uniform- truncated uniform- gamma,…)
but the normal beta not work with stan_model
I just needed to run library(simulations) to simulate ‘prep’
I try this
data{
int N;
real theta[N];
real<lower=0,upper=1> phi;
real<lower=0.1> lambda;
}
transformed parameters {
real<lower=0> alpha = lambda * phi;
real<lower=0> beta = lambda * (1 - phi);
}
model {
theta ~ beta(lambda * phi, lambda * (1 - phi));
}
and this second try
model {
real alpha = lambda * phi
real beta = lambda * (1 - phi);

for (n in 1:N)
theta[n] ~ beta(alpha, beta);
}
the third try
model {
phi ~ beta(1, 1); // uniform
lambda ~ pareto(0.1, 1.5);
for (n in 1:N)
theta[n] ~beta_1pdf(alpha, beta);
}
i get this message
Error in stanc(filename, allow_undefined = TRUE) :
failed to parse Stan model ‘4_file’ due to the above error.
In addition: Warning message:
In readLines(file, warn = TRUE) :
incomplete final line found on ‘4_file.stan’

rstan:::rstudio_stanc(“4_file.stan”)
PARSER FAILED TO PARSE INPUT COMPLETELY
STOPPED AT LINE 17:
}
Error in stanc(filename, allow_undefined = TRUE) :
failed to parse Stan model ‘4_file’ due to the above error.
In addition: Warning message:
In readLines(file, warn = TRUE) :
incomplete final line found on ‘4_file.stan’
I don’t know why it is not complete
also, if I add beta_1pdf for likelihood ,it is error (lambda, and phi are continuous in my data)
like this
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Probability function must end in _lpdf or _lpmf. Found distribution family = beta_1pdf with no corresponding probability function beta_1pdf_lpdf, beta_1pdf_lpmf, or beta_1pdf_log
addition I don’t find kummer distribution {one of Kummer’s functions (a confluent hypergeometric function)}

I’m not sure if there are two different errors, but the last block seems to be simply complaining that beta_1pdf doesn’t exist. I’m guessing you are looking for beta_lpdf, with “L” for log.

thank you for your guessing but I try all them beta_1pdf_1pdf , beta_1pdf_log and beta_1pdf_1mdf ,all this don’t work
theta[n] ~ beta_1pdf_log(alpha, beta);
result
Error in stanc(filename, allow_undefined = TRUE) :
failed to parse Stan model ‘4_file’ due to the above error.
they made red line under second parameter Beta and give to me the same your guessing

Hi Eman,

The issue is that you’re calling the distribution ‘1pdf’, when you need to call it ‘lpdf’. You’re using the number 1, when you need to use the letter l

1 Like

I appreciate you helping but the same
theta[n] ~ beta_lpdf_log(alpha, beta);
the same
Error in stanc(filename, allow_undefined = TRUE) :
failed to parse Stan model ‘4_file’ due to the above error.
the problem doesn’t solve

That’s because the _lpdf extensions are not meant to be used on right hand side of the ~ operator.

For example, you can either write:

for (n in 1:N)
theta[n] ~ beta(alpha, beta);
}

Or:

for (n in 1:N)
target += beta_lpdf(theta[n] | alpha, beta);
}

But you can’t use:

for (n in 1:N)
theta[n] ~ beta_lpdf(alpha, beta);
}

See this section of the Manual for more information: https://mc-stan.org/docs/2_24/reference-manual/sampling-statements-section.html

1 Like

it is work now
thank you so much

1 Like

No worries, welcome to Stan!

1 Like