R/stress_test.R

Defines functions stress_test_plot stress_test

Documented in stress_test stress_test_plot

#' Calculates and plots stress
#' Window and step size can be specified by user
#'
#' @param data A dataframe containing taxon wad values per tube
#' @param light A dataframe containing light isotope adjusted taxon wad values averaged across all tubes
#' @export

stress_test = function(data, light, window = 0.1, step = 0.1){
  require(tidyverse)
  f = seq(0, 1 - window, by = step)
  df = data.frame()
  for (i in f) {
    j = i + window
    S = tube_shift_heavy(data = data, light = light, high = j, low = i) %>%
      filter(inactive == TRUE) %>%
      summarize(S = mean(taxon_corrected_stress)) %>%
      pull()
    df = rbind(df, data.frame("low" = i, "high" = j, "stress" = S))

  }
  df = arrange(df, stress)
  message("lowest stress window ", df[1,1], "-", df[1,2])
  return(df)
}

#' Stress test plot
#' @param stress_test_results Dataframe output of stress_test function
#' @export

stress_test_plot = function(stress_test_results){
  require(tidyverse)
  stress_test_results %>%
    ggplot(aes(x = low, y = stress)) +
    theme_classic() +
    geom_point()
}
rh482/sipTA documentation built on Nov. 3, 2020, 3:38 a.m.