Provides pre-implemented APIs to packages for joint density estimation. Optionally, custom fit and evaluation functions can be provided.

jd_method(package = NULL, fit_fun = NULL, eval_fun = NULL, cc = TRUE,
  ...)

Arguments

package

character string of the package name; so far, only "cctools", "kdevine", "np" are implemented.

fit_fun

only used if package = NULL; a function of type function(x, ...) that fits a joint density model on a data matrix x. The ... can be used for passing additional parameters.

eval_fun

only used if package = NULL; a function of type function(object, newdata, ...) that takes an object fitted by fit_fun and evaluates the density estimate on newdata.

cc

only used if package = NULL; if TRUE, discrete variables (and the class indicator) are made continuous with cctools::cont_conv(); only use FALSE when your fit_fun can handle discrete variables.

...

additional parameters passed to fit_fun.

Value

An object of class "jd_method".

Examples

# pre-implemented APIs cctools_method <- jd_method("cctools") kdevine_method <- jd_method("kdevine")
#> Error in jd_method("kdevine"): installed version of 'kdevine' is too old, please update with install.packages("kdevine")
np_method <- jd_method("np") # custom API (alternative implementation of kdevine method) require(kdevine)
#> Loading required package: kdevine
fit_kdevine <- function(x, ...) kdevine::kdevine(x, ...) eval_kdevine <- function(object, newdata, ...) kdevine::dkdevine(newdata, object) my_method <- jd_method(fit_fun = fit_kdevine, eval_fun = eval_kdevine, cc = FALSE)
#> Error in value[[3L]](cond): fit_fun doesn't work: Error in (1 - h) * qs[i]: non-numeric argument to binary operator