diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2022-09-16 21:06:54 +0200 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2022-09-16 21:06:54 +0200 |
commit | fd205e13061de8abc595d266f3b0c7650773d442 (patch) | |
tree | 73fc6d4e33f758bec1c45189e39d1533f186a99b /R/llhist.R | |
parent | afe466d01ccf60a9746616ebc0e06f0383aa814f (diff) |
Improve multistart documentation, bugfix
- Split out llhist and parhist documentation
- Add example code for multistart
- Create a multistart vignette, because the example code fails when run
by pkgdown
- Fix multistart for the case of mkin transformations in the saem fit
Diffstat (limited to 'R/llhist.R')
-rw-r--r-- | R/llhist.R | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/R/llhist.R b/R/llhist.R new file mode 100644 index 00000000..6a6d93cd --- /dev/null +++ b/R/llhist.R @@ -0,0 +1,30 @@ +#' 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. +#' +#' @param object The [multistart] object +#' @param breaks Passed to [hist] +#' @param lpos Positioning of the legend. +#' @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 = "", ...) { + ll <- sapply(object, logLik) + kde <- KernSmooth::bkde(ll) + 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")) +} |