Closed BenoitLondon closed 1 year ago
I don't think it has to do with the latest mixedup, it's just that I don't have functionality for 'by' stuff (except maybe by accident). But I think it's also that you can do this more clearly as a random slope of log_wt
across cyl
approach
From your primary model:
> coef(mod)
(Intercept) s(cyl):I(log(wt)).1 s(cyl):I(log(wt)).2 s(cyl):I(log(wt)).3
33.933241 -9.382861 -12.449715 -13.648564
Differently expressed:
> mod <- mgcv::bam(mpg ~ s(log_wt, cyl, bs = "re"), data = mtcarsf)
> coefs <- mixedup::extract_random_effects(mod)
> coefs
# A tibble: 3 × 7
group_var effect group value se lower_2.5 upper_97.5
<chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
1 cyl log_wt 4 -9.38 2.66 -14.6 -4.17
2 cyl log_wt 6 -12.4 2.08 -16.5 -8.37
3 cyl log_wt 8 -13.6 1.64 -16.9 -10.4
Same result. 😄 I also think that model would be more clear to you in the future as well.
Other notes:
+ s(cyl, bs = 're')
. You can compare a model with and without the random slope and possibly simplify the model if need be, but mainly that would be more consistent with how mixed models with random slopes are usually expressed.I()
or log()
, as mgcv and/or mixedup (and many other packages) will likely have naming issues at some point. Just create the feature separately as log_wt to avoid potential problems.Hope that helps, but let me know if you have other issues.
Going ahead and closing but feel free to reopen if needed.
thanks that all makes sense.
Hi, first thank you for that great package! Unfortunately, it does not work for my use case anymore :( Hope you can help :D Here's a reprex:
digging into the code
vn
does not look to contain a valid column anymore when grabbed hereif no
by
term in the spline, it works fine