`model_parameters()` for `mgcv::gam()` returns an error when the model does not contain smooth terms
RoelVerbelen opened this issue · 3 comments
RoelVerbelen commented
Great set of packages!
I noticed an issue when trying to use it with mgcv
: when specifying a gam()
model without smooth terms, the model_parameters()
function breaks down. Here's a reproducible example:
library(parameters)
library(mgcv)
#> Loading required package: nlme
#> This is mgcv 1.8-39. For overview type 'help("mgcv-package")'.
dat <- gamSim(1,n = 400, dist = "normal", scale = 2)
#> Gu & Wahba 4 term additive model
b <- gam(y~ x0 + x1 + x2 + x3, data = dat)
model_parameters(b, ci_method = "wald")
#> Error in rep("smooth_terms", nrow(cs.smooth)): invalid 'times' argument
Created on 2023-01-25 by the reprex package (v2.0.1)
Would it be possible to take this use case into account?
strengejacke commented
library(parameters)
library(mgcv)
#> Loading required package: nlme
#> This is mgcv 1.8-41. For overview type 'help("mgcv-package")'.
set.seed(123)
dat <- gamSim(1,n = 400, dist = "normal", scale = 2)
#> Gu & Wahba 4 term additive model
b <- gam(y~ x0 + x1 + x2 + x3, data = dat)
model_parameters(b)
#> Parameter | Coefficient | SE | 95% CI | t(395) | p
#> -------------------------------------------------------------------
#> (Intercept) | 6.51 | 0.54 | [ 5.44, 7.58] | 11.98 | < .001
#> x0 | 0.28 | 0.55 | [-0.80, 1.35] | 0.51 | 0.611
#> x1 | 6.39 | 0.53 | [ 5.34, 7.44] | 11.97 | < .001
#> x2 | -5.20 | 0.55 | [-6.29, -4.11] | -9.39 | < .001
#> x3 | 1.40 | 0.54 | [ 0.34, 2.47] | 2.60 | 0.010
b <- gam(y~ s(x0) + s(x1), data = dat)
model_parameters(b)
#> # Fixed Effects
#>
#> Parameter | Coefficient | SE | 95% CI | t(393.94) | p
#> --------------------------------------------------------------------
#> (Intercept) | 7.97 | 0.17 | [7.64, 8.30] | 47.83 | < .001
#>
#> # Smooth Terms
#>
#> Parameter | F | df | p
#> ----------------------------------------
#> Smooth term (x0) | 4.48 | 2.53 | 0.004
#> Smooth term (x1) | 43.35 | 2.53 | < .001
b <- gam(y ~ s(x0) + s(x1) - 1, data = dat)
model_parameters(b)
#> Parameter | Coefficient | 95% CI | t(397.26) | p
#> ------------------------------------------------------------
#> Smooth term (x0) | 1.50 | | 0.53 | 0.628
#> Smooth term (x1) | 1.24 | | 14.24 | < .001
b <- gam(y ~ s(x0) + s(x1) + x2 + x3, data = dat)
model_parameters(b)
#> # Fixed Effects
#>
#> Parameter | Coefficient | SE | 95% CI | t(391.73) | p
#> ----------------------------------------------------------------------
#> (Intercept) | 9.88 | 0.39 | [ 9.11, 10.65] | 25.31 | < .001
#> x2 | -5.30 | 0.53 | [-6.34, -4.25] | -9.96 | < .001
#> x3 | 1.41 | 0.52 | [ 0.39, 2.43] | 2.71 | 0.007
#>
#> # Smooth Terms
#>
#> Parameter | F | df | p
#> ----------------------------------------
#> Smooth term (x0) | 6.69 | 2.50 | < .001
#> Smooth term (x1) | 49.63 | 2.76 | < .001
Created on 2023-01-25 with reprex v2.0.2
strengejacke commented
Requires latest insight
RoelVerbelen commented
Excellent, thanks a lot for the quick fix!