Testing for non-linear slopes #1193
-
Hi Vincent, Thank you for the tireless work on the marginaleffects package! I have been recommending it fervently to all my colleagues working in R. I've been trying recently to crack a problem that is probably trivial to more statistically knowledgable people. I think marginaleffects could be used nicely for that. I want to fit a GAM model on longitudinal data to allow for non-linear interactions between time and my continuous predictor of interest. Having done that, I want to see whether the slope for my continous variable is truly non-linear across time or if it could be described well enough with only a linear trend. I would ideally end up with a separate p-value for the linear trend and the non-linear trend. Any idea how I could obtain those using marginaleffects? I assume it would be some combination of avg_slopes and the hypothesis function, but in the many useful example you document I could not find one that gets this particular job done. Thank you sincerely! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Glad you like the package! I would not use |
Beta Was this translation helpful? Give feedback.
-
Thanks! Got it, then I would get each conditional slope and I could test them all individually against each other. A follow-up question which might be a bit vague - would you know if theres a way to test with the |
Beta Was this translation helpful? Give feedback.
-
To determine whether or not the slope is "significantly" nonlinear, one only needs to examine the effective degree of freedom (edf) of the smooth term provided by the summary function when used on a mgcv::gam() object. |
Beta Was this translation helpful? Give feedback.
Sounds like you're looking for a second order derivative. There's currently no way to compute this easily with
marginaleffects
, unfortunately.You could look at the "sequential" option for
hypothesis
, but that's still comparing pairs.