R/coverage_p.R

Defines functions coverage_p

coverage_p <- function(x, ignore_NaN = FALSE) {
  N <- x$counts["N"]
  p <- x$proportions["p"]
  ks <- x$proportions[-c(1:3)]
  int_names <- names(x$intervals)
  if (ignore_NaN) {
    usable <- filter(x$intervals, !is.nan(mW_Lower))
    lower <- select(usable, str_subset(int_names, "Lower"))
    upper <- select(usable, str_subset(int_names, "Upper"))
  } else {
    lower <- select(x$intervals, str_subset(int_names, "Lower"))
    upper <- select(x$intervals, str_subset(int_names, "Upper"))
  }
  coverages <- map2(lower, upper, ~ map2(.x, .y, ~ between(p, .x, .y))) %>%
    transpose() %>%
    bind_rows() %>%
    summarise_all(mean)
  names(coverages) <- str_remove(names(coverages), "[_]?Lower[_]?")
  coverages %>%
    add_column("N" = N, "p" = p, .before = TRUE)
}
BriceonWiley/IntegratedLikelihood.R documentation built on Aug. 21, 2020, 11 p.m.