-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Non-positive definite matrix when fitting nested GLMM #792
Comments
What happens if you include some clustering in the simulation? Or am I missing this in your code? |
No, there is no clustering in the current simulation (recalled is just a Bernoulli RV for every row in the dataframe). Just to clarify, you're suggesting creating a simulation where there is non-zero variability due to subject/session etc? |
Right. Your data have nothing to be recovered in the random-effect structure if I understand correctly. So these data do not require a GLMM; they would be fitted with a GLM. |
That is correct -- it still seems strange to me that this error would occur only with very specific design matrices (given that there is no random-effect structure in any of the models) but I will try a simulation with clustering and report back! |
I added the following code to the data generation prior to fitting the model:
My understanding is that the random effect variances are always initialized to 1 and the fixed effects are initialized to small values near 0. In any case, I believe this should simulate data assuming that the model being fitted is correct. |
I should note that this error actually occurs during construction of the model object, prior to any model fitting. The following code is enough to produce the error:
Therefore, it cannot be about the relationship between the response variable and the covariates. |
The two formulae are acceptable for linear mixed models. I am out of my depths with GLMM.
|
This isn't quite right -- the failing factorization also occurs during model creation because the factorization is part of the internal representation of a Since @kliegl pointed out that the LMM fit seems to work, that highlights an experimental feature that we have that starts off with an LMM fit to get better initial starting values for the GLMM fit. You can try passing the keyword argument |
Thanks so much for all your help in understanding this so far @palday and @kliegl. @palday thanks for the suggestion but (and please correctly if I'm wrong) I'm not sure if that will solve the problem because the error occurs prior to fitting in the constructor for the
Specifically the issue seems to be with the deviance calculation here.
Would there be an issue with calling |
In the other direction, I've now attempted to produce an example where the data is generated with clustering and the model is "correct"
This resulted in the same positive-definite matrix error. That being said, I'm still somewhat of a Julia novice so please correct me if I've made any mistakes here! |
I am trying to understand some issues I've encountered when trying to fit some models or a psychology experiment on memory where there is a lot of nested structure.
For background, the goal is to estimate the effect of position within a list on the probability of recall. Each subject in the experiment participates in multiple sessions with multiple lists. The following code creates an example dataset:
Then to fit the model I use the following code:
I fit several models, some of which fit without problems and one that has problems. The following all fit fine:
(m1)
form => @formula(recalled ~ serialpos + (1 | subject) + (1 | subject & session) + (1 | subject & session & list))
(m2)
recalled ~ serialpos + zerocorr(serialpos | subject)
(m3)
recalled ~ serialpos + (1 | subject) + (1 | serialpos & subject) + (1 | subject & session)
However, I run into issues when trying to fit the following model, with the subject effects varying and random intercepts by session:
(m4)
recalled ~ serialpos + zerocorr(serialpos | subject) + (1 | subject & session))
This results in this error:
I realize this has been partially addressed before (e.g. #349 (comment)) but I'm not really sure I fully understand why (m4) has an error -- (m1) should have more parameters and (m3) should be nearly equivalent to (m4) (although I realize the design matrices are slightly different).
I thought perhaps the correlation structure might be an issue so I tried fitting two models with fulldummy which seems more straight forward.
(m5)
recalled ~ serialpos + zerocorr(fulldummy(serialpos) | subject)
(m6)
recalled ~ serialpos + zerocorr(fulldummy(serialpos) | subject) + (1 | subject & session)
(m5) fit fine and (m6) ran into the positive definite error.
Is there any good intuition for what is going on here?
The text was updated successfully, but these errors were encountered: