R/RcppExports.R

Defines functions webFromNicheModel likelihoodMC_core interaction_proba prodNorm getNullOne getNull

Documented in getNull getNullOne prodNorm webFromNicheModel

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' @name getNull
#' @title getNull
#'
#' @author
#' Kevin Cazelles
#'
#' @description Wrapper around the `null` function of Armadillo library
#' that finds the orthonormal basis of the null space of matrix A. Note that
#' this wrapper do not allow the user to use any other parameters the
#' original function can.
#'
#' @param A a matrix.
#' @param B a matrix (an orthogonal basis of A).
#' @param V a vector.
#' @param nbsp an integer (from an ecological standpoint, a number
#' of species).
#'
#' @return The null basis of `A`.
#'
#' @importFrom Rcpp evalCpp
#' @export
getNull <- function(A) {
    .Call('_alien_getNull', PACKAGE = 'alien', A)
}

#' @describeIn getNull Special case of `getNull` for which the orthonormal
#' basis of the unit vector is required.
#' @export
getNullOne <- function(nbsp) {
    .Call('_alien_getNullOne', PACKAGE = 'alien', nbsp)
}

#' @describeIn getNull Matrix product that requires to normalise one vector 
#' (see [fitIMC()]).
#' @export
prodNorm <- function(nbsp, B, V) {
    .Call('_alien_prodNorm', PACKAGE = 'alien', nbsp, B, V)
}

interaction_proba <- function(M1_i, M2_j, cent1_i, cent2_j, Lambda, m) {
    .Call('_alien_interaction_proba', PACKAGE = 'alien', M1_i, M2_j, cent1_i, cent2_j, Lambda, m)
}

likelihoodMC_core <- function(netObs, M1, M2, cent1, cent2, Lambda, m) {
    .Call('_alien_likelihoodMC_core', PACKAGE = 'alien', netObs, M1, M2, cent1, cent2, Lambda, m)
}

#' @name webFromNicheModel
#'
#' @title Generate a web using the niche model.
#'
#' @description
#' This function is an implementation of the niche model which generates
#' food webs based on 1- a number of species, 2- a niche axis and 3- a value of
#' comnectance.
#'
#' @author
#' Kevin Cazelles
#'
#' @param nbsp An integer giving the number of species considered.
#' @param connec A real positive between 0 and .5 indicating the connectance
#' of the network to be generated.
#' @param connect_all Logical. If TRUE, then all species in the network have a
#' least one prey (but the niche with the lowest niche value).
#' @param unbias Logical. If TRUE, then the first species may not be a basal species.
#' @param niche A vector real positive between 0 and 1 standing for the niche axis.
#' Default is set to \code{NULL}, in such case the niche axis is automatically generated.
#'
#' @return A logical matrix describing pairwise interactions. A given line
#' describes the diet of a given species while a column decribes the set of
#' predator associated to a particular species.
#'
#' @details
#' Three remarks. First, according to Williams and Martinez (2000),
#' the species with the lowest niche value is considered as a basal species and
#' therefore cannot feed upon another species. This introduces a slight bias (\emph{e.g} the
#' expected connectance is lower than the expected values \code{connec}). Second,
#' forcing all the species to be connected introduces another biais (on
#' connectance values) as they tends to be more connected than expected.
#' Third, if one uses its own customed niche axis, values should be between 0 and
#' and 1 and the expected connectance (\code{connec}) can vary significantly if the
#' distribution of niche values differ from the uniform distribution used in
#' Williams and Martinez (2000).
#'
#' @references
#' Williams, R.J. and Martinez, N.D. (2000) Simple rules yield complex food webs.
#' \emph{Nature}, 404:180–183.
#'
#' @export
NULL

#' @importFrom Rcpp evalCpp
#'
webFromNicheModel <- function(nbsp, connec, connect_all = FALSE, unbias = FALSE, niche = NULL) {
    .Call('_alien_webFromNicheModel', PACKAGE = 'alien', nbsp, connec, connect_all, unbias, niche)
}
TheoreticalEcosystemEcology/alien documentation built on Dec. 25, 2021, 5:57 p.m.