-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Example 1
When running the code below:
data("ChickWeight")
lm_robust(weight ~ 0 + Diet + Time:Diet, data = ChickWeight, clusters = Chick)
I get the error:
Error in !(class(ret[["cluster"]]) %in% c("factor", "integer")) && !is.null(ret[["cluster"]]) : 'length = 2' in coercion to 'logical(1)'
I believe this is a bug relating to ChickWeight$Chick being an ordered factor. When running the following code instead, lm_robust() works as expected:
data("ChickWeight")
ChickWeight$Chick <- factor(ChickWeight$Chick, ordered = FALSE)
lm_robust(weight ~ 0 + Diet + Time:Diet, data = ChickWeight, clusters = Chick)
Example 2
To prove that this bug is related to clusters being an ordered factor, I tried again with mtcars. The following code, where clusters is not an ordered factor, runs as expected:
data("mtcars")
lm_robust(mpg ~ wt + hp, data = mtcars, clusters = cyl)
When I try again, but with cyl being an ordered factor, I get the same error:
data("mtcars")
mtcars$cyl <- factor(mtcars$cyl, ordered = TRUE)
lm_robust(mpg ~ wt + hp, data = mtcars, clusters = cyl)
Error in !(class(ret[["cluster"]]) %in% c("factor", "integer")) && !is.null(ret[["cluster"]]) : 'length = 2' in coercion to 'logical(1)'