Replies: 1 comment
-
I wouldn't rename for now (we just had a breaking release after all 😉), but add in a new function. We can look into formal deprecation/redirection as we get more familiar with the use. But otherwise, this sounds like a great optimization to have. On the |
Beta Was this translation helpful? Give feedback.
-
@kliegl has been working on a very large data set where one of the grouping factors,
Student
, has over 100,000 levels. The next grouping factor,School
, has about 500 levels. He would like to create caterpillar plots of the prediction intervals for the random effects for school. At present it is necessary to create the conditional variance,condVar
, results for all the grouping factors to do this - which means that there is a tremendous amount of effort devoted to evaluating conditional variances of the random effects for each of the students, even though it is known that they won't be used.So we should work out a way to create the conditional covariance matrices for a "trailing" set of grouping factors. Alternatively, we can define
condVar
to apply to only one grouping factor because we only plot one set of random effects at a time in the caterpillar plot.Restricting to a single grouping factor is aided by the fact that the central calculation is solving a system with the left hand side being the random-effects part of the blocked lower Cholesky factor L, and leading zeros are propagated in such a solution. That is, when working with a lower triangular matrix, as in the call to
ldiv!
below, you don't need the part of L corresponding toStudent
if you only want information onSchool
random effects. The hand-waving explanation of this is that lower triangular systems can be solved with a "forward solve" so if you start off with a whole bunch of leading zeros on the right hand side these propagate to the solution. You do need to take into account blocks to the right of the one where you start (Cohort
in Reinhold's example) but not those to the left.Currently the
condVar
method is defined aswhere
sparseL
creates a sparse version of the part of the L factor associated with the random effects.For example, using a model fit to the
:mrk17_exp1
data setthe blocks of
A
andL
arebut the last row corresponds to the fixed-effects and the response. Thus
sparseL
returns a sparse lower triangular matrix of dimension 1638 (= 1200 + 438)The point of describing all this is that to evaluate the conditional variance-covariance for the random effects for
subj
, you don't need the part on the left. You only need the 438 by 438 part in the lower right. In Reinhold's example the whole matrix will be on the order of 600,000 by 600,000 but only a few hundred rows and columns are involved in obtaining the conditional covariance matrices for theSchool
s.My plan right now is to rename
sparseL
asranefL
or something like that and have a second argument of a grouping factor name, which will default to the first grouping fact. For the first grouping factor the result will be essentially what it is now except that the sparse matrix will be passed throughdensify
, which will make it dense unless the sparse matrix is sufficiently sparse to warrant keeping it that way. (Sparse matrices are only worth the trouble is there is a high degree of sparsity. In this case about 37% of the lower triangle is non-zero so it would be easier and faster to work with a dense matrix.)If the grouping factor is not the first one in the fitted model then the L that is returned will be just the lower right block(s) from that position on. In Reinhold's case this will be the blocks corresponding to School and to Cohort for the School grouping factor.
I will explore this and report back on timings, etc.
Beta Was this translation helpful? Give feedback.
All reactions