R/width_p.R

Defines functions width_p

width_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"))
  }
  widths <- map2(lower, upper, ~ map2(.x, .y, ~ (.y - .x))) %>%
    transpose() %>%
    bind_rows() %>%
    summarise_all(mean)
  names(widths) <- str_remove(names(widths), "[_]?Lower[_]?")
  widths %>%
    add_column("N" = N, "p" = p, .before = TRUE)
}
BriceonWiley/IntegratedLikelihood.R documentation built on Aug. 21, 2020, 11 p.m.