Function that creates a log likelihood function given a density function density.

likelihood(density, ...)

Arguments

density density function used other options

Value

A function that is the log likelihood function from density function density.

Details

The log likelihood is the log of a function of parameters given the data.

Examples

likelihood(dnorm, x = rnorm(100))#> function (mean = 0, sd = 1, x = rnorm(100), log = FALSE)
#> {
#>     form <- map(set_names(ls(), ls()), function(x) {
#>         tryCatch(env_get(nm = x, inherit = TRUE), error = function(cnd) {
#>             NULL
#>         })
#>     })
#>     form <- form[!sapply(form, is.null)]
#>     if (log == TRUE) {
#>         value <- Reduce(+, rlang::invoke(map, c(.x = list(x),
#>             .f = expr(function (x, mean = 0, sd = 1, log = FALSE)
#>             .Call(C_dnorm, x, mean, sd, log)), form[!(names(form) %in%
#>                 "x")])))
#>     }
#>     else if (log == FALSE) {
#>         value <- Reduce(*, rlang::invoke(map, c(.x = list(x),
#>             .f = expr(function (x, mean = 0, sd = 1, log = FALSE)
#>             .Call(C_dnorm, x, mean, sd, log)), form[!(names(form) %in%
#>                 "x")])))
#>     }
#>     else {
#>         stop(paste0("The log value: ", log, " will not work. Please specify either TURE or FALSE"))
#>     }
#>     value
#> }
#> <environment: 0x55a2930>