Home > Mobile >  undefined columns selected: hlme
undefined columns selected: hlme

Time:10-08

I ran the following code using 'hlme' and keep getting the following error message:

m1a <- hlme(GFR_QRT_MEAN ~ poly(TIME_QRT, degree = 3, raw = F),random = ~ 1, subject = "ID",data = WK, ng = 1)

"Error in [.data.frame(x, i, j) : undefined columns selected".

I checked the dataset 'WK', "GFR_QRT_MEAN" ,"TIME_QRT" , and "ID" are all in the dataset. I also tried this dataset to do other regression analysis using these three variables. There was no such error message at all. Could you kindly help me to find the reason? Thank you!

CodePudding user response:

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,

  1. hlme(Sepal.Length ~ poly(iris2$Sepal.Width, degree = 3), random = ~ 1, subject = "Species", data = iris2, ng = 1)

  2. 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

  •  Tags:  
  • r
  • Related