R/RcppExports.R

# This file was generated by Rcpp::compileAttributes
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Compute mean fitness under stabilizing selection
#' @param zbar mean trait prior to selection
#' @param theta enironmental optimum
#' @param oz2 strength of stabilizing selection
#' @param gamma 1/(oz2 + Vz2), with Vz2 phenotypic variance
#' @details IN USE
#' @export
Log_W_bar <- function(zbar, theta, oz2, gamma) {
    .Call('phenoecosim_Log_W_bar', PACKAGE = 'phenoecosim', zbar, theta, oz2, gamma)
}

#' Compute mean fitness under stabilizing selection
#' @inheritParams Log_W_bar
#' @param LOG (=TRUE) whether to return the log of fitness
#' @details IN USE
#' @export
W_bar <- function(zbar, theta, oz2, gamma, LOG) {
    .Call('phenoecosim_W_bar', PACKAGE = 'phenoecosim', zbar, theta, oz2, gamma, LOG)
}

#' Compute population growth rate under stabilizing selection and no regulation
#' @param R0 basic reproductive number
#' @param Wbar average fitness
#' @param N number of individuals in this generation
#' @details Assumes ceiling population regulation
#' would be good to have separate DD function specified after
#' chevin and lande 2010
#' @export
R_bar <- function(R0, Wbar, N) {
    .Call('phenoecosim_R_bar', PACKAGE = 'phenoecosim', R0, Wbar, N)
}

#' Compute population growth rate under stabilizing selection and ceiling regulation
#' @inheritParams R_bar
#' @param K carrying capacity
#' @details Assumes ceiling population regulation
#' would be good to have separate DD function specified after
#' chevin and lande 2010
#' @export
R_bar_ceiling <- function(R0, Wbar, N, K) {
    .Call('phenoecosim_R_bar_ceiling', PACKAGE = 'phenoecosim', R0, Wbar, N, K)
}

#' Compute population growth rate under stabilizing selection and theta-logistic regulation
#' @inheritParams R_bar
#' @param K0 carrying capacity with optimal trait
#' @param thetaL theta-logistic parameter for density dependence
#' @details Assumes theta-logistic population regulation
#' would be good to have separate DD function specified after
#' chevin and lande 2010
#' @export
R_bar_thetalog <- function(R0, Wbar, N, K0, thetaL) {
    .Call('phenoecosim_R_bar_thetalog', PACKAGE = 'phenoecosim', R0, Wbar, N, K0, thetaL)
}

#' Compute population growth rate under stabilizing selection and Gompertz regulation
#' @inheritParams R_bar
#' @param K0 carrying capacity at optimum trait
#' @details Assumes Gompertz population regulation
#' @export
R_bar_gompertz <- function(R0, Wbar, N, K0) {
    .Call('phenoecosim_R_bar_gompertz', PACKAGE = 'phenoecosim', R0, Wbar, N, K0)
}

#' Va additive genetic variance in the phenotype as a function of the environment
#' @param env environment in which plastiicty is cued
#' @param GG additive genetic variance-covariance matrix
#' @export
Va <- function(env, GG) {
    .Call('phenoecosim_Va', PACKAGE = 'phenoecosim', env, GG)
}

#' Calculate N_e
#'
#' R0 @param reproductive rate
#' N   @param census popualtion size
#' @details use $N_e \approx 2 R0 N  / (2 R0 - 1)$.
#' @export
N_e <- function(R0, N) {
    .Call('phenoecosim_N_e', PACKAGE = 'phenoecosim', R0, N)
}

#' SHC
#'
#' @param sigma_g2 asymptotic genetic variance
#' @param omegaz2 defines width of the fitness function $\omega ^2 + 1$
#' @param N     census population size
#' @param R0   reproductive rate
#' @details
#'          For this modified SHC after Burger
#'          \[
#'          \sigma_{SHC}(\sigma_g^2) =
#'           \frac{sigma_g}{1 + \frac{V_s}{\alpha ^ 2 N_e}}
#'          \]
#'          For $\alpha^2$ the variance of the effect of new mutations, $V_m$
#'          the genomic mutation rate per generation, and $N_e \approx 2 R_0 N  / (2 R_0 - 1)$.
#'          As population size increases, the function approaches a limit of $\sigma_g^2$
#'          $V_s = \omega^2 + \sigma_e^2$ is the width of the fitness function.
#'          Hard-coded parameters and $alpha^2 = 0.005$ and $\sigma_e^2 = 1$
#' @export
SHC <- function(sigma_g2, omegaz2, N, R0) {
    .Call('phenoecosim_SHC', PACKAGE = 'phenoecosim', sigma_g2, omegaz2, N, R0)
}

#' Compute a white noise environment with a shift
#' @param t the time point
#' @param env_args other args:
#' t.jump the location for the jump,
#' delta env change that takes place at t.jump
#' sd noise in env
#' sdc noise in cue
#' @details nada
#' @export
Env_shift_cpp <- function(t, env_args) {
    .Call('phenoecosim_Env_shift_cpp', PACKAGE = 'phenoecosim', t, env_args)
}

#' Compute correctly-scaled environment of development and selection
#' @param env_args environment args
#' @param T how many gens
#' @details given a pre-generated vector of random environments
#' @export
make_env <- function(T, env_args) {
    .Call('phenoecosim_make_env', PACKAGE = 'phenoecosim', T, env_args)
}

#' Compute phenotypic dynamic Time Series of trait + demographic change under stabilizing selection as
#' function of environment (after Lande Chevin)
#' @param T end time, assuming start time of 1
#' @param X parameters (z, a, b, wbar, logN, theta)
#' @param params a list with (gamma_sh, omegaz, A, B, R0, var_a, Vb, delta, sigma_xi, rho_tau, fractgen)
#' @param env_args extra args for env.fn
#' @param growth_fun density-dependence ("independent", "gompertz", "thetalogistic", "ceiling")
#' @param poisson (logical) return N(t+1) = Poisson(f(N(t)). NOTE: only
#'        implemented for independent and thetalog!
#' @param varying_g varying genetic variance using stochastic house of cards (SHC)
#'                  approximation. See Details.
#' @details NB - for now assume Tchange = 0 and demography after CL 2010
#'          For the SHC after Burger and Lynch (1995) and Kopp and Matuszewski (2013)
#'          \[
#'          \sigma_{SHC}() =
#'           \frac{2 V_m V_s}{1 + \frac{V_s}{\alpha ^ 2 N_e}}
#'          \]
#'          For $\alpha^2$ the variance of the effect of new mutations, $V_m$
#'          the genomic mutation rate per generation, and $N_e \approx 2 R_0 N  / (2 R_0 - 1)$.
#'          As population size increases, the function approaches a limit of $2 V_s V_m$
#'          $V_s = \omega^2 + \sigma_e^2$ (we hard code the latter as 1) is the width of the fitness function.
#' @return a long matrix with columns zbar, abar, bbar, Wbar, Npop, theta
#' @export
simulate_pheno_ts <- function(T, X, params, env_args, growth_fun = "independent", poisson = FALSE, varying_g = FALSE) {
    .Call('phenoecosim_simulate_pheno_ts', PACKAGE = 'phenoecosim', T, X, params, env_args, growth_fun, poisson, varying_g)
}
ashander/phenoecosim documentation built on May 10, 2019, 1:52 p.m.