gavinsimpson / gratia

ggplot-based graphics and useful functions for GAMs fitted using the mgcv package
https://gavinsimpson.github.io/gratia/
Other
206 stars 28 forks source link

Second derivative error #251

Closed samlipworth closed 8 months ago

samlipworth commented 8 months ago

Hi There,

When following the example for derrivative_samples, using order=1 works but order =2 gives the following error:

fd_samp <- derivative_samples(m, data = ds, type = "central",
+                               focal = "x2", eps = 0.01, seed = 21, n_sim = 100,order=2)
Error in mutate():
ℹ In argument: ..fd = case_match(...).
Caused by error in case_match():
! ..1 (right) must have size 1, not size 60000.
Run rlang::last_trace() to see where the error occurred

Any idea what causes this?

gavinsimpson commented 8 months ago

Any idea what causes this?

Yep; my stupidity. I was misusing case_match(). And I'm pretty sure order = 1 was only giving forward finite differences because the type argument was being ignored.

gavinsimpson commented 8 months ago

This is now fixed in the GitHub version. Thanks for letting me know about this issue.