Probit regression with data augmentation in stan

天大地大妈咪最大 提交于 2019-12-05 01:00:43

问题


I am attempting to do a probit model with data augmentation using stan. This is where we have outcomes y either 0/1 that tell us the sign of the latent variable ystar. This is what I have so far, but I'm not sure how to add information in the model section about y. Any thoughts?

data {
  int<lower=0> N; // number of obs
  int<lower=0> K; // number of predictors
  int<lower=0,upper=1> y[N]; // outcomes
  matrix[N, K] x; // predictor variables
}
parameters {
  vector[K] beta; // beta coefficients
  vector[N] ystar; // latent variable
}
model {
  vector[N] mu; 
  beta ~ normal(0, 100);
  mu <- x*beta;
  ystar ~ normal(mu, 1);
}

回答1:


You could do data { int<lower=0> N; // number of obs int<lower=0> K; // number of predictors vector<lower=-1,upper=1> sign; // y = 0 -> -1, y = 1 -> 1 matrix[N, K] x; // predictor variables } parameters { vector[K] beta; // beta coefficients vector<lower=0>[N] abs_ystar; // latent variable } model { beta ~ normal(0, 100); // ignore the warning about a Jacobian from the parser sign .* abs_ystar ~ normal(x * beta, 1); }

That said, there is no reason to do data augmentation in Stan for a binary probit model, unless some of the outcomes were missing or something. It is more straightforward (and reduces the parameter space to K instead of K + N) to do data { int<lower=0> N; // number of obs int<lower=0> K; // number of predictors int<lower=0,upper=1> y[N]; // outcomes matrix[N, K] x; // predictor variables } parameters { vector[K] beta; // beta coefficients } model { vector[N] mu; beta ~ normal(0, 100); mu <- x*beta; for (n in 1:N) mu[n] <- Phi(mu[n]); y ~ bernoulli(mu); } If you really care about the latent utility, you could generate it via rejection sampling in the generated quantities block, like this generated quantities { vector[N] ystar; { vector[N] mu; mu <- x * beta; for (n in 1:N) { real draw; draw <- not_a_number(); if (sign[n] == 1) while(!(draw > 0)) draw <- normal_rng(mu[n], 1); else while(!(draw < 0)) draw <- normal_rng(mu[n], 1); ystar[n] <- draw; } } }



来源:https://stackoverflow.com/questions/31838491/probit-regression-with-data-augmentation-in-stan

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!