New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
smooth_samples() throws error messages for gam models with random effects #121
Comments
The issue with these data is annoyingly simple (and you can avoid the bug by specifying the four smooths arising from the factor by term as the only smooths to evaluate). The function is working; all the hard work gets done, but it falls over when adding information about the variables involved in the smooth because in handling factor-by terms I am ignoring factors at some point in the code and for random effects the factor is the data hence I'm also ignoring the very thing I need. Now I just need to figure out what the right fix is... |
Thanks for the clarification Gavin, library(mgcv); library(gratia) set.seed(2) m2 <- gam(y ~ fac + s(x2, by = fac) + s(x0), data = dat) sms <- smooth_samples(m2, n = 5, seed = 42) sms <- smooth_samples(m2, n = 5, seed = 42, term = "s(x2)") smooths(m2) # Select smooths specific to each level of "fac" sms.2 <- smooth_samples(m2, n = 5, seed = 42, term = "s(x2):fac2") sms.3 <- smooth_samples(m2, n = 5, seed = 42, term = "s(x2):fac2") I hope I didn't make any mistake here, but it looks like the lines above only works for the first level of "fac". I am not able to select and plot the next levels however. Hope this can be solved easily, I really like the package otherwise and it's really improved my understanding of these complicated classes of model! Thanks! Raphaël |
Those last two should work; that they don't is a bug. Looks like I'm not pulling out the correct factor level or label somewhere. I will take a look at this and @isabellaghement's problem in the next few days or over Christmas when I have some time away from work work. |
… is now different; add tests for main issue in #121
@rroyaute I have fixed the problem you reported here - that was caused by a silly thinko in some of the code. |
@isabellaghement I have now fixed the main issue you reported; I have decided to just ignore random effect smooths for now as they aren't really what I had in mind for this function and would be tricky to fit into the current paradigm. |
@isabellaghement The example data from your issue are all working with the GitHub version of {gratia} now. You mentioned another issue with your real data but that isn't raised in the reproducible example you provided and from the error message you mention seems unrelated to the other error messages. I'm going to close this one as fixed now, but can you install from GitHub and try your actual data example again and file a new issue if the other problem persists? |
Hi Gavin,
I'm trying to use gratia's smooth_samples() function as part of a "by hand" derivatives calculation but am getting error messages for gam models which include random effects.
Using the dataset normtimedata.csv available at https://uofi.app.box.com/s/jtzww0bmgo9216qgpxu6d7avpaa15sey via the Download button, I put together some R code which illustrates one type of error message that I get. The models used in this code were inspired by this post: https://marissabarlaz.github.io/portfolio/gam/.
The error message I get from R for each of the above gam models expect for the one without random effects is:
Error in names(summ_names) <- paste0(".x", seq_along(summ_names)) :
'names' attribute [1] must be the same length as the vector [0]
For my own dataset, I actually get a different error message, which I could not reproduce with the examples listed above:
Error: New columns must be compatible with
.data
.x New column has 15000 rows.
i
.data
has 7000 rows.But it seems to me that smooth_samples() is struggles with gam models that include random effects and, depending on the model specification, it throws different types of error messages.
If you could look into this and let me know if there is a fix, that would be greatly appreciated.
Thanks very much!
Isabella
The text was updated successfully, but these errors were encountered: