R/width_phi.R

Defines functions width_phi

Documented in width_phi

width_phi <- function(x, ignore_NaN = FALSE) {
  N0 <- x$values["N0"]; N <- x$values["N"]
  phi <- x$values["phi"];
  theta1 <- x$values["theta1"]; theta2 <- x$values["theta2"]
  int_names <- names(x$intervals)
  if (ignore_NaN) {
    usable <- filter(x$intervals, !is.nan(W_Lower)) %>%
      filter(!is.nan(S_Upper)) %>%
      filter(!is.nan(ILR_Upper))
    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(
      "N0" = N0, "N" = N, "phi" = phi,
      "theta1" = theta1, "theta2" = theta2, .before = TRUE
    )
}
BriceonWiley/IntegratedLikelihood.R documentation built on Aug. 21, 2020, 11 p.m.