Skip to content

gratia::derivatives of factor smooth #362

@vrest-png

Description

@vrest-png

0

I fit a hierarchical generalized additive model with a sum to zero smooth interactions (bs="sz"). I would like to take the first derivative and plot the simultaneous confidence interval in order to detect significant periods of change. My goal is to do this for both the global term and also the site-specific deviations from the global term.

Using gratia::derivatives I'm able to achieve this. However, I get the following error when taking the derivative of the site year factor smooth:


Error in `quos()`:
! The LHS of `:=` must be a string, not a character vector.
Run `rlang::last_trace()` to see where the error occurred.

Model:
mod <- gam( TP ~ s(Year, k = 10) + # global smooth s(Year, Site, bs = "sz", k = 10), # constrained factor smooth (includes site mean shifts) data = my_data, family = tw(link = "log"), method = "REML" )

Derivative of site year factor smooth

deriv_global <- derivatives( mod, term = "s(Year,Site)", data = new_data_global, order = 1, type = "central", interval = "simultaneous", n_sim = 10000, level = 0.95, unconditional = TRUE )
Error:


Error in `quos()`:
! The LHS of `:=` must be a string, not a character vector.
Run `rlang::last_trace()` to see where the error occurred.

Checking smoother terms


smooths(mod)
[1] "s(Year)"      "s(Year,Site)"

I believe the error is saying that my factor smooth in the gratia::derivatives function is not labeled the same as the model, but this is not the case. I have tried specifying the term with and without quotes. I've seen work out there reporting derivatives of the site smooth interaction so this should be possible.

I have tried this with several datasets, and restarted R, but the problem is consistent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions