Hi,

Can you advise how to add an interaction term between the categorical variable “groups2” which has 3 categories (N_GROUPS2=3) and the continuous variable “X”? In this case there should be 3 beta2 coefficients. There is some incomplete code below for this.

To allow for variation between group1 categories, can you advise how allow each category in group1 to have their own interaction terms for the “group2” by “X” interaction. N_GROUP1=4 so in this case there should be 12 coefficients. To reduce code I am keeping assuming all group coefficients come from a fixed prior distribution (not centered or noncentered).
Thank you
data{
int<lower=1> N;
int<lower=1> N_GROUPS1;
int<lower=1> N_GROUPS2;
int<lower=1, upper=N_GROUPS1> groups1[N];
int<lower=1, upper=N_GROUPS2> groups2[N];
real X[N];
real Y[N];
}
parameters{
vector[N_GROUPS1] alpha;
vector[N_GROUPS1] beta1;
vector[N_GROUPS2] beta2;
real sigma;
}
model{
alpha~normal(0,5);
beta1~normal(0,5);
beta2~normal(0,5);
sigma~normal(0,5);
for(i in 1:N){
Y[i]~normal(alpha[groups1[i]]+beta1[groups1[i]]*X[i] + beta2[groups2[i]]* ??,sigma);
}
}