Skip to content
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

simulateResidual error - incorrect number of dimensions #434

Open
NLJames opened this issue Sep 13, 2024 · 6 comments
Open

simulateResidual error - incorrect number of dimensions #434

NLJames opened this issue Sep 13, 2024 · 6 comments

Comments

@NLJames
Copy link

NLJames commented Sep 13, 2024

Hi @florianhartig,

Firstly, DHARMa is amazing, thank you for all the hard work.

I am having an issue I have never encountered after hundreds of uses of this function. I ran a model in glmmTMB which I have checked has converged with a sensible output. But running simulateResiduals() on this object does not seem to be able to interpret the output. Strangley, I have never had this issues before with glmmTMB model objects. Can you shed any light on why this is happening? I can share the data if need be.

m4<-glmmTMB(resids ~ wSpeed_mn + (1|BandNumber)
            , family = gaussian()
            , data=noNA_resiDat
            , REML=TRUE)

pRes1<-simulateResiduals(fittedModel =  m4, n=2000)

Error message

Error in mr[, 1] : incorrect number of dimensions
@NLJames
Copy link
Author

NLJames commented Sep 16, 2024

I have figured out the issue here, posting info for posterity. Seems that the resids column was stored as a matrix within the data frame used for the model. It was not converted through the glmmTMB function which I suppose was causing problems when handed to DHARMa. So seems that the column classes are important even at the modelling stage.

@melina-leite
Copy link
Collaborator

Hi @NLJames, thanks for reporting and finding the error!
This is related to issue #280, but now with glmmTMB.
This is a bug that should be fixed soon.

Cheers

@florianhartig
Copy link
Owner

Hi @NLJames,

as Melina said, we'll be looking at this - for this, and just if it's no inconvenience, it could be useful if you could provide a reproducible example of your problem and post it here, just so that we can check if a possible solution to the issue fixes the problem?

Cheers
Florian

@florianhartig florianhartig reopened this Sep 16, 2024
@bbolker
Copy link
Contributor

bbolker commented Sep 16, 2024

If this is something that triggers any problems in glmmTMB (as opposed to being DHARMa-specific) please post an issue for glmmTMB as well.

@bbolker
Copy link
Contributor

bbolker commented Sep 16, 2024

A reproducible example of a warning (not an error):

mtcars$mpg <- scale(mtcars$mpg)
m <- glmmTMB::glmmTMB(mpg ~ cyl, data = mtcars)
DHARMa::simulateResiduals(m)
Object of Class DHARMa with simulated residuals based on 250 simulations with refit = FALSE . See ?DHARMa::simulateResiduals for help. 
 
Scaled residual values: 0.548 0.564 0.116 0.612 0.912 0.208 0.44 0.272 0.112 0.292 0.16 0.68 0.772 0.548 0.076 0.076 0.504 0.972 0.9 1 ...

Warning messages:
1: In securityAssertion("nKcase - wrong dimensions of response") :
Message from DHARMa: During the execution of a DHARMa function, some unexpected conditions occurred. Even if you didn't get an error, your results may not be reliable. Please check with the help if you use the functions as intended. If you think that the error is not on your side, I would be grateful if you could report the problem at https://github.com/florianhartig/DHARMa/issues

Context: nKcase - wrong dimensions of response
2: In securityAssertion("nKcase - wrong family") :
Message from DHARMa: During the execution of a DHARMa function, some unexpected conditions occurred. Even if you didn't get an error, your results may not be reliable. Please check with the help if you use the functions as intended. If you think that the error is not on your side, I would be grateful if you could report the problem at https://github.com/florianhartig/DHARMa/issues

Context: nKcase - wrong family

(Adding a random effect and REML=TRUE doesn't seem to make a difference.)

@melina-leite
Copy link
Collaborator

Hi @bbolker, thanks for sharing an example with the warnings. It was an issue with the function getObservedResponse.default() that was expecting a matrix for the observed responses only for n/k binomial models. We no longer have a warning about "binomial" problems when the response variable is a matrix (as when using scale()).
So, I closed issue #280.

However, I'm not sure anymore if this issue problem is related to it. @NLJames, if possible, could you please provide a reproducible example of your case? It would be also great if you could try to run the code with the latest DHARMa development version to check if the solution to issue #280 also worked for your problem. :)

Best,
Melina

@melina-leite melina-leite modified the milestones: 0.4.7, 0.4.8 Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants