[R-sig-ME] Cross validated log likelihood, redux.

Rolf Turner r@turner @end|ng |rom @uck|@nd@@c@nz
Sat Aug 17 01:55:11 CEST 2019

My apologies for continuing to pester the list with questions about this 
issue, but I urgently need an answer to my most recent question.

That question was contained in a postscript to a reply to D. Rizopoulos, 
and thereby may have been overlooked.  Consequently I am re-posting this 
question.  (Again I apologise for taking up bandwidth.)

In summary, the situation is as follows:

* I am trying to calculate the log likelihood of a "new" data set on the 
basis of a model fitted to a different data set.

* Ben Bolker showed me how to do this using glmer() (from the lme4 
package) and after some to-ing and fro-ing I got his recipe to work.

* Dimitris Rizopoulis also showed me how to do this using the 
mixed_model() function from the GLMMadaptive package.  Again, after much 
delay and after more to-ing and fro-ing, I got Prof. Rizopoulis's advice 
to work.

* I then wanted to cross-check the value obtained from mixed_model() 
with that obtained from glmer(), so I re-ran the glmer() based code.
Lo and behold, that code threw an error (where it had not before done so).

I would really like to be able to use both methods (i.e. that based on 
mixed_model() and that based on glmer()).  So I would like to figure out 
what is going wrong --- or what I am doing wrong --- in the case of the 
glmer() approach.

I have attached a source-able script demo.glmer.txt to demonstrate what 
happens, and have also attached the (simulated) data set X.txt which the 
script uses.

If you place demo.glmer.txt and X.txt in your working directory and
source("demo.glmer.txt") you will get the following message and error 

> fixed-effect model matrix is rank deficient so dropping 1 column / coefficient
> (15!=3)
> Error in pp$setTheta(theta) : theta size mismatch

As I said in my (possibly overlooked) postscript in a previous posting 
on this issue:

This code *worked* previously!!!

I thought that the dropped coefficient might be the problem, so in the 
demo script I replaced coefs by coefs[-15] but then the error simply 
changes to:

 > (14!=3)
 > Error in pp$setTheta(theta) : theta size mismatch

Indeed 15!=3 (no shit, Sherlock!) and likewise 14!=3.  But why *3*???

If I do

chk <- update(g.trn,data=VS)
coefs.chk <- unlist(getME(chk,c("theta","beta")))

I get coefs.chk to be a vector of length 14 (which seems to line up,
names-wise, with coefs as produced by the script) so 14 seems to be the 
"right answer".  Where does 3 come in?

Initially (way back when) I got an error *something* like this, but then
Ben Bolker advised me to add the argument


to the call to update() and that fixed the problem that I was having. 
But the fix no longer seems to be "operative". :-)

What has changed?  Is there any way I can get this to work?

Thanks for any pearls of wisdom.


Rolf Turner

Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: demo.glmer.txt
URL: <https://stat.ethz.ch/pipermail/r-sig-mixed-models/attachments/20190817/d7e8d4a9/attachment.txt>

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: X.txt
URL: <https://stat.ethz.ch/pipermail/r-sig-mixed-models/attachments/20190817/d7e8d4a9/attachment-0001.txt>

More information about the R-sig-mixed-models mailing list