I have a latent variable model in which I produce a product term. The product term is the product of two latent variables who's scores are sampled. Currently, my model is sampling the product term. This has drastically increased the number of parameters in my model.
My original model was in non matrix formulation:
vector [N] mueta;
matrix [N ,2] xi ;
mueta = b1[1] +
b1[2]*xi[,1] +
b1[3]*xi[,2] +
b1[4]*(xi[,2].*xi[,1]) ;
I changed it to a matrix formulation wherexi[,1]
is an N
length vector of 1s (intercept), xi[,2:3]
are factor scores, and xi[,4]
is an interaction effect.
vector [N] mueta;
xi[,1] = rep_vector(1, N);
xi[,2:3] = zi * diag_pre_multiply(sigmaxi,L1)' ;
xi[,4] = (xi[,2].*xi[,3]);
mueta = xi * b1 ;
The first model does not sample the product of the xi
matrix, the second formulation does. Is there a way for me to specify this in Stan so that xi[,4]
is not sampled, and is just a generated value from the product of the sampled scores of the 2 factors.
It looks like I solved my own issue. I wanted to post this answer for others who may have a similar problem.
vector [N] mueta;
xi[,1] = rep_vector(1, N);
xi[,2:3] = zi * diag_pre_multiply(sigmaxi,L1)' ;
mueta = (append_col(xi,(xi[,2].*xi[,3])) * b1) ;