gavinsimpson / gratia

ggplot-based graphics and useful functions for GAMs fitted using the mgcv package
https://gavinsimpson.github.io/gratia/
Other
206 stars 28 forks source link

smooth_type has no return when smooth class is cpspline.smooth #312

Closed NatalieDupont closed 3 months ago

NatalieDupont commented 3 months ago

smooths produced in a gam using s(x, bs="cp") do not return a smooth type with the function gratia::smooth_type(smooth). here is some example code that reproduces this issue:

library(gratia)
library(mgcv)

data <- data.frame(x = c(1:100),
                   y=c(1:100))

gam <- gam(y~s(x, bs="cp"), data=data, method="REML")
smooth <- get_smooth(gam, "s(x)")
class(smooth) # class of smooth appropriately reported
#[1] "cpspline.smooth" "mgcv.smooth"

cp_smooth_type <- smooth_type(smooth)
#throws error Error in smooth_type.default(smooth) : Unknown type of smooth

Version of R: 4.4.1 Version of mgcv: mgcv_1.9-1 Version of gratia: gratia_0.9.2

gavinsimpson commented 3 months ago

This is fixed following #297 in the development version. If you install from GitHub or my r-universe, you will get the devel version. Instructions are in the README.md