Skip to content

Commit

Permalink
richardson by default
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Jul 16, 2023
1 parent 7e62813 commit efb42b8
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 44 deletions.
16 changes: 10 additions & 6 deletions R/get_jacobian.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# adapted from the numDeriv package for R by Paul Gilbert published under GPL2 license

get_jacobian <- function(func, x) {
numDeriv_args <- getOption("marginaleffects_numDeriv", default = NULL)
numDeriv_args <- getOption("marginaleffects_numDeriv", default = "richardson")

# forward finite difference (faster)
if (is.null(numDeriv_args)) {
Expand All @@ -19,11 +19,15 @@ get_jacobian <- function(func, x) {

# numDeriv (more accurate)
} else {
insight::check_if_installed("numDeriv")
numDeriv_args[["func"]] <- func
numDeriv_args[["x"]] <- x
ndFUN <- get("jacobian", asNamespace("numDeriv"))
df <- do.call(ndFUN, numDeriv_args)
if (identical(numDeriv_args, "richardson")) {
df <- get_jacobian_richardson(func, x)
} else {
insight::check_if_installed("numDeriv")
numDeriv_args[["func"]] <- func
numDeriv_args[["x"]] <- x
ndFUN <- get("jacobian", asNamespace("numDeriv"))
df <- do.call(ndFUN, numDeriv_args)
}
}

return(df)
Expand Down
28 changes: 14 additions & 14 deletions inst/tinytest/_tinysnapshot/plot_slopes_continuous.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit efb42b8

Please sign in to comment.