R/getSpeciesDiversity.R

Defines functions getSpeciesdiversity

Documented in getSpeciesdiversity

#' Calculates how many species compose the response of each taxon.
#'
#' Calculates how many species compose the response of each taxon.
#'
#' @param x A \code{\link{crestObj}} generated by the
#'        \code{\link{crest.reconstruct}}, \code{\link{loo}} or
#'        \code{\link{crest}} functions.
#' @return Return the number of composing species of each taxon.
#' @export
#' @examples
#' data(reconstr)
#' getSpeciesdiversity(reconstr)

getSpeciesdiversity <- function(x) {
    if(base::missing(x)) x

    if(!is.crestObj(x)) {
        cat('\nx should be a crestObj.\n\n')
        return(invisible(NA))
    }

    div <- rep(0, length(x$inputs$taxa.name))
    names(div) <- x$inputs$taxa.name

    for(tax in x$inputs$taxa.name) {
        if(is.list(x$modelling$pdfs[[tax]][[1]])) {
           div[tax] <- length(x$modelling$pdfs[[tax]][[1]]$pdfsp)
        }
    }

    div <- sort(div)
    div
}

Try the crestr package in your browser

Any scripts or data that you put into this service are public.

crestr documentation built on Jan. 6, 2023, 5:23 p.m.