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

Tensor product smooths can't handle a random.effect marginal smooth #169

Open gavinsimpson opened 2 years ago

gavinsimpson commented 2 years ago

Previously this was largely handled because {gratia} silently ignored 3+ dimensional smooths when plotting (which is where such random effect smooths would arise - if univariate random smooth users would use the "fs" basis instead). Now that we handle 3 and 4 d smooths, need to handle tensor product smooths that have a random effect smooth as a marginal.

Think carefully about how to implement this; don't want to explode the number of evaluation points which could happen if the number of levels n of the random effect was large.

If the dimension is 1, we have equivalent of "fs" — especially if full = TRUE and t2() are used — If n is say <= 16 and dimension is 3 (so we have random 2d surfaces) , we could evaluate the entire line/surface at a number of points for each level? But what about > 16? We could sample, randomly, 16 of the levels?

For 4d smooths involving a random effect (so a random 3d smooth) I think we just have to not allow a plot. Which kinds makes finishing data_slice() more of a priority...

For smooth_estimates we should just do what the user wants and evaluate everything.

For draw() we should impose the above restrictions on what is plotted.

Fix:

  1. [x] smooth_data() needs to be aware of factors in the wrapper
  2. [x] smooth_estimates()
  3. [ ] draw.smooth_estimates()
  4. [ ] draw.gam()
gavinsimpson commented 1 year ago

Tensor products with a random effect marginal(s) are supported but whether anything useful can be plotted remains to be seen.

There are also no checks yet on how many levels of the random effect there are or an argument to restrict the number of levels plotted.