When running iccbin() on a dataset that has a particular CID value that only appears once, or that appears zero times but is still specified as a factor level, I get the following unhelpful error message:
Error in if (rho.mak < 0 | rho.mak > 1) { : missing value where TRUE/FALSE needed
I suggest adding a check for empty or singleton levels and providing an informative error message instead. I'd be willing to write code for that if you are accepting pull requests.
Here is some code you can use to replicate the issue:
# create a data frame with a nonzero ICC
testicc <- data.frame(
cid = factor(rep(seq(2,4), 30), levels=seq(2,4)),
score = runif(90, 0, 1)
)
testicc$y <- ifelse(testicc$score * 5 <= as.numeric(as.character(testicc$cid)), 1, 0)
# same data frame, but the CID has a level that occurs zero times
testicc_emptylevel <- data.frame(
cid = factor(rep(seq(2,4), 30), levels=seq(2,5)),
score = runif(90, 0, 1)
)
testicc_emptylevel$y <- ifelse(testicc_emptylevel$score * 5 <= as.numeric(as.character(testicc_emptylevel$cid)), 1, 0)
# same data frame as the first one, but the CID has a factor level that occurs only once
testicc_singletonlevel <- data.frame(
cid = factor(c(rep(seq(2,4), 30), 5), levels=seq(2,5)),
score = runif(91, 0, 1)
)
testicc_singletonlevel$y <- ifelse(testicc_singletonlevel$score * 5 <= as.numeric(as.character(testicc_singletonlevel$cid)), 1, 0)
# review data frames
with(testicc, table(cid, y))
with(testicc_emptylevel, table(cid, y))
with(testicc_singletonlevel, table(cid, y))
# this works
iccbin(cid=cid, y=y, data=testicc)
# these two both fail with an uninformative error message
iccbin(cid=cid, y=y, data=testicc_emptylevel)
iccbin(cid=cid, y=y, data=testicc_singletonlevel)
Thank you very much for this. I got this error too while playing around with this package, and would not have known how to diagnose if I hadn't seen this.
When running
iccbin()
on a dataset that has a particular CID value that only appears once, or that appears zero times but is still specified as a factor level, I get the following unhelpful error message:Error in if (rho.mak < 0 | rho.mak > 1) { : missing value where TRUE/FALSE needed
I suggest adding a check for empty or singleton levels and providing an informative error message instead. I'd be willing to write code for that if you are accepting pull requests.
Here is some code you can use to replicate the issue: