On Mar 17, 2014, at 6:32 PM, Douglas Bates <
dmb...@gmail.com> wrote:
> I am dipping my toes into stan,
Welcome!
> coming from a background in maximum likelihood estimation of linear mixed-effects models (I am one of the authors of the lme4 package for R and also of the MixedModels package for Julia).
We've all heard a lot about lme4 from Andrew (who calls it "lmer").
We've been spending some time going the other way and thinking
about (penalized) MLE and (penalized) maximum marginal likelihood for
Stan.
> I also have some familiarity with C++, Rcpp and Eigen having done the interface between R/Rcpp and Eigen for the RcppEigen package.
>
> I have at least skimmed the Reference Manual for Stan 2.2.0 and read some of the sections pretty thoroughly.
>
> I very much like the idea of the
>
> cholesky_factor_cov
>
> and
>
> cholesky_factor_cor
>
> classes. As the Stan authors may know, lmer uses the elements of the cholesky_factor_cov representation of the (relative) covariance matrices for the random effects as the parameters being directly optimized in the maximum likelihood estimation of parameters. (The fixed-effects coefficients and the residual standard deviation are profiled out of the log-likelihood function.)
Only a few of us are versed in the lme4 code.
> My first question is regarding a prior on the parameters in a cholesky_factor_cor object. Sections 46 and 47 of the manual discuss distributions of covariance matrices and correlation matrices. Is it possible to assign a prior distribution to the Cholesky factor directly? For example, in the lkj_corr_log method defined in lkj_corr.hpp the correlation matrix is factored before being passed to lkj_corr_choleksy, but lkj_corr_cholesky_log. Have I missed a definition of lkj_corr_cholesky or lkj_cov_cholesky to be used in an expression like
>
> L~lkj_corr_cholesky(eta)
>
> or do I go the direct route and call lkj_corr_cholesky_log to increment the log probability?
That function no longer exists as of Stan 2.2 (though it's still there in C++ if
that's what you're after). We're going to bring it back when we've added the cholesky_corr data type,
which is nearly ready to go. Without the data type, the density's useless because you'd have to
do the decomposition and Jacobian adjustment yourself in the Stan code, which
is pretty awful.
For now (Stan 2.2), you have to go the roundabout way of defining
a correlation matrix parameter:
parameters {
...
corr_matrix[K] Omega;
...
}
and then give it an LKJ prior:
model {
matrix[K,K] L; // local variable
Omega ~ lkj_corr(nu); // prior directly on correlation matrix
L <- cholesky_decompose(Omega);
... use L ...
}
This introduces a lot of redundant calculations because the underlying representation
for Omega in the unconstrained space is as its Cholesky factor, so we have to
do a redundant multiplication and Jacobian adjustment to get to the correlation
matrix itself in the constrained space, and then I believe lkj_corr does the Cholesky
factorization under the hood, and then cholesky_decompose does the factorization again.
All the redundant calculation will go away when we have the cholesky_corr data type, and
you'll be able to write something like this (we'll probably simplify the name of the
density):
parameters {
cholesky_corr L;
...
model {
L ~ lkj_cholesky(nu);
... use L ...
Ben Goodrich has a neat paper comparing Wishart and LKJ-style priors (he was
the one driving the design of these parts of the code):
http://www.stat.columbia.edu/~gelman/research/unpublished/Visualization.pdf
We're also adding a quad_form_diag(Omega,sigma) function in the next release
of Stan that will do
diag_matrix(sigma) * Omega * diag_matrix(sigma)
to make the kind of scaled covariance priors Andrew and Ben like easier to express.
- Bob