1
$\begingroup$

Can anyone point me to sources (publications, blog posts, videos etc) about the following problem? (The more conceptual the discussion, the better!)

I have the two explanatory GAMs below (in this example implemented with mgcv), and would like to compare the effect sizes of s(x1) and s(x2) in a more formal way than just visual comparison. In particular, I'd be interested in which smooth predicts more y_counts. Would integration of the x1 and x2 smooths be a feasible option?

mod1 <- gam(count_y ~ s(time) + s(x1) , data = dat, family = nb, method = 'REML', select = TRUE)
mod2 <- gam(count_y ~ s(time) + s(x2) , data = dat, family = nb, method = 'REML', select = TRUE)

The above models ignore some of the complexity of my real models, which include distributed lag (set up as a 7-column matrix, as in the code by Simon Wood in the gamair package) and additional covariates as follows:

mod3 <- gam(count_y ~ s(time) + te(x1, lag) + te(z, lag) , data = dat, family = nb, method = 'REML', select = TRUE)
mod4 <- gam(count_y ~ s(time) + te(x2, lag) +te(z, lag) , data = dat, family = nb, method = 'REML', select = TRUE)

Here te(x1, lag) and te(x2, lag ) model 3D-surfaces rather than 2D curves

I'd be very happy for responses about the more complex models too, but thought I'd first get the ball rolling on the simpler ones without the distributed lag.

$\endgroup$
6
  • $\begingroup$ Is there a reason not to include both te(x1, lag) and te(x2, lag) in the same model? $\endgroup$ Commented Oct 25, 2022 at 7:03
  • $\begingroup$ Hi Gavin, yes. In my case, x1 and x2 are two different measures of heat (say x1 = air temperature and x2 = some heat index that is a composite of e.g. air temperature and humidity). I am interested in which measure predicts more deaths (y_counts), particularly across the function. $\endgroup$
    – Jade
    Commented Oct 25, 2022 at 9:39
  • 1
    $\begingroup$ In that case, can't you simulate daily deaths from each model varying xX over their respective ranges, sum the daily deaths from each simulation, and that yields a posterior for the cumulative deaths which you can then summarise with some quantiles. Do that for your models with x1 and x2 and you have the point estimates (plus uncertainties) to compare $\endgroup$ Commented Oct 25, 2022 at 10:50
  • $\begingroup$ That sounds like a good solution! I have 2 questions which are probably quite silly (sorry), but here goes. 1) Presumably steps between consecutive values of x1 need to be very small to get good coverage. How would this be different from integrating the function, and are there no packages that do that? 2) What is the benefit of using simulation over prediction? $\endgroup$
    – Jade
    Commented Oct 25, 2022 at 16:17
  • 1
    $\begingroup$ 1) integrating a function between limits is just summing values of the function over the interval defined by the limits, with the accuracy increasing as you increase the number of points you evaluate the function at. But if the data has a natural time step, there's not much gained by going finer than that time step. 2) You want to simulate new data from the posterior; prediction would give you E(y) and you want actual counts not expected counts. $\endgroup$ Commented Oct 25, 2022 at 18:42

1 Answer 1

1
$\begingroup$

Assuming that x1 and x2 are standardised (so we can compare their coefficients directly), I would start by plotting the splines s(x1) and s(x2) on the same axes.

You can do this in base R, but there are some useful functions in the tidymv package. You may find this helpful: https://cran.r-project.org/web/packages/tidymv/vignettes/plot-smooths.html

$\endgroup$
1
  • $\begingroup$ Thanks, I'll look into that! I was, however, wondering about more formal ways in which to do this, such as e.g. integrating and comparing the area under each curve. Wondering if there are any packages that do this. I've edited my question to make this clearer. $\endgroup$
    – Jade
    Commented Oct 24, 2022 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.