Skip to content

Commit

Permalink
Full simulator with Luis
Browse files Browse the repository at this point in the history
Features: simulate autocorrelated environment with trait and population
dynamics. Also ceiling density regulation.

Expand README and add LICENSE (MIT)

Add Luis as package author

Add testing:
- unit testing at highest (ts simulation) level
- env sim
- stub for tests
- a regression test

Ignore build and autosave files
- Add rds files to ignore
  • Loading branch information
ashander committed Nov 18, 2015
1 parent a5cdfd0 commit acae90c
Show file tree
Hide file tree
Showing 33 changed files with 511 additions and 927 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
.Rhistory
*.rds
..Rcheck
*.o
*.so
.\#*
\#*\#
15 changes: 8 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ Description: A set of codes to simulate evolutionary, plastic and ecological
constantly moving optima
Title: Simulations of eco-evo trait and demographic dynamics under changing
environments
Version: 0.0-1
Date: 2013-10-31
Version: 0.1.0
Date: 2015-11-17
Authors@R: c(person("Jaime", "Ashander", role = c("aut", "cre"), email=
'[email protected]'))
"[email protected]"), person("Luis-Miguel", "Chevin", role=c("aut"),
email="[email protected]"))
Depends:
RcppArmadillo (>= 0.4.3)
Imports:
Rcpp,
deSolve,
MASS
Rcpp
LinkingTo: Rcpp, RcppArmadillo
License: BSD
License: MIT
Suggests:
testthat
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Jaime Ashander and Luis-Miguel Chevin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 4 additions & 16 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
# Generated by roxygen2 (4.0.2): do not edit by hand

export(Beta)
export(Env_shift)
export(Env_shift_cpp)
export(Env_smooth)
export(G)
export(Log_R_bar)
export(Log_W_bar)
export(Log_W_bar_lethal)
export(Pheno_demo)
export(Pheno_demo_econ)
export(Pheno_demo_lande)
export(Pheno_lande)
export(R_bar)
export(R_bar_dd)
export(R_bar_ceiling)
export(R_bar_thetalog)
export(Va)
export(W_bar)
export(pdTS)
export(stab_curve)
import(MASS)
import(deSolve)
export(make_env)
export(simulate_pheno_ts)
useDynLib(phenoecosim)
102 changes: 50 additions & 52 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,70 +1,71 @@
# This file was generated by Rcpp::compileAttributes
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' 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
NULL

#' 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 no details
#' @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)
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 no details
#' @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)
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
#' Compute population growth rate under stabilizing selection and no regulation
#' @param R0 basic reproductive number
#' @param Wbar average fitness
#' @details Assumes density-independent
#' @export
R_bar <- function(R0, Wbar) {
.Call('phenoecosim_R_bar', PACKAGE = 'phenoecosim', R0, Wbar)
}

#' Compute LOG population growth rate under stabilizing selection
#' @inheritParams R_bar
#' @param logWbar log average fitness
#' @details Assumes theta-logistic population regulation
#' @param N number of individuals in this generation
#' @param K carrying capacity
#' @details Assumes ceiling population regulation
#' would be good to have separate DD function specified after
#' chevin and lande 2010
#' @export
Log_R_bar <- function(R0, logWbar) {
.Call('phenoecosim_Log_R_bar', PACKAGE = 'phenoecosim', R0, logWbar)
R_bar <- function(R0, Wbar, N) {
.Call('phenoecosim_R_bar', PACKAGE = 'phenoecosim', R0, Wbar, N)
}

#' Compute population growth rate under stabilizing selection
#' @inheritParams R_bar
#' Compute population growth rate under stabilizing selection and ceiling regulation
#' @param R0 basic reproductive number
#' @param Wbar average fitness
#' @param N number of individuals in this generation
#' @param K carrying capacity
#' @param thetaL theta-logistic parameter for density dependence
#' @details Assumes theta-logistic population regulation
#' @details Assumes ceiling population regulation
#' would be good to have separate DD function specified after
#' chevin and lande 2010
#' @export
R_bar_dd <- function(R0, Wbar, N, K, thetaL) {
.Call('phenoecosim_R_bar_dd', PACKAGE = 'phenoecosim', R0, Wbar, N, K, thetaL)
R_bar_ceiling <- function(R0, Wbar, N, K) {
.Call('phenoecosim_R_bar_ceiling', PACKAGE = 'phenoecosim', R0, Wbar, N, K)
}

#' Selection on plasticity as as function of environment assuming stabilizing selection
#' @param gamma = 1/(Oz2 + Vz2), with Vz2 phenotypic variance
#' @param A the environmental optimum RN int
#' @param B the environmental optimum RN slope
#' @param a current value of RN int
#' @param b current value of RN slope
#' @param e_t environment now
#' @param e_plast env that cues plasticity
#' Compute population growth rate under stabilizing selection and theta-logistic regulation
#' @inheritParams R_bar_ceiling
#' @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
Beta <- function(gamma, A, B, a, b, e_t, e_plast) {
.Call('phenoecosim_Beta', PACKAGE = 'phenoecosim', gamma, A, B, a, b, e_t, e_plast)
R_bar_thetalog <- function(R0, Wbar, N, K, thetaL) {
.Call('phenoecosim_R_bar_thetalog', PACKAGE = 'phenoecosim', R0, Wbar, N, K, thetaL)
}

#' Va additive genetic variance in the phenotype as a function of the environment
Expand All @@ -75,28 +76,25 @@ Va <- function(env, GG) {
.Call('phenoecosim_Va', PACKAGE = 'phenoecosim', env, GG)
}

#' 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
#' 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
Env_shift_cpp <- function(t, env_args) {
.Call('phenoecosim_Env_shift_cpp', PACKAGE = 'phenoecosim', t, env_args)
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
#' 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, Va, Vb, delta, sigma_xi, rho_tau, fractgen)
#' @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
#' @details NB - for now assume Tchange = 0 and demography after CL 2010
#' @value a long matrix
#' @export
pdTS <- function(T, X, params, env_args) {
.Call('phenoecosim_pdTS', PACKAGE = 'phenoecosim', T, X, params, env_args)
simulate_pheno_ts <- function(T, X, params, env_args) {
.Call('phenoecosim_simulate_pheno_ts', PACKAGE = 'phenoecosim', T, X, params, env_args)
}

52 changes: 0 additions & 52 deletions R/envsim.R

This file was deleted.

Loading

0 comments on commit acae90c

Please sign in to comment.