我正在尝试使用 RSTAN 拟合随机效应模型。我的设计矩阵有 198 列。它是如此之宽,因为我的原始数据框是一堆因子变量,我将其转换为二进制指标以尝试在 STAN 中拟合模型。我可以使用从一个或两个预测变量转换而来的几列来拟合模型,但完成 1/2 的采样需要 10 个小时。
这是我用来尝试拟合模型的 STAN 代码(基本线性模型)。我试过矢量化,但也许有办法进一步优化?另外,为什么要花这么长时间的直觉是什么?
data {
int<lower=0> N;
int<lower=0> J;
int<lower=0> K;
int<lower=1,upper=J> geo[N];
matrix[N,K] X;
vector[N] y;
}
parameters {
vector[J] a;
vector[K] B;
real mu_a;
real<lower=0,upper=100> sigma_a;
real<lower=0,upper=100> sigma_y;
}
model {
vector[N] y_hat;
for (i in 1:N)
y_hat[i] <- a[geo[i]];
mu_a ~ normal(0, 1);
a ~ normal(0, 1);
y ~ normal(mu_a + sigma_a * y_hat + X * B, sigma_y);
}