如何使用STAN将多级模型拟合到大型数据集?

时间:2020-01-02 15:15:34

标签: r bayesian stan rstan hierarchical-bayesian

我正在使用stan(使用rstan)制作一个多层次的Logistic回归模型以适合大型数据集。我的数据集是2000 x 100100矩阵,其中包含2000个个体的基因组(SNP)中100100个位置的模拟测序数据。该模型的目标是估计每个SNP对0或1(健康或患病)的结果变量的影响。

我想估计100100个斜率,每个SNP一个。我已经在STAN中编写了以下模型,该模型能够拟合出2000乘以101的裁剪数据集,其中Rhat = 1且n_eff值非常高。

data{
  int<lower=1> N; // Rows
  int<lower=1> M; // Columns

  int<lower=0, upper=1> y[N]; // Outcome variable
  matrix[N, M] x; // Predictor variable
}

parameters{
  // Hyper priors
  real mu;
  real<lower=0> sigma;

  // Priors
  real a;
  vector[M] b;
}

model{
  // Hyper-priors
  mu ~ normal(0, 10);
  sigma ~ cauchy(0, 10);

  // Priors
  a ~ normal( 0 , 10 );
  b ~ normal(mu, sigma);

  // Likelihood
  y ~ bernoulli_logit(a + x * b);
}

当我尝试使用rstan函数sample()使模型适合大型数据集时,R没有响应。模型的编译工作正常。你知道我在做什么错吗?

R代码如下:

model <- stan_model("mult_predictor.stan")
fit <- sampling(model, list(N=2000, 
                            M=100100, 
                            y=y, 
                            x=x),
                iter=2000, chains=4)

0 个答案:

没有答案