|I am trying to fit a multivariate linear mixed (MLMM) for the analysis of multiple response |\underbrace{\mathbf{y}}_{qn\times 1} = \boldsymbol{X\beta} + \boldsymbol{\underbrace{Z}_{qn\times qm}\underbrace{\gamma}_{qm\times 1}} + \boldsymbol{\varepsilon},~~ ||\boldsymbol{\gamma}\sim \mathcal{N}(\textbf{0},I_m\otimes\mathbf{G}),~~| ||\boldsymbol{\varepsilon}\sim \mathcal{N}(\textbf{0},I_n\otimes\mathbf{R})
I had the following error messages
“Error in FUN(X[[i]], …) : object ‘iter’ not found
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘C:/RTools/rtools40/usr/mingw_/bin/g++’ not found”
Thanks for your reply
data {
int<lower=0> N; // number of students
int<lower=1> q; //number of responses
int<lower=1> m; //number of random effects
int<lower=1> qm;
int<lower=1> qN;
matrix[m,m] A; // Identity matrix of size m
matrix[N,N] B; // Identity matrix of size N
int<lower=1> p; // number of fixed effects
matrix[qN,p] X; // Fixed effects design matrix
vector[1] Y[qN]; // response variable
matrix[qN,qm] Z; //subj ranef design matrix
}
transformed data{
matrix[m,m] LA;
matrix[N,N] LB;
LA= cholesky_decompose(A);
LB = cholesky_decompose(B);
}
parameters {
matrix[qm, 1] a_tilde;
matrix[N, 1] b_tilde;
vector[p] beta; // fixed effects
// Gi matrix
cholesky_factor_corr[q] L_Omega_G;
vector<lower=0>[q] L_sigma_G;
// R_i matrix
cholesky_factor_corr[q] L_Omega_R;
vector<lower=0>[q] L_sigma_R;
}
transformed parameters {
matrix[qm,qm] gam;
matrix[qN,qN] V;
matrix[qN,qN] R;
gam = (LA * a_tilde) *diag_pre_multiply(L_sigma_G, L_Omega_G)';
R = (LB * b_tilde) *diag_pre_multiply(L_sigma_R, L_Omega_R)';
V= Z*gam*Z'+R ;
}
model {
vector[N] mu = X * beta;
//E(y)=X*beta var(y)=ZGZ+R
Y ~ multi_normal_cholesky(mu, V);
to_vector(beta) ~ normal(0, 1);
to_vector(a_tilde) ~ normal(0, 1);
to_vector(b_tilde) ~ normal(0, 1);
L_Omega_G ~ lkj_corr_cholesky(2);
L_sigma_G ~ cauchy(0, 5);
L_Omega_R ~ lkj_corr_cholesky(2);
L_sigma_R ~ cauchy(0, 5);
}
generated quantities {
cov_matrix[q] G;
cov_matrix[q] Re;
corr_matrix[q] corrG;
corr_matrix[q] corrR;
G = multiply_lower_tri_self_transpose(diag_pre_multiply(L_sigma_G, L_Omega_G));
Re = multiply_lower_tri_self_transpose(diag_pre_multiply(L_sigma_R, L_Omega_R));
corrG = multiply_lower_tri_self_transpose(L_Omega_G);
corrR = multiply_lower_tri_self_transpose(L_Omega_R);
}