Hello.

I’m trying to predict a probability distribution from a categorical predictor. It seems like my model is not only clunky, but also wrong, as I am getting a few error messages that I can’t seem to fix. Hope someone can help. Here’s the error message:

```
SAMPLING FOR MODEL 'stan_code' NOW (CHAIN 1).
Unrecoverable error evaluating the log probability at the initial value.
Exception: dirichlet_lpmf: prior sample sizes has dimension = 6, expecting dimension = 48989; a function was called with arguments of different scalar, array, vector, or matrix types, and they were not consistently sized; all arguments must be scalars or multidimensional values of the same shape. (in 'model9ddc3e2dbeb8_stan_code' at line 36)
[1] "Error in sampler$call_sampler(args_list[[i]]) : "
[2] " Exception: dirichlet_lpmf: prior sample sizes has dimension = 6, expecting dimension = 48989; a function was called with arguments of different scalar, array, vector, or matrix types, and they were not consistently sized; all arguments must be scalars or multidimensional values of the same shape. (in 'model9ddc3e2dbeb8_stan_code' at line 36)"
error occurred during calling the sampler; sampling not done
```

And here’s the relevant part of my R code:

`design_matrix = model.matrix(~ Typ, data = dat) distributions = t(simplify2array(dat$distribution_vectors)) data_list = list(Y = distributions, X = design_matrix, N = nrow(dat), ncat = 6, input_dim = 6) # fit model fit <- stan(file = 'stan_code.stan', data = data_list, iter = 1000, chains = 1)`

And finally the stan script:

`data { int<lower=1> N; // total number of observations int<lower=2> ncat; // number of categories int<lower=2> input_dim; // number of predictor levels matrix[N,input_dim] X; // predictor design matrix matrix[N,ncat] Y; // response variable (simplex?) } transformed data{ matrix[ncat,N] Y_transposed; for (category in 1:ncat){ for (n in 1:N){ Y_transposed[category,n] = Y[n,category]; } } } parameters { matrix[ncat,input_dim] weights; // coefficients vector[ncat] y_transposed; } model { // priors for (out_category in 1:ncat) { for (in_category in 1:input_dim) { weights[out_category,in_category] ~ normal(0,5); } } // likelihood for (n in 1:N) { vector[ncat] logits; for (m in 1:ncat){ logits[m] = X[n] * transpose(weights[m]); } // logits = X[n] * weights; // can't multiply matrix with vector Y[,n] ~ dirichlet(softmax(logits)); } }`