Skip to content

Commit

Permalink
Adapt calc_div and calc_comm_div to calc_SPIE and calc_PIE
Browse files Browse the repository at this point in the history
- both functions get the replace argument
- use calc_SPIE when index="S_PIE
- documentation

#258 (comment)
  • Loading branch information
T-Engel committed Dec 10, 2020
1 parent 242625e commit 8f479b2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
17 changes: 10 additions & 7 deletions R/mobr_boxplots.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ boot_sample_groups = function(abund_mat, index, effort, extrapolate, return_NA,
#' @examples
#' data(inv_comm)
#' calc_div(inv_comm[1, ], 'S_n', effort = c(5, 10))
calc_div = function(x, index, effort, rare_thres = 0.05, ...) {
calc_div = function(x, index, effort, rare_thres = 0.05, replace = F, ...) {
if (index == 'N') out = sum(x)
if (index == 'S') out = sum(x > 0)
if (index == 'S_n') out = rarefaction(x, method = 'IBR', effort = effort, ...)
if (index == 'PIE') out = calc_PIE(x, ENS = FALSE)
if (index == 'S_PIE') out = calc_PIE(x, ENS = TRUE)
if (index == 'PIE') out = calc_PIE(x, replace = replace)
if (index == 'S_PIE') out = calc_SPIE(x, replace = replace)
if (index == 'f_0') out = calc_div(x, 'S_asymp') - calc_div(x, 'S')
if (index == 'S_asymp') {
S_asymp = try(calc_chao1(x))
Expand Down Expand Up @@ -272,7 +272,9 @@ calc_div = function(x, index, effort, rare_thres = 0.05, ...) {
#' \code{alpha} scales.
#' } Defaults to all three scales: \code{c('alpha', 'gamma', 'beta')}
#'
#'
#' @param replace Used for \code{PIE} and \code{SPIE}. If TRUE, sampling with replacement is used. Otherwise,
#' sampling without replacement (default).
#'
#' @details This function is primarily intended as auxiliary function used in
#' \code{\link{get_mob_stats}}, but can be also used directly for data exploration.
#'
Expand Down Expand Up @@ -303,7 +305,8 @@ calc_comm_div = function(abund_mat, index, effort = NA,
extrapolate = TRUE,
return_NA = FALSE, rare_thres = 0.05,
scales = c('alpha', 'gamma', 'beta'),
coverage = TRUE) {
coverage = TRUE,
replace = FALSE) {

# store each calculated index into its own data.frame in a list
out = vector('list', length = length(index))
Expand All @@ -314,11 +317,11 @@ calc_comm_div = function(abund_mat, index, effort = NA,
if (any(c('alpha','beta') %in% scales))
alpha = apply(abund_mat, 1, calc_div, index[i], effort, rare_thres,
extrapolate = extrapolate, return_NA = return_NA,
quiet = TRUE)
quiet = TRUE, replace = replace)
if (any(c('gamma', 'beta') %in% scales))
gamma = calc_div(colSums(abund_mat), index[i], effort, rare_thres,
extrapolate = extrapolate, return_NA = return_NA,
quiet = TRUE)
quiet = TRUE, replace = replace)
if ('beta' %in% scales) {
# compute beta
if (index[i] == 'S_n' & length(effort) > 1) {
Expand Down
6 changes: 5 additions & 1 deletion man/calc_comm_div.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/calc_div.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8f479b2

Please sign in to comment.