R/ignore/old_functions.R

Defines functions ses_overlap

# Functions to be ignored in build, but include in repo just in case
# ------------------------------------------------------------------

# Function to extract null model quantiles from the overlap stats generated by my tweaked QTstats function.

ses_overlap <- function(ts, qs = c(0.025, 0.975)) {
  ses <- ses_lower <- ses_upper <- raw_lower <- raw_upper <- matrix(NA, nrow=nrow(ts$overlaps), ncol=ncol(ts$overlaps))

  for (i in 1:nrow(ts$overlaps)) {
    for (j in 1:ncol(ts$overlaps)) {
      if(!is.na(ts$overlaps[i,j])) {
        obs <- ts$overlaps[i,j]
        nullvals <- na.omit(ts$overlaps_nm[, j, i])
        ses[i,j] <- (obs - mean(nullvals))/sd(nullvals)
        ses_lower[i,j] <- (quantile(nullvals, probs=qs[1]) - mean(nullvals))/sd(nullvals)
        ses_upper[i,j] <- (quantile(nullvals, probs=qs[2]) - mean(nullvals))/sd(nullvals)
        raw_lower[i,j] <- quantile(nullvals, probs=qs[1])
        raw_upper[i,j] <- quantile(nullvals, probs=qs[2])
      }
    }
  }

  return(list(ses=ses, ses_lower=ses_lower, ses_upper=ses_upper, raw_lower=raw_lower, raw_upper=raw_upper))
}
NEON-biodiversity/Ostats documentation built on Nov. 21, 2024, 4:01 a.m.