R/getCIs.R

Defines functions getSEFromBootStats

Documented in getSEFromBootStats

#' getSEFromBootStats
#'
#' @param l a list of vectors or matrices
#'
#' @return a dataframe containing the confidence intervals
#' @export

getSEFromBootStats <- function(l) {
  l1 <- l[[1]]
  if (class(l1) == "matrix" || class(l1) == "data.frame") {
    ncols <- ncol(l1)
    nrows <- nrow(l1)
    map_dfr(1:ncols, function(i) {
      vals <- map_dfc(.x = l, .f = function(mat) {mat[,i]})
      SEs <- apply(vals, 1, sd) %>% tibble::enframe(name = NULL)
      colnames(SEs) <- "SE"
      SEs$row <- 1:nrows
      SEs$col <- i
      return(SEs)
    })
  } else if (class(l1) == "numeric" || class(l1) == "integer") {
    vals <- map_dfc(.x = l, .f = identity)
    SEs <- apply(vals, 1, sd) %>% tibble::enframe(name = NULL)
    colnames(SEs) <- "SE"
    SEs$index <- 1:length(l1)
    return(SEs)
  }
}
Timothy-Barry/coproanalysis documentation built on Feb. 12, 2020, 7:33 a.m.