Suppose \beta \sim (1-\pi)N(0,1) + \pi \delta_{0}(\beta), where \delta_{0}(\beta) denotes a point mass at 0, equally, p(\beta = 0) = 1.

My problem is , how can I write this model into stan?

I can use target function to achieve this, my code is as following,

```
data{
int<lower=0> N; // number of obs
int<lower=0> p; // number of predictors
int<lower=0> K;
int<lower=0,upper=1> y[N,K];
matrix[N, p] X; // predictor variables
real<lower=0> a[p];
real<lower=0> b[p];
real<lower=3> d;
cov_matrix[K] Q;
real<lower=0> api;
real<lower=0> bpi;
}
parameters{
// vector[p] beta[K];
matrix[K,p] beta;
// vector<lower=0>[p] tau;
real<lower=0> tau[p];
real<lower=0> lambda[p];
cov_matrix[K] Sigma;
real<lower=0,upper=1> pi;
}
transformed parameters{
vector[N] mu[K];
for(k in 1:K){
mu[k] = X*beta[k,]';
mu[k] = Phi(mu[k]);
}
}
model{
for(k in 1:K){
target += bernoulli_lpmf(y[,k] | mu[k]);
}
for(j in 1:p){
target += gamma_lpdf(tau[j] | (K+1)/2 , lambda[j]/2);
target += gamma_lpdf(lambda[j] | a[j],b[j]);
}
for(j in 1:p){
target += log_mix(1-pi , multi_normal_lpdf(beta[,j] | rep_vector(0,K) , tau[j]*Sigma ) , 0);
}
target += beta_lpdf(pi | api,bpi);
target += inv_wishart_lpdf(Sigma | d , Q);
}
```

particularly, I achieve mixture model part by

```
for(j in 1:p){
target += log_mix(1-pi , multi_normal_lpdf(beta[,j] | rep_vector(0,K) , tau[j]*Sigma ) , 0);
}
```

where log\_mix(\theta,\lambda_{1},\lambda_{2}) = log(\theta*exp(\lambda_{1}) + (1-\theta)*exp(\lambda_{2})).

Now my problem is, since \beta is a parameter generate directly by stan, I can’t restrict it equally to zero.

I’m new in stan and I can’t get through it, can anybody help me ?

Thank you!!