Questions tagged [gratia]

The gratia package was created by Gavin Simpson, with much of its usage documented here. The package includes several useful functions for plotting generalized additive models (GAMs), but also for estimating "under-the-hood" features of GAMs, such as the basis functions, derivatives, and partial residuals. Some of the common functions include:

  • draw: used as a catch-all ggplot style plot for GAMs
  • basis: create data frame containing basis functions for GAM splines
  • confint.gam: estimates confidence intervals for smooths.
10 questions
3
votes
0 answers

Overlaying Basis Functions for GAM Plot Part II: Random Effects

I recently posted a question about overlaying basis function on a GAM plot. This was quite helpful for modeling fixed effects models. However, I want to do the same thing for GAMMs and I'm running into a bit of a road block. I've tried simulating…
Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30
2
votes
1 answer

combining linear and random effect smooth in mgcv for plotting

Consider a simple GAM (using mgcv) with one linear smooth and one random intercept term like this: gam(y ~ s(x1) + s(x2, bs="re"), method = 'REML', family = 'gaussian', data = my.data) I know I can use gratia::smooth_estimates() to get nicely…
2
votes
0 answers

Custom GAMM function won't work on refit models

Solution So Far I wanted to craft a quick function for plotting crossed random effects GAMM models since I will likely be using them a good deal in the future. Using ggplot and gratia as the backbone, I tried simulating some data and making this…
Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30
2
votes
3 answers

How to plot logistic probability for custom generalized additive model (GAM) plot?

I realize that there is already a question pertaining to this here. However, I'm not looking to use the draw function and would prefer to build up the plot by scratch like shown here. However, the plot shown in the link doesn't show how to do this…
Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30
1
vote
1 answer

How to interpret the partial effect plots for parametric terms while using gratia::draw()?

I am asking a question akin to this one: What does the y-axis "effect" mean after using gratia::draw for a GAM but am wondering the same question for parametric terms not smooths. My data looks like this: df<-structure(list(spreg = structure(c(2L,…
David Smith
  • 305
  • 1
  • 8
1
vote
1 answer

How to overlay basis functions onto GAM plot

I am trying to find a way to replicate a plot similar to this, where the splines and the basis functions that make up those splines are both plotted in the same window. I have successfully done both separately below: #### Load Libraries…
Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30
0
votes
1 answer

Getting the correct order of factors for parametric terms in gratia::draw(parametric_effects())

I have a data set: df<- structure(list(Depth = c(6.83999999999997, 8.56, 4.64999999999998, 8.83999999999997, 6.56, 8.64999999999998, 12.21, 11.82, 5.41000000000003, 11.63, 9.41000000000003, 11.26, 8.95999999999998, 10.81, 10.68, 12.74, 14.06,…
David Smith
  • 305
  • 1
  • 8
0
votes
1 answer

Plot parametric interaction term from GAMM in R

From my GAMM, I've plotted my parametric interaction term on the response scale, but I'm getting these jagged/spiked predictions in my plots, particularly in the green line [A.]. I'd like to see something more like the second plot [B], where each…
Nate
  • 411
  • 2
  • 10
0
votes
1 answer

Function to plot multiple GAM parametric effects?

I created several GAMs which include non-smoothed (parametric), continuous variables (besides the s() parameters). I would like to plot the parametric, continuous variables of two models together. For example: g1 <- x ~ s(y) + z g2 <- x ~ s(y1) +…
mto23
  • 303
  • 1
  • 5
  • 15
0
votes
1 answer

ggplot: "No non-missing arguments to min/max; returning Inf"

I'm attempting to recreate this plot (my version: lat/lon by year), but keep getting these warnings after running the ggplot code: > warnings() Warning messages: 1: `stat_contour()`: Zero contours were generated 2: In min(x) : no non-missing…
Nate
  • 411
  • 2
  • 10