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, log = TRUE) #> { #> unevalcallparams <- as.list(match.call())[-1] #> params <- lapply(unevalcallparams, function(y) { #> eval(y, parent.frame(n = 3)) #> }) #> if ("x" %in% names(params)) { #> x <- params$x #> params <- params[!(names(params) == "x")] #> } #> else { #> x <- x #> } #> if ("log" %in% names(params)) { #> log <- params$log #> params <- params[!(names(params) == "log")] #> } #> else { #> log <- log #> } #> if (log == TRUE) { #> value <- Reduce(`+`, do.call(plyr::llply, args = c(list(.data = x, #> .fun = density, log = TRUE), lazyeval::lazy_eval(dots), #> params))) #> } #> else { #> value <- Reduce(`*`, do.call(plyr::llply, args = c(list(.data = x, #> .fun = density, log = FALSE), lazyeval::lazy_eval(dots), #> params))) #> } #> value #> } #> <environment: 0x6bf8230>