I have a cell-mean model where I am trying to put a Dirichlet prior on the design matrix.

I am really struggling to implement this in RStan and would really appreciate some help.

I am struggling to just get a basic inflexible implementation to work.

Here is my current model without the Dirichlet with the desired model (hard coded/inflexible) for the example data provided below (commented out due to invalid syntax):

```
data {
int<lower=0> N; // number of data items
int<lower=0> K; // number of means
matrix[N,K] x; // design matrix
vector[N] y; // outcome vector
}
parameters {
vector[K] mu; // coefficients for predictors
real<lower=0> sigma; // error scale
real eta[K]; // Error in mean
//simplex[5] x_w1; // Weights in mean estimation
//simplex[5] x_w2; // Weights in mean estimation
}
//transformed parameters{
// matrix[N,K] x_w;
// x_w[1:5,1] = x_w1; x_w[6:10,1] = 0;
// x_w[1:5,2] = 0; x_w[6:10,1] = x_w2;
//} Should have been set according to x
model {
// x_w1 ~ dirichlet(1/2); Uniformative priors for simplicty
// x_w2 ~ dirichlet(1/2);
//
y ~ normal(x * mu, sigma); //Should have been x_w instead of x
sigma ~ gamma(1, 1);
for (i in 1:K){
mu ~ normal(sigma*eta[i], sigma);
}
eta ~ normal(0, 1);
}
```

Simulated data:

```
# Simulate data in R
set.seed(1)
y <- rnorm(10)
y[6:10] <- y[6:10] + rnorm(5,1, seq(.5, 1.5, length.out = 5))
x <- model.matrix(~0+factor(rep(c(1,2), each = 5)))
dat <- list(
N = 10,
K = 2,
y = y,
x = x
)
```

Any help or suggestions (alternative model designs) are highly appreciated.

- Windows
- R package version 2.21.5