subsample | R Documentation |
The function will take a function that has an occurrence dataset as an argument, and reruns it iteratively on the subsets of the dataset.
subsample( x, q, tax = NULL, bin = NULL, FUN = divDyn, coll = NULL, iter = 50, type = "cr", keep = NULL, rem = NULL, duplicates = TRUE, output = "arit", useFailed = FALSE, FUN.args = NULL, na.rm = FALSE, counter = TRUE, ... )
x |
( |
q |
( |
tax |
( |
bin |
( |
FUN |
( |
coll |
( |
iter |
( |
type |
( |
keep |
( |
rem |
( |
duplicates |
( |
output |
( |
useFailed |
( |
FUN.args |
( |
na.rm |
( |
counter |
( |
... |
arguments passed to |
The subsample
function implements the iterative framework of the sampling standardization procedure.
The function 1. takes the dataset x
, 2. runs function FUN
on the dataset and creates a container for results of trials
3. runs one of the subsampling trial functions (e.g. subtrialCR
) to get a subsampled 'trial dataset'
4. runs FUN
on the trial dataset and
5. averages the results of the trials for a simple output of step 4. such as vector
s, matrices
and data.frames
. For averaging, the vectors
and matrices
have to have the same output dimensions in the subsampling, as in the original object. For data.frames
, the bin-specific information have to be in rows and the bin
numbers have to be given in a variable bin
in the output of FUN
.
For a detailed treatment on what the function does, please see the vignette ('Handout to the R package 'divDyn' v0.5.0 for diversity dynamics from fossil occurrence data'). Currently the Classical Rarefaction ("cr"
, Raup, 1975), the occurrence weighted by-list subsampling ("oxw"
, Alroy et al., 2001) and the Shareholder Quorum Subsampling methods are implemented ("sqs"
, Alroy, 2010).
References:
Alroy, J., Marshall, C. R., Bambach, R. K., Bezusko, K., Foote, M., Fürsich, F. T., … Webber, A. (2001). Effects of sampling standardization on estimates of Phanerozoic marine diversification. Proceedings of the National Academy of Science, 98(11), 6261-6266.
Alroy, J. (2010). The Shifting Balance of Diversity Among Major Marine Animal Groups. Science, 329, 1191-1194. https://doi.org/10.1126/science.1189910
Raup, D. M. (1975). Taxonomic Diversity Estimation Using Rarefaction. Paleobiology, 1, 333-342. https: //doi.org/10.2307/2400135
Either a list of replicates or an object matching the class of FUN
.
data(corals) data(stages) # Example 1-calculate metrics of diversity dynamics dd <- divDyn(corals, tax="genus", bin="stg") rarefDD<-subsample(corals,iter=30, q=50, tax="genus", bin="stg", output="dist", keep=95) # plotting tsplot(stages, shading="series", boxes="sys", xlim=c(260,0), ylab="range-through diversity (genera)", ylim=c(0,230)) lines(stages$mid, dd$divRT, lwd=2) shades(stages$mid, rarefDD$divRT, col="blue") legend("topleft", legend=c("raw","rarefaction"), col=c("black", "blue"), lwd=c(2,2), bg="white") # Example 2-SIB diversity # draft a simple function to calculate SIB diversity sib<-function(x, bin, tax){ calc<-tapply(INDEX=x[,bin], X=x[,tax], function(y){ length(levels(factor(y))) }) return(calc[as.character(stages$stg)]) } sibDiv<-sib(corals, bin="stg", tax="genus") # calculate it with subsampling rarefSIB<-subsample(corals,iter=25, q=50, tax="genus", bin="stg", output="arit", keep=95, FUN=sib) rarefDD<-subsample(corals,iter=25, q=50, tax="genus", bin="stg", output="arit", keep=95) # plot tsplot(stages, shading="series", boxes="sys", xlim=c(260,0), ylab="SIB diversity (genera)", ylim=c(0,230)) lines(stages$mid, rarefDD$divSIB, lwd=2, col="black") lines(stages$mid, rarefSIB, lwd=2, col="blue") # Example 3 - different subsampling types with default function (divDyn) # compare different subsampling types # classical rarefaction cr<-subsample(corals,iter=25, q=20,tax="genus", bin="stg", output="dist", keep=95) # by-list subsampling (unweighted) - 3 collections UW<-subsample(corals,iter=25, q=3,tax="genus", bin="stg", coll="collection_no", output="dist", keep=95, type="oxw", xexp=0) # occurrence weighted by list subsampling OW<-subsample(corals,iter=25, q=20,tax="genus", bin="stg", coll="collection_no", output="dist", keep=95, type="oxw", xexp=1) SQS<-subsample(corals,iter=25, q=0.4,tax="genus", bin="stg", output="dist", keep=95, type="sqs") # plot tsplot(stages, shading="series", boxes="sys", xlim=c(260,0), ylab="range-through diversity (genera)", ylim=c(0,100)) shades(stages$mid, cr$divRT, col="red") shades(stages$mid, UW$divRT, col="blue") shades(stages$mid, OW$divRT, col="green") shades(stages$mid, SQS$divRT, col="cyan") legend("topleft", bg="white", legend=c("CR (20)", "UW (3)", "OW (20)", "SQS (0.4)"), col=c("red", "blue", "green", "cyan"), lty=c(1,1,1,1), lwd=c(2,2,2,2))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.