Nothing
#' Prepare data for evaluation
#'
#' \code{prep_data()} formats and arranges the initial data so that it can be
#' readily used by the other functions in the package. The function first gets
#' the species names and the number of samples for each species from the input
#' data frame. Then, it permutes the sampling efforts and calculates the pseudo-F
#' statistic and the mean squares for each permutation. Finally, it returns a
#' data frame with the permutations, pseudo-F statistic, and mean squares.
#'
#' @param data Data frame with species names (columns) and samples (rows)
#' information. The first column should indicate the site to which the sample
#' belongs, regardless of whether a single site has been sampled.
#' @param type Nature of the data to be processed. It may be presence / absence
#' ("P/A"), counts of individuals ("counts"), or coverage ("cover")
#' @param Sest.method Method for estimating species richness. The function
#' specpool is used for this. Available methods are the incidence-based Chao
#' "chao", first order jackknife "jack1", second order jackknife "jack2" and
#' Bootstrap "boot". By default, the "average" of the four estimates is used.
#' @param cases Number of data sets to be simulated.
#' @param N Total number of samples to be simulated in each site.
#' @param sites Total number of sites to be simulated in each data set.
#' @param n Maximum number of samples to consider.
#' @param m Maximum number of sites.
#' @param k Number of resamples the process will take. Defaults to 50.
#' @param transformation Mathematical function to reduce the weight of very
#' dominant species: 'square root', 'fourth root', 'Log (X+1)', 'P/A', 'none'
#' @param method The appropriate distance/dissimilarity metric (e.g. Gower,
#' Bray–Curtis, Jaccard, etc). The function [vegan::vegdist()] is called for
#' that purpose.
#' @param dummy Logical. It is recommended to use TRUE in cases where there are
#' observations that are empty.
#' @param useParallel Logical. Perform the analysis in parallel? Defaults to TRUE.
#' @param model Select the model to use. Options, so far, are 'single.factor' and
#' 'nested.symmetric'.
#'
#' @return \code{prep_data()} returns an object of class "ecocbo_data".
#'
#' An object of class "ecocbo_data" is a list containing: \code{$Results}, a data
#' frame that lists the estimates of pseudoF for \code{simH0} and \code{simHa}
#' that can be used to compute the statistical power for different sampling
#' efforts, as well as the square means necessary for calculating the variation
#' components.
#'
#' @author Edlin Guerra-Castro (\email{edlinguerra@@gmail.com}), Arturo Sanchez-Porras
#'
#' @references Underwood, A. J. (1997). Experiments in ecology: their logical
#' design and interpretation using analysis of variance. Cambridge university
#' press.
#' @references Underwood, A. J., & Chapman, M. G. (2003). Power, precaution,
#' Type II error and sampling design in assessment of environmental impacts.
#' Journal of Experimental Marine Biology and Ecology, 296(1), 49-70.
#'
#' @seealso
#' [sim_beta()]
#' [plot_power()]
#' [sim_cbo()]
#' [scompvar()]
#'
#' @aliases prepdata
#'
#' @export
#' @import parallel
#' @import doParallel
#' @import foreach
#' @importFrom SSP assempar simdata
#'
#' @examples
#' \donttest{
#' simResults <- prep_data(data = epiDat, type = "counts", Sest.method = "average",
#' cases = 5, N = 100, sites = 10,
#' n = 5, m = 5, k = 30,
#' transformation = "none", method = "bray",
#' dummy = FALSE, useParallel = FALSE,
#' model = "single.factor")
#' }
#' simResults
#'
prep_data <- function(data, type = "counts", Sest.method = "average",
cases = 5, N = 100, sites = 10,
n, m, k = 50,
transformation = "none", method = "bray",
dummy = FALSE, useParallel = TRUE,
model = "single.factor"){
# Check the inputs ----
if (n > N){stop("'n' must be equal or less than 'N' on simulated data")}
if(ceiling(n) != floor(n)){stop("n must be integer")}
if(n <= 1){stop("n must be larger than 1")}
if (m > sites){stop("'m' must be equal or less than 'sites' on simulated data")}
if(ceiling(m) != floor(m)){stop("m must be integer")}
if(m <= 1){stop("m must be larger than 1")}
# The function to work with depends on the selected model
Results <- if(model == "single.factor"){
prep_data_single(data, type, Sest.method, cases, N,
sites, n, m, k, transformation, method,
dummy, useParallel)
} else if(model == "nested.symmetric"){
prep_data_nestedsymmetric(data, type, Sest.method, cases, N,
sites, n, m, k, transformation, method,
dummy, useParallel)
}
return(Results)
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.