Non-convergence of latent variable model

Lucas

Glad it is working now

I agree, i havent found a way to automate this section of sign adjusting.

Yes, basically sign correct the slope as another correlation, following the same rules/steps as before

blavaan handles the regressions in a way way more fancy than I can code, this does makes it harder to read sometimes

How I have code the regressions between factors, follow the next “rules” changes in the model section. For an example like this

HS.model <- ' visual  =~ x1 + x2 + x3
              textual =~ x4 + x5 + x6
              speed   =~ x7 + x8 + x9 
visual ~ textual + speed
'
  1. The outcome is set to follow a normal() instead of multivariate_normal(), because it is no longer correlated with anything else
  2. The 2 predictors factor, still follow a multivariate_normal(), for the correlation between them
  3. The mean of the predictor factors are fixed to 0, and their SD = 1
  4. The mean of the outcome factor is a function of the regression (M3), with an intercept of 0, to keep the factor identification constraints, the total variance is set to 1

I dont have a full example, but here would be the transform parameter and model section. In the generated quantities you would need to add the slopes into the sign correction if statements

transformed parameters{
vector[D-1] M;
vector<lower=0, upper=100>[D-1] Sd_d; // standard deviations
real mu[N,P];
matrix[D-1,D-1] Ly;// cholesky of the corr between factors
vector[N] M3;

for (m in 1:(D-1)) {
M[m] = 0;
Sd_d[m] = 1;}

Ly = diag_pre_multiply(Sd_d, L_corr_d);

for(i in 1:N){
mu[i,1] = b[1] + lam[1]*FS[i,1];
mu[i,2] = b[2] + lam[2]*FS[i,1];
mu[i,3] = b[3] + lam[3]*FS[i,1];
mu[i,4] = b[4] + lam[4]*FS[i,2];
mu[i,5] = b[5] + lam[5]*FS[i,2];
mu[i,6] = b[6] + lam[6]*FS[i,2];
mu[i,7] = b[7] + lam[7]*FS3[i];
mu[i,8] = b[8] + lam[8]*FS3[i];
mu[i,9] = b[9] + lam[9]*FS3[i];

M3[i] = reg[1]*FS[i,1] + reg[2]*FS[i,2];
}
}


model{

L_corr_d ~ lkj_corr_cholesky(2);
b ~ normal(0, 5);
lam ~ normal(0.4,10);
reg ~ normal(0.2,10);

FS3 ~ normal(M3, 1);

for(i in 1:N){  
FS[i] ~ multi_normal_cholesky(M, Ly);
}

}

Hope something like this works