gamlss-dev / gamlss

gamlss: Generalized Additive Models for Location Scale and Shape
https://CRAN.R-project.org/package=gamlss
12 stars 4 forks source link

predict with pvc not working #15

Open alvinwmtan opened 2 months ago

alvinwmtan commented 2 months ago

When fitting a gamlss model with pvc(), the predict method doesn't work.

Minimal reprex:

age <- c(17,17,18,18,19,19,17,17,18,18,19,19)
language <- c("eng","eng","eng","eng","eng","eng","spa","spa","spa","spa","spa","spa")
prop <- c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.2, 0.3, 0.4, 0.3, 0.6, 0.6)
df <- data.frame(age = age, language = as.factor(language), prop = prop)

mod <- gamlss(prop ~ pvc(age, by = language, lambda=10000), sigma.fo = prop ~ pvc(age, by = language), data = df)

nd <- expand_grid(age = c(17,18,19), language = c("eng", "spa"))
pred <- predict(mod, newdata = nd, type = "response", data = df)
# Error in l$beta : $ operator is invalid for atomic vectors
# In addition: Warning messages:
# 1: In model.matrix.default(~fac - 1, contrast = "") :
#   non-list contrasts argument ignored
# 2: In model.matrix.default(~fac - 1, contrast = "") :
#   non-list contrasts argument ignored
# 3: In model.matrix.default(~fac - 1, contrast = "") :
#   non-list contrasts argument ignored
TenanATC commented 1 month ago

I've also noticed that pvc() appears to throw those warnings when building the model and would be interested to know if they represent an issue that needs resolution.

Though, it is worth noting that the predict() method works fine when the following model is specified:

mod <- gamlss(prop ~ pvc(age, by = language), data = df)

So, it is not entirely clear to me if the issue resides with pvc() exactly or because there is some sparsity or another issue with overall model specification.