diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2022-10-26 08:40:58 +0200 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2022-10-26 08:40:58 +0200 |
commit | 06df20703a9390692ab1ece3ae1702a71fff05ae (patch) | |
tree | 29b5adc2cc8dbb24ae70b5f2e0d95459dbc7497e /R/llhist.R | |
parent | 36dd8f47c147ed64874c88c9914a1ab4850a72cc (diff) |
Remove kernel density estimate from llhist
Diffstat (limited to 'R/llhist.R')
-rw-r--r-- | R/llhist.R | 20 |
1 files changed, 9 insertions, 11 deletions
@@ -1,8 +1,7 @@ #' Plot the distribution of log likelihoods from multistart objects #' -#' Produces a histogram of log-likelihoods, and an overlayed kernel density -#' estimate. In addition, the likelihood of the original fit is shown as -#' a red vertical line. +#' Produces a histogram of log-likelihoods. In addition, the likelihood of the +#' original fit is shown as a red vertical line. #' #' @param object The [multistart] object #' @param breaks Passed to [hist] @@ -10,9 +9,10 @@ #' @param main Title of the plot #' @param \dots Passed to [hist] #' @seealso [multistart] -#' @importFrom KernSmooth bkde #' @export -llhist <- function(object, breaks = "Sturges", lpos = "topleft", main = "", ...) { +llhist <- function(object, breaks = "Sturges", lpos = "topleft", main = "", + ...) +{ oldpar <- par(no.readonly = TRUE) on.exit(par(oldpar, no.readonly = TRUE)) @@ -26,19 +26,17 @@ llhist <- function(object, breaks = "Sturges", lpos = "topleft", main = "", ...) } ll <- stats::na.omit(sapply(object, llfunc)) - kde <- KernSmooth::bkde(ll) par(las = 1) h <- hist(ll, freq = TRUE, - xlim = range(kde$x), xlab = "", main = main, ylab = "Frequency of log likelihoods", breaks = breaks, ...) freq_factor <- h$counts[1] / h$density[1] - lines(kde$x, freq_factor * kde$y) + abline(v = logLik(attr(object, "orig")), col = 2) + legend(lpos, inset = c(0.05, 0.05), bty = "n", - lty = 1, col = c(2, 1), - legend = c("original log likelihood", - "kernel density estimate")) + lty = 1, col = c(2), + legend = "original fit") } |