如何解决Stan:多元模型的初始化问题
已发布here。
嗨, 我第一次尝试使用多元模型。 我阅读了manual。 我按照它做了两个模型(有和没有“通过 Cholesky 分解优化”)。 在这两种情况下,都存在初始化问题。我将复制每个模型下方的错误消息。 观测值 (y) 是整数,可以是正数、负数或零。
- 没有 Cholesky 分解
data {
int<lower=0> N; // num individuals (observations)
int<lower=1> K; // num ind predictors (= nb of species)
int<lower=1> J; // num groups (= nb of species)
int<lower=1> L; // num group predictors (1?)
int<lower=1,upper=J> jj[N]; // group for individual (species)
matrix[N,K] x; // individual predictors (all abundances at time t)
row_vector[L] u[J]; // group predictors (1 everywhere)
vector[N] y; // outcomes (abundance of focal species at time t)
}
parameters {
corr_matrix[K] Omega; // prior correlation
vector<lower=0>[K] tau; // prior scale
matrix[L,K] gamma; // group coeffs
vector[K] beta[J]; // indiv coeffs by group
real<lower=0> sigma; // prediction error scale
}
model {
tau ~ cauchy(0,2.5);
Omega ~ lkj_corr(2);
to_vector(gamma) ~ normal(0,5);
{
row_vector[K] u_gamma[J];
for (j in 1:J)
u_gamma[j] = u[j] * gamma;
beta ~ multi_normal(u_gamma,quad_form_diag(Omega,tau));
}
{
vector[N] x_beta_jj;
for (n in 1:N)
x_beta_jj[n] = x[n] * beta[jj[n]];
y ~ normal(x_beta_jj,sigma);
}
}
错误:
重复消息:
Chain 1: Exception: lkj_corr_lpdf: Shape parameter is 0,but must be > 0! (in 'model1d032109b2a5f_Model' at line 20)
最后一条消息:
Chain 1:
Chain 1: Initialization between (-2,2) Failed after 100 attempts.
Chain 1: Try specifying initial values,reducing ranges of constrained values,or reparameterizing the model.
[1] "Error in sampler$call_sampler(args_list[[i]]) : Initialization Failed."
error occurred during calling the sampler; sampling not done
- 使用 Cholesky 分解
data {
int<lower=0> N; // num individuals (observations)
int<lower=1> K; // num ind predictors (= nb of species)
int<lower=1> J; // num groups (= nb of species)
int<lower=1> L; // num group predictors (1?)
int<lower=1,K] x; // individual predictors (all abundances at time t)
matrix[L,J] u; // group predictors (1 everywhere)
vector[N] y; // outcomes (abundance of focal species at time t)
}
parameters {
matrix[K,J] z;
cholesky_factor_corr[K] L_Omega;
vector<lower=0,upper=pi()/2>[K] tau_unif; // prior scale
matrix[K,L] gamma; // group coeffs
real<lower=0> sigma; // prediction error scale
}
transformed parameters {
vector<lower=0>[K] tau = 2.5 * tan(tau_unif);
matrix[K,J] beta = gamma * u + diag_pre_multiply(tau,L_Omega) * z;
}
model {
vector[N] mu;
for(n in 1:N) {
mu[n] = x[n,] * beta[,jj[n]];
}
to_vector(z) ~ std_normal();
L_Omega ~ lkj_corr_cholesky(2);
to_vector(gamma) ~ normal(0,5);
y ~ normal(mu,sigma);
}
重复消息:
Chain 1: Rejecting initial value:
Chain 1: Log probability evaluates to log(0),i.e. negative infinity.
Chain 1: Stan can't start sampling from this initial value.
最后的消息:
Chain 1:
Chain 1: Initialization between (-2,or reparameterizing the model.
[1] "Error in sampler$call_sampler(args_list[[i]]) : Initialization Failed."
error occurred during calling the sampler; sampling not done
我不知道该怎么做,因为我不懂数学……如果你们中有人有想法,我很乐意尝试!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。