在 Stan 中,我收到以下错误:
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
require unconstrained variable declaration. found simplex.
ERROR at line 48
46: for (j in 1:records) {
47: real phenology_predictor;
48: simplex[7] pi;
^
我不太明白是什么问题。当我使用real pi[7]
而不是simplex[7] pi
,我得到了不同的错误:
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
no matches for function name="categorical_log"
arg 0 type=int
arg 1 type=real[1]
available function signatures for categorical_log:
0. categorical_log(int, vector) : real
1. categorical_log(int[1], vector) : real
unknown distribution=categorical
ERROR at line 63
62:
63: Y[j] ~ categorical(pi);
^
64:
我也不明白...我的整个代码:
data {
int sites;
int records;
int Y[records];
vector[records] yday;
int site[records];
}
transformed data {
int M[sites];
}
parameters {
real<lower=0,upper=1> psi;
real<lower=0,upper=1000> phi_phen_scale;
real phi_alpha;
real q_date;
real q_date2;
real q_site[sites];
}
model {
real p[records];
real q[records];
// priors
phi_phen_scale ~ normal(0, 10);
phi_alpha ~ normal(0, 10);
q_date ~ normal(0, 10);
q_date2 ~ normal(0, 10);
// vectorized
M ~ bernoulli(psi);
q_site ~ normal(0, 10);
for (j in 1:records) {
real phenology_predictor;
simplex[7] pi;
phenology_predictor <- q_date * yday[j] + q_date2 * yday[j]^2;
p[j] <- M[site[j]] * inv_logit(phi_alpha + phi_phen_scale * phenology_predictor);
q[j] <- inv_logit(q_site[site[j]] + phenology_predictor);
pi[1] <- 1-p[j] + p[j]*(1-q[j])^6;
pi[2] <- p[j]*q[j] ;
pi[3] <- p[j]*(1-q[j])*q[j];
pi[4] <- p[j]*(1-q[j])^2*q[j];
pi[5] <- p[j]*(1-q[j])^3*q[j];
pi[6] <- p[j]*(1-q[j])^4*q[j];
pi[7] <- p[j]*(1-q[j])^5*q[j];
Y[j] ~ categorical(pi);
}
}