Here is the model in STAN syntax (thanks to code from Tanner Sorensen via a message sent on 30/01/2015):
data {
int<lower=0> N;
int<lower=0> T;
vector[N*T] vecY;
vector[N*T] vecM;
matrix[N,N] U;
matrix[T,T] S;
}
parameters {
matrix[T,T] V;
}
model {
matrix[T*N,T*N] Sigma;
V ~ inv_wishart(T+1, S);
for(ti in 1:T)
for(tj in 1:T)
for(ni in 1:N)
for(nj in 1:N)
Sigma[N*(ti-1)+ni, N*(tj-1)+nj] <- V[ti,tj] * U[ni,nj];
vecY ~ multi_normal(vecM, Sigma);
}
But when I use it, I get:
[1] "Rejecting initial value:"
[2] " Error evaluating the log probability at the initial value."
[3] "Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:"
[4] "Exception thrown at line 14: stan::math::inv_wishart_log: LDLT_Factor of random variable is not positive definite. last conditional variance is 3.66872."
[5] "If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,"
[6] "but if this warning occurs often then your model may be either severely ill-conditioned or misspecified."
[7] "Rejecting initial value:"
[8] " Error evaluating the log probability at the initial value."
[9] "Initialization between (-2, 2) failed after 100 attempts. "
[10] " Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model."
The problem seems to come from the inverse Wishart prior, but why?
ps: when I draw a random sample from MCMCpack::riwish(v=T+1, S=diag(T)) everything seems fine.
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.3 LTS
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] MCMCpack_1.3-3 coda_0.18-1 rstan_2.8.0 ggplot2_1.0.1 Rcpp_0.12.2
[6] MASS_7.3-44
loaded via a namespace (and not attached):
[1] lattice_0.20-33 codetools_0.2-14 digest_0.6.8 grid_3.2.2
[5] plyr_1.8.3 gtable_0.1.2 stats4_3.2.2 magrittr_1.5
[9] scales_0.3.0 stringi_1.0-1 reshape2_1.4.1 proto_0.3-10
[13] tools_3.2.2 stringr_1.0.0 munsell_0.4.2 compiler_3.2.2
[17] inline_0.3.14 colorspace_1.2-6 gridExtra_2.0.0
--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<test_matrix-normal.txt>