It's pretty strange. As you might know, poly
function's default for raw
is FALSE
. For iris
data, I can reproduce similar(or same) error by
iris2 <- iris %>%
mutate(Species = as.numeric(Species))
hlme(Sepal.Length ~ poly(iris2$Sepal.Width, degree = 3, raw = F), random = ~ 1, subject = "Species", data = iris2, ng = 1)
Error in `[.data.frame`(data, , v) : undefined columns selected
There were several strange way to fix this is,
hlme(Sepal.Length ~ poly(iris2$Sepal.Width, degree = 3), random = ~ 1, subject = "Species", data = iris2, ng = 1)
hlme(Sepal.Length ~ poly(iris2$Sepal.Width, degree = 3, raw = FALSE), random = ~ 1, subject = "Species", data = iris2, ng = 1)
what's weird is
x <- poly(iris2$Sepal.Width, degree = 3, raw = FALSE)
y <- poly(iris2$Sepal.Width, degree = 3, raw = F)
z <- poly(iris2$Sepal.Width, degree = 3)
head(x)
1 2 3
[1,] 0.083201357 -0.016039377 -0.086836597
[2,] -0.010776079 -0.053252127 0.029150387
[3,] 0.026814895 -0.056361540 -0.023300097
[4,] 0.008019408 -0.057805919 0.003760092
[5,] 0.101996844 0.009397687 -0.092912930
[6,] 0.158383306 0.121697905 -0.027105624
head(y)
1 2 3
[1,] 0.083201357 -0.016039377 -0.086836597
[2,] -0.010776079 -0.053252127 0.029150387
[3,] 0.026814895 -0.056361540 -0.023300097
[4,] 0.008019408 -0.057805919 0.003760092
[5,] 0.101996844 0.009397687 -0.092912930
[6,] 0.158383306 0.121697905 -0.027105624
head(z)
1 2 3
[1,] 0.083201357 -0.016039377 -0.086836597
[2,] -0.010776079 -0.053252127 0.029150387
[3,] 0.026814895 -0.056361540 -0.023300097
[4,] 0.008019408 -0.057805919 0.003760092
[5,] 0.101996844 0.009397687 -0.092912930
[6,] 0.158383306 0.121697905 -0.027105624
In conclusion, instead of raw = F
, try nothing or raw = FALSE