I have tried the following 2 sets of codes.
Code 1
This code models the probability that consumers will buy each of the product. This utilizes normal distribution.
stan.code = "data {
int<lower=0> N;
int<lower=0> K; // No. of Choice
matrix[N,K] Mix; //outcome
matrix[N,K] Price;
}
transformed data {
vector[N*K] y;
y = to_vector(Mix);
}
parameters {
vector[K-1] alpha_raw;
vector<lower=0>[K] beta;
real<lower=0> sigma;
}
transformed parameters {
vector[K] alpha;
matrix[N,K] gamma;
vector[N*K] mu;
alpha = append_row(0, alpha_raw);
for (i in 1:N) {
gamma[i] = (softmax( alpha - beta .* Price[i]' ))';
}
mu = to_vector(gamma);
}
model {
alpha_raw ~ normal(0,1);
beta ~ lognormal(0,1);
sigma ~ normal(0,0.5);
y ~ normal( mu, sigma);
}
"
Code 2
This code models sales of each product instead of probability. Hence, it utilizes multinomial distribution.
"data {
int<lower=0> N;
int<lower=0> K; // No. of Choice
matrix[N,K] Price;
int Mix[N,K]; //outcome
}
parameters {
vector[K-1] alpha_raw;
vector<lower=0>[K] beta;
}
transformed parameters {
vector[K] alpha;
matrix[N, K] pred_shares;
alpha = append_row(0, alpha_raw);
for (t in 1:N) {
pred_shares[t,1:K] = (softmax((alpha - beta .* (Price[t,1:K])')))';
}
}
model {
alpha_raw ~ normal(0,1);
beta ~ lognormal(0,1);
for (t in 1:N) {
Mix[t] ~ multinomial(pred_shares[t]');
}
}
"
May I ask which method would be more appropriate? Both methods produce different estimates of the coefficients. In addition, code 1 takes a shorter time to run compared to code 2. Any other advice on how I can improve this further? Thank you!