【发布时间】:2021-02-08 02:39:20
【问题描述】:
我使用下面的代码来估计一个分层的 logit 模型。
data {
int<lower=1> D; // number of covariates
int<lower=0> N; // number of observations
int<lower=1> L; // number of groups (levels)
int<lower=0,upper=1> y[N]; // binary response
int<lower=1,upper=L> ll[N]; // group ids
row_vector[D] x[N]; //covariates
}
parameters {
real mu[D];
real<lower=0> sigma[D];
vector[D] beta[L];
}
model {
mu ~ normal(0, 100); // prior for mu
// sigma ~ uniform(0, 100) ; // prior for sigma
for (l in 1:L) beta[l] ~ normal(mu, sigma);
{
vector[N] x_beta_ll;
for (n in 1:N) x_beta_ll[n] = x[n] * beta[ll[n]];
y ~ bernoulli_logit(x_beta_ll);
}
}
对于我的数据,N = 264,713(总观察数),L = 10,000(组数),D = 26(协变量数)。然后,我有这个消息,需要很长时间才能采样:
Chain 1: Gradient evaluation took 0.131 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 1310 seconds.
Chain 1: Adjust your expectations accordingly!
不知道有没有什么提高速度的好方法。顺便说一句,这是我使用的 R 代码:
fit <- stan(
file = "hierarchical_logit.stan", # Stan program
data = data, # named list of data
chains = 1, # number of Markov chains
warmup = 1000, # number of warmup iterations per chain
iter = 2000, # total number of iterations per chain
cores = 5, # number of cores (could use one per chain)
verbose = TRUE
)
我会感谢专家的提示。
谢谢。
【问题讨论】:
标签: performance hierarchical stan