Open lemaitreh opened 3 days ago
temporary fix with the use of global assignment operator:
holder <<- data.frame(y = abdom[[variable]], x = abdom$x)
Thanks for the report. I can confirm the bug. The newdata
is actually found without any problem. But for some reason the predict()
method tries to re-evaluate the Call$data
from the fitted model and it does so in the wrong environment. Not sure why this is neeeded in the first place. A minimal reproducible example is:
library("gamlss")
pred <- function() {
d <- data.frame(y = sin(1:10), x = 1:10)
m <- gamlss(y ~ x, data = d, family = NO)
predict(m, newdata = d)
}
pred()
## GAMLSS-RS iteration 1: Global Deviance = 20.7488
## GAMLSS-RS iteration 2: Global Deviance = 20.7488
## Error in eval(Call$data) : object 'd' not found
Remark: Using the successor package gamlss2 (not yet on CRAN) the same code works. But the predict()
method works a bit differently.
I'm trying to use the predict function within a shiny app and it seems to have a problem with the newdata option:
RStudio 2021.09.0 Build 351 R 4.4.1 gamlss 5.4.22
Not working (predict.gamlss and newdata):
Error:
Working (gamlss, no newdata):
Working (predict.lm, newdata):