1
$\begingroup$

I am asking a question akin to this one: https://stackoverflow.com/questions/71884457/what-does-the-y-axis-effect-mean-after-using-gratiadraw-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, 2L, 2L, 2L, 2L, 2L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L), levels = c("n", "y"), class = c("ordered", 
"factor")), Landings = c(48974, 16933, 18389, 16433, 5720, 3775, 
1388, 97109, 148609, 104267, 77454, 128938, 108096, 126957, 102396, 
16165, 59423, 2892, 4728, 3783, 4785, 11359, 5323, 6106, 167, 
568, 480, 2208, 4378, 1908), year = c(2007, 2009, 2011, 2013, 
2015, 2018, 2007, 2007, 2007, 2012, 2015, 2018, 2007, 2007, 2012, 
2015, 2018, 2008, 2010, 2006, 2008, 2011, 2008, 2011, 2007, 2010, 
2007, 2014, 2015, 2014)), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 
20L, 21L, 22L, 23L, 24L, 25L, 26L, 28L, 29L, 30L, 31L), class = "data.frame")

My code looks like this:

library(mgcv)
library(gratia)
gam<-gam(Landings~s(year)+spreg,data=df)
draw(parametric_effects(gam))

Partial effect plot looks like this:

enter image description here

This is what summary(gam) looks like:

Family: gaussian 
Link function: identity 

Formula:
Landings ~ s(year) + spreg

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)  
(Intercept)    30460      11178   2.725   0.0112 *
spreg.L       -16964      15961  -1.063   0.2974  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Approximate significance of smooth terms:
          edf Ref.df     F p-value
s(year) 1.374  1.652 0.229   0.798

R-sq.(adj) =  -0.00914   Deviance explained = 7.35%
GCV = 2.6732e+09  Scale est. = 2.3726e+09  n = 30

I want to report these partial effect plots for parametric terms but I am having trouble finding a good description of the partial effect plots for fixed effects. Is this the estimate and 95% credible interval like the smooth partial effect plots?

$\endgroup$
10
  • $\begingroup$ The value for the y group is literally the estimated value for the y term shown in the output from summary(), and the interval is based on the SE shown in that output too. The value for n is 0 as it is the reference level and hence it has 0 partial effect as the intercept term represents this group and the partial effects shown are for deviations from the intercept. I don't find these plots that useful, but plot.gam showed them so draw() does as it is a ggplot-based alternative to plot.gam. $\endgroup$ Commented Mar 30, 2023 at 20:45
  • $\begingroup$ Thanks Gavin. That is what I was thinking. I've noticed that if the fixed effect is an ordered factor it looks as though the partial effect estimates in relation to zero effect instead of in relation to the reference level. (I'll edit the post to show that.) Am I right to assume that the estimate there is in relation to zero effect? $\endgroup$ Commented Mar 31, 2023 at 16:47
  • $\begingroup$ So spreg is the ordered factor? Can you add the output from summary(gam) to your question? Or is the plot shown based on the subset of data you provided? If the latter I can take a look directly myself tomorrow $\endgroup$ Commented Apr 1, 2023 at 1:38
  • $\begingroup$ @GavinSimpson this is just a small subset of a much larger data set that I put on here. I added the summary(gam) to the question. $\endgroup$ Commented Apr 3, 2023 at 20:24
  • $\begingroup$ spreg is the ordered factor. $\endgroup$ Commented Apr 3, 2023 at 20:25

1 Answer 1

0
$\begingroup$

With ordered factors, the intercept represents the expected value of the response at the mean of the factor's levels; in the snippet of data, this is 1.5, and the remaining coefficients represent polynomials of the factor levels. In the model shown, there is only a linear polynomial term because there are two levels.

With this kind of factor, the output from parametric_effect() is the model estimate (partial effect) for each factor level:

r$> ds <- data_slice(m, spreg = evenly(spreg))
r$> fitted_values(m, data = ds, exclude = c("(Intercept)", "s(year)"))          
# A tibble: 2 × 6
  spreg  year  fitted     se   lower  upper
  <ord> <dbl>   <dbl>  <dbl>   <dbl>  <dbl>
1 n      2010  11996. 11286. -10124. 34115.
2 y      2010 -11996. 11286. -34115. 10124.

which, because there is only a linear polynomial contrast, the two estimates equally deviate from the intercept (the mean of the levels) in opposite directions (hence the sign on the fitted value).

$\endgroup$

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