Hello, Pioneers of STAN!
I’m STAN rookie.
I posted about “closed-form equation” to this forum some days ago.
As I was taught that “you should use algebra_solver
function” in this post, I rewrote my STAN code.
As my model is complicated, I tried simple model like this.
This model is supposed Gamma distribution with parameters (α, β).
As you know, mean of this distribution is α/β, so I re-parametrizationed from (α, β) to (μ, β).
And then, I introduced prior distribution of μ and β.
We succeeded if we simply executed α = μβ.
However, since I want to use algebra_solver
, it looks like the following code.
functions{
//solve function
vector algebra_system(vector y,//y menas alpha
vector theta,//theta means mu and beta
real[] x_r,
int[] x_i){
vector[1] result;
result[1] = y[1]-theta[1]*theta[2];
return result;
}
}
data{
int n;
real Data[n];
}
transformed data{
vector[1] y_guess;
y_guess[1] = 1.0;
real x_r[0];
int x_i[0];
}
parameters{
real mu;
real beta;
}
transformed parameters{
vector[2] theta;
theta[1] = mu;
theta[2] = vector;
real alpha = algebra_solver(algebra_system, y_guess, theta, x_r, x_i);
//In fact alpha=mu*beta is enough, and in the case, compile succeeded.
}
model{
for(i in 1:n) {
Data[i] ~ gamma(alpha, beta);
}
mu ~ uniform(0, 1);
beta ~ uniform(0, 4);
}
And I got the following error.
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
variable "real" does not exist.
error in 'model_tutorial2' at line 22, column 7
-------------------------------------------------
20: y_guess[1] = 1.0;
21:
22: real x_r[0];
^
23: int x_i[0];
-------------------------------------------------
Error in stanc(model_code = paste(program, collapse = "\n"), model_name = model_cppname, :
failed to parse Stan model 'tutorial2' due to the above error.
I can’t understand the meaning of this, variable "real" does not exist.
Would you tell me something solution?
In addition, I would like you to forgive my poor English.
Thank you.