Hey everyone,
I am trying to build my first Bayes Model for a Bayes confirmatory factor analysis. I am working with rstan. I am not quite sure if I did it right. My model does converge, but i have some problems with long running times (many hours), so I wanted to ask for hints here.
Here is my model:
mod_4 <- "
data {
int<lower=0> N; // Number of observations
int<lower=0> K; // Number of observed variables
int<lower=0> F; // Number of factors
matrix[N, K] Y; // Matrix of observed data
int<lower=1,upper=F> factor_map[K]; // Factor mapping of variables
}
parameters {
vector<lower=0, upper=1>[K] lambda; // Factor loadings
cholesky_factor_corr[F] L_Omega; // Cholesky-dissembled correlation matrix of factors
vector<lower=0>[F] tau; // Scale parameters of the latent factors
matrix[N, F] eta_tilde; // Uncorrelated latent variables
vector<lower=0, upper=1>[K] sigma; // Residual variances
}
transformed parameters {
matrix[N, F] eta; // Latente Variablen mit Kovarianzstruktur
matrix[F, F] Omega; // Korrelationsmatrix der Faktoren
Omega = multiply_lower_tri_self_transpose(L_Omega); // Berechnung von Omega aus L_Omega
eta = eta_tilde * diag_pre_multiply(tau, L_Omega); // Skalierte und korrelierte latente Faktoren
}
model {
// Informative Priors for factor loadings
lambda[1:3] ~ normal(0.84, 0.05); # Positive Emotions ## Changing Standard deviation due to too narrow priors
lambda[4:6] ~ normal(0.65, 0.200); # Engagement
lambda[7:9] ~ normal(0.78, 0.107); # Relationships
lambda[10:12] ~ normal(0.87, 0.05); # Meaning ## Changing Standard deviation due to too narrow priors
lambda[13:15] ~ normal(0.75, 0.151); # Accomplishment
// Uninformative priors for sigma
sigma ~ beta(2,3);
// LKJ-Prior fĂĽr die Korrelationsmatrix
L_Omega ~ lkj_corr_cholesky(1);
// Priors fĂĽr die Skalenparameter der latenten Faktoren
tau ~ normal(0, 1);;
// Latent variables as standardized normal distributed
to_vector(eta_tilde) ~ normal(0, 1);
// Likelihood der beobachteten Variablen
for (k in 1:K) {
Y[, k] ~ normal(lambda[k] * eta[, factor_map[k]], sigma[k]);
}
}
"
Further, i have to run the code with a lot of iterations, I run the model with the following arguments:
fit_bayes_4 <- stan(
model_code = mod_4,
data = stan_data,
iter = 22000,
chains = 4,
# verbose = TRUE,
control = list(adapt_delta = 0.9995, max_treedepth = 20)
)
I am really not sure if I did it right and since I have any comparison because this is my first bayes model, I am uncertain if this is normal (like the long running times and lots of iterations to get acceptable rhat and n_eff).
I am really helpfull if someone could give me their thoughts about my model!
Thanks in advance!