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

Error in v1.0-8 about the structure of the data for the random factor #5

Open
wcornwell opened this issue Oct 4, 2017 · 3 comments

Comments

@wcornwell
Copy link

wcornwell commented Oct 4, 2017

Hello,

I had some code that seemed to be working with v1.0-6, but when I updated to v1.0-8, the model call returns an error.

model1<-BTm(player1=winner,player2=loser,
            formula = ~ prev +   
              (1|ID), id="ID",data=dataset)

which still in v1.0-6 runs (apparently) well, but in v1.0-8 it returns this error

Error in (function (fixed, random = NULL, family = "binomial", data = NULL, : 
`random` should be a matrix object, with 596 rows.

the traceback is pretty cryptic at least to me:

Error in (function (fixed, random = NULL, family = "binomial", data = NULL, : 
`random` should be a matrix object, with 596 rows.
5.
stop("`random` should be a matrix object, with ", nrow(modelData), " rows.")
4.
(function (fixed, random = NULL, family = "binomial", data = NULL, subset = NULL, weights = NULL, offset = NULL, na.action = NULL, start = NULL, etastart = NULL, mustart = NULL, control = glmmPQL.control(...), sigma = 0.1, sigma.fixed = FALSE, model = TRUE, x = FALSE, ...
3.
eval(fit, parent.frame())
2.
eval(fit, parent.frame())
1.
BTm(player1 = winner, player2 = loser, formula = ~prev + (1 | ID), id = "ID", data = dataset)

This is probably my mistake, but I'm having trouble tracking down where it's coming from. Any thoughts?

@hturner
Copy link
Owner

hturner commented Oct 5, 2017

The error is coming from BradleyTerry2::glmmPQL which is called when the model formula involves random effects. BTm ought to set up the random effects matrix correctly though. It's odd because your example appears to have the same form as the example in ?chameleons, which is running fine.

I would check the data structure of chameleons and see if your dataset has a similar form. For example, are winner$ID and loser$ID factors with the same set of levels?

If you're still stuck, I think I'd need a reproducible example to test - perhaps you can share a subset of your data, there are some tips here on how to share a minimal dataset: https://stackoverflow.com/q/5963269/173755.

@wcornwell
Copy link
Author

wcornwell commented Oct 5, 2017

Thanks so much for the quick response!

Turns out after some more digging it's a missing data handling issue, although trickily the missing data was not in the random effects matrix, but rather the previous contest result column. This should reproduce it with the chameleon data:

 chameleons$winner$prev.wins.2[34] <- NA
 summary(chameleon.model <- BTm(player1 = winner, player2 = loser, formula = ~ prev.wins.2 + ch.res[ID] + prop.main[ID] + (1|ID), id = "ID",  data = chameleons))
Error in (function (fixed, random = NULL, family = "binomial", data = NULL,  : 
  `random` should be a matrix object, with 105 rows.

I think for our use case I'll be able to sort it out. Thanks again!

@hturner
Copy link
Owner

hturner commented Oct 5, 2017

Glad you were able to find the source of the problem. I'll keep this issue open though, to check if this case could be handled more gracefully - at least giving a more helpful error message.

@hturner hturner reopened this Oct 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants