Skip to content

Commit acae90c

Browse files
committed
Full simulator with Luis
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
1 parent a5cdfd0 commit acae90c

33 files changed

Lines changed: 511 additions & 927 deletions

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
.Rhistory
2+
*.rds
3+
..Rcheck
4+
*.o
5+
*.so
6+
.\#*
7+
\#*\#

DESCRIPTION

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ Description: A set of codes to simulate evolutionary, plastic and ecological
44
constantly moving optima
55
Title: Simulations of eco-evo trait and demographic dynamics under changing
66
environments
7-
Version: 0.0-1
8-
Date: 2013-10-31
7+
Version: 0.1.0
8+
Date: 2015-11-17
99
Authors@R: c(person("Jaime", "Ashander", role = c("aut", "cre"), email=
10-
'jashander@ucdavis.edu'))
10+
"jashander@ucdavis.edu"), person("Luis-Miguel", "Chevin", role=c("aut"),
11+
email="luis-miguel.chevin@cefe.cnrs.fr"))
1112
Depends:
1213
RcppArmadillo (>= 0.4.3)
1314
Imports:
14-
Rcpp,
15-
deSolve,
16-
MASS
15+
Rcpp
1716
LinkingTo: Rcpp, RcppArmadillo
18-
License: BSD
17+
License: MIT
18+
Suggests:
19+
testthat

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Jaime Ashander and Luis-Miguel Chevin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

NAMESPACE

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
# Generated by roxygen2 (4.0.2): do not edit by hand
22

3-
export(Beta)
4-
export(Env_shift)
5-
export(Env_shift_cpp)
6-
export(Env_smooth)
73
export(G)
8-
export(Log_R_bar)
94
export(Log_W_bar)
10-
export(Log_W_bar_lethal)
11-
export(Pheno_demo)
12-
export(Pheno_demo_econ)
13-
export(Pheno_demo_lande)
14-
export(Pheno_lande)
15-
export(R_bar)
16-
export(R_bar_dd)
5+
export(R_bar_ceiling)
6+
export(R_bar_thetalog)
177
export(Va)
188
export(W_bar)
19-
export(pdTS)
20-
export(stab_curve)
21-
import(MASS)
22-
import(deSolve)
9+
export(make_env)
10+
export(simulate_pheno_ts)
2311
useDynLib(phenoecosim)

R/RcppExports.R

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,71 @@
11
# This file was generated by Rcpp::compileAttributes
22
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
33

4+
#' Compute a white noise environment with a shift
5+
#' @param t the time point
6+
#' @param env_args other args:
7+
#' t.jump the location for the jump,
8+
#' delta env change that takes place at t.jump
9+
#' sd noise in env
10+
#' sdc noise in cue
11+
#' @details nada
12+
NULL
13+
414
#' Compute mean fitness under stabilizing selection
515
#' @param zbar mean trait prior to selection
616
#' @param theta enironmental optimum
7-
#' @param Oz2 strength of stabilizing selection
8-
#' @param gamma 1/(Oz2 + Vz2), with Vz2 phenotypic variance
9-
#' @details no details
17+
#' @param oz2 strength of stabilizing selection
18+
#' @param gamma 1/(oz2 + Vz2), with Vz2 phenotypic variance
19+
#' @details IN USE
1020
#' @export
11-
Log_W_bar <- function(zbar, theta, Oz2, gamma) {
12-
.Call('phenoecosim_Log_W_bar', PACKAGE = 'phenoecosim', zbar, theta, Oz2, gamma)
21+
Log_W_bar <- function(zbar, theta, oz2, gamma) {
22+
.Call('phenoecosim_Log_W_bar', PACKAGE = 'phenoecosim', zbar, theta, oz2, gamma)
1323
}
1424

1525
#' Compute mean fitness under stabilizing selection
1626
#' @inheritParams Log_W_bar
17-
#' @param LOG (=TRUE) whether to return the log of fitness
18-
#' @details no details
27+
#' @param LOG (=TRUE) whether to return the log of fitness
28+
#' @details IN USE
1929
#' @export
20-
W_bar <- function(zbar, theta, Oz2, gamma, LOG) {
21-
.Call('phenoecosim_W_bar', PACKAGE = 'phenoecosim', zbar, theta, Oz2, gamma, LOG)
30+
W_bar <- function(zbar, theta, oz2, gamma, LOG) {
31+
.Call('phenoecosim_W_bar', PACKAGE = 'phenoecosim', zbar, theta, oz2, gamma, LOG)
2232
}
2333

24-
#' Compute population growth rate under stabilizing selection
34+
#' Compute population growth rate under stabilizing selection and no regulation
2535
#' @param R0 basic reproductive number
2636
#' @param Wbar average fitness
27-
#' @details Assumes density-independent
28-
#' @export
29-
R_bar <- function(R0, Wbar) {
30-
.Call('phenoecosim_R_bar', PACKAGE = 'phenoecosim', R0, Wbar)
31-
}
32-
33-
#' Compute LOG population growth rate under stabilizing selection
34-
#' @inheritParams R_bar
35-
#' @param logWbar log average fitness
36-
#' @details Assumes theta-logistic population regulation
37+
#' @param N number of individuals in this generation
38+
#' @param K carrying capacity
39+
#' @details Assumes ceiling population regulation
3740
#' would be good to have separate DD function specified after
3841
#' chevin and lande 2010
3942
#' @export
40-
Log_R_bar <- function(R0, logWbar) {
41-
.Call('phenoecosim_Log_R_bar', PACKAGE = 'phenoecosim', R0, logWbar)
43+
R_bar <- function(R0, Wbar, N) {
44+
.Call('phenoecosim_R_bar', PACKAGE = 'phenoecosim', R0, Wbar, N)
4245
}
4346

44-
#' Compute population growth rate under stabilizing selection
45-
#' @inheritParams R_bar
47+
#' Compute population growth rate under stabilizing selection and ceiling regulation
48+
#' @param R0 basic reproductive number
49+
#' @param Wbar average fitness
4650
#' @param N number of individuals in this generation
4751
#' @param K carrying capacity
48-
#' @param thetaL theta-logistic parameter for density dependence
49-
#' @details Assumes theta-logistic population regulation
52+
#' @details Assumes ceiling population regulation
5053
#' would be good to have separate DD function specified after
5154
#' chevin and lande 2010
5255
#' @export
53-
R_bar_dd <- function(R0, Wbar, N, K, thetaL) {
54-
.Call('phenoecosim_R_bar_dd', PACKAGE = 'phenoecosim', R0, Wbar, N, K, thetaL)
56+
R_bar_ceiling <- function(R0, Wbar, N, K) {
57+
.Call('phenoecosim_R_bar_ceiling', PACKAGE = 'phenoecosim', R0, Wbar, N, K)
5558
}
5659

57-
#' Selection on plasticity as as function of environment assuming stabilizing selection
58-
#' @param gamma = 1/(Oz2 + Vz2), with Vz2 phenotypic variance
59-
#' @param A the environmental optimum RN int
60-
#' @param B the environmental optimum RN slope
61-
#' @param a current value of RN int
62-
#' @param b current value of RN slope
63-
#' @param e_t environment now
64-
#' @param e_plast env that cues plasticity
60+
#' Compute population growth rate under stabilizing selection and theta-logistic regulation
61+
#' @inheritParams R_bar_ceiling
62+
#' @param thetaL theta-logistic parameter for density dependence
63+
#' @details Assumes theta-logistic population regulation
64+
#' would be good to have separate DD function specified after
65+
#' chevin and lande 2010
6566
#' @export
66-
Beta <- function(gamma, A, B, a, b, e_t, e_plast) {
67-
.Call('phenoecosim_Beta', PACKAGE = 'phenoecosim', gamma, A, B, a, b, e_t, e_plast)
67+
R_bar_thetalog <- function(R0, Wbar, N, K, thetaL) {
68+
.Call('phenoecosim_R_bar_thetalog', PACKAGE = 'phenoecosim', R0, Wbar, N, K, thetaL)
6869
}
6970

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

78-
#' Compute a white noise environment with a shift
79-
#' @param t the time point
80-
#' @param env_args other args:
81-
#' t.jump the location for the jump,
82-
#' delta env change that takes place at t.jump
83-
#' sd noise in env
84-
#' sdc noise in cue
85-
#' @details nada
79+
#' Compute correctly-scaled environment of development and selection
80+
#' @param env_args environment args
81+
#' @param T how many gens
82+
#' @details given a pre-generated vector of random environments
8683
#' @export
87-
Env_shift_cpp <- function(t, env_args) {
88-
.Call('phenoecosim_Env_shift_cpp', PACKAGE = 'phenoecosim', t, env_args)
84+
make_env <- function(T, env_args) {
85+
.Call('phenoecosim_make_env', PACKAGE = 'phenoecosim', T, env_args)
8986
}
9087

91-
#' Compute phenotypic dynamic Time Series of trait + demographic change under stabilizing selection as
88+
#' Compute phenotypic dynamic Time Series of trait + demographic change under stabilizing selection as
9289
#' function of environment (after Lande Chevin)
9390
#' @param T end time, assuming start time of 1
9491
#' @param X parameters (z, a, b, wbar, logN, theta)
95-
#' @param params a list with (gamma_sh, omegaz, A, B, R0, Va, Vb, delta, sigma_xi, rho_tau, fractgen)
92+
#' @param params a list with (gamma_sh, omegaz, A, B, R0, var_a, Vb, delta, sigma_xi, rho_tau, fractgen)
9693
#' @param env_args extra args for env.fn
9794
#' @details NB - for now assume Tchange = 0 and demography after CL 2010
95+
#' @value a long matrix
9896
#' @export
99-
pdTS <- function(T, X, params, env_args) {
100-
.Call('phenoecosim_pdTS', PACKAGE = 'phenoecosim', T, X, params, env_args)
97+
simulate_pheno_ts <- function(T, X, params, env_args) {
98+
.Call('phenoecosim_simulate_pheno_ts', PACKAGE = 'phenoecosim', T, X, params, env_args)
10199
}
102100

R/envsim.R

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)