CecileProust-Lima / lcmm

R package lcmm
https://CecileProust-Lima.github.io/lcmm/
48 stars 13 forks source link

Error appears in For-loop of hlme : Error in `[.data.frame`(data, , v) : undefined columns selected #219

Open shendong333 opened 9 months ago

shendong333 commented 9 months ago

Dear Authors,

I am trying to explore some models based on different polynomial, but in the For-loop I encountered a error I can not fixed on my own. below is what i was tring :

ls <- list()
for (i in 1:5) {model_1 <- hlme(Y ~ poly(Time, degree = i, raw = TRUE),
                                ng = 1,
                                random = ~ -1,
                                data = data_hlme,
                                subject = "ID") 

ls[[i]] <- model_1 
}

And the error is:

Error in[.data.frame(data, , v) : undefined columns selected

Many thanks for any help.

VivianePhilipps commented 7 months ago

Hi,

this is a bug in the package. The variable "i" appearing in poly is seen as a covariate, so the error occurs because there is no such variable in data_hlme. I will try to fix it, but a workaround is to create this artificial covariate :

ls <- list() for (i in 1:5) { data_hlme$i <- i model_1 <- hlme(Y ~ poly(Time, degree = i, raw = TRUE), ng = 1, random = ~ -1, data = data_hlme, subject = "ID")

ls[[i]] <- model_1 }

This returns a lot of warnings, but the models seem correct.

Thank you for your feedback.

Viviane