Please provide this additional information in addition to your question:
- Operating System: MacOS 10.12.6
- CmdStan Version: 2.22.1
- Compiler/Toolkit: clang
Hi,
I have a question about initial values for a cholesky factor. I have a model for two correlated outcomes (different ground-motion parameters from different earthquakes). There is also a random effect for each earthquake. The data is truncated, with the truncation being on the first target variable.
For the truncated model, in the model building process I find it convenient to specify starting values. I’m getting an erro when specifying starting values for this model.
The Stan code for a simplified model is as follows
data {
int<lower=1> N; // overall number of records
int<lower=1> NEQ; // number of earthquakes
int<lower=1> NP; // number of target variables
vector[N] M; // magnitude
int<lower=1,upper=NEQ> eq[N]; // earthquake id
vector[NP] Y[N]; // log psa
real<upper=min(Y[:,1])> Ytrunc; // truncation value
}
transformed data {
vector[NP] mu_eq = rep_vector(0,NP);
}
parameters {
vector[NP] intercept;
vector[NP] slope;
vector<lower=0>[NP] phi;
vector<lower=0>[NP] tau;
vector[NP] deltaB[NEQ];
cholesky_factor_corr[NP] L_p;
cholesky_factor_corr[NP] L_eq;
}
model {
vector[NP] mu[N];
matrix[NP,NP] L_Sigma;
matrix[NP,NP] L_Sigma_eq;
intercept ~ normal(0,10);
slope ~ normal(1,1);
phi ~ normal(0,1);
tau ~ normal(0,1);
L_p ~ lkj_corr_cholesky(1);
L_Sigma = diag_pre_multiply(phi, L_p);
L_eq ~ lkj_corr_cholesky(1);
L_Sigma_eq = diag_pre_multiply(tau, L_eq);
deltaB ~ multi_normal_cholesky(mu_eq,L_Sigma_eq);
for(i in 1:N) {
mu[i] = intercept + slope * M[i] + deltaB[eq[i]];
}
target += multi_normal_cholesky_lpdf(Y | mu, L_Sigma) - normal_lccdf(Ytrunc | mu[:,1],phi[1]);
}
The model runs without any problems when I don’t specify any initial values. However, when I use initial values from a file, then I get the following error
Exception: matrix[uni,uni] indexing, row: accessing element out of range. index 2 out of range;
expecting index to be between 1 and 1 (in '/var/folders/p3/r7vrsk6n2d15709vgcky_y880000gn/T/RtmpZ1S1FD/model-186147cbd6a5.stan',
line 28, column 2 to column 32)
Line 28 is where the cholesky factor is defined as a parameter. I don’t understand the error, the factor s defined as having size NP (which is two in this example). The initial values are also 2 by 2. I’s also not a problem with just these initial values.
I’m probably missing something simple here, and would appreciate any help. I attached example data and an initial file, in case someone wants to try and reproduce the example.
data_test.txt (4.6 KB)
init_test_tr_1.txt (1018 Bytes)