diff --git a/.Rbuildignore b/.Rbuildignore index 5954eef4..6aaa3e6d 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -14,8 +14,8 @@ ^\.Rproj\.user$ ^\.covrignore$ -^LICENSE$ ^\.zenodo\.json$ ^\.vscode$ -^source_odeint\.R +^dummy\.R +^LICENSE\.md$ diff --git a/DESCRIPTION b/DESCRIPTION index 1586e294..fdbe3656 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: DAISIE Type: Package Title: Dynamical Assembly of Islands by Speciation, Immigration and Extinction -Version: 4.3.4 -Date: 2023-03-16 +Version: 4.4.0 +Date: 2023-03-29 Depends: R (>= 4.2.0) biocViews: Imports: @@ -105,11 +105,11 @@ Authors@R: c( email = "r.scherrer@rug.nl", role = c("ctb"), comment = c(ORCID = "0000-0002-1447-7630"))) -License: GPL-3 +License: GPL (>= 3) | file LICENSE +Copyright: See the file COPYRIGHTS for various DAISIE copyright details Description: Simulates and computes the (maximum) likelihood of a dynamical model of island biota assembly through speciation, immigration and - extinction. See e.g. Valente et al. 2015. Ecology Letters 18: 844-852, - . + extinction. See Valente et al. (2015) . NeedsCompilation: yes SystemRequirements: C++17 Encoding: UTF-8 diff --git a/LICENSE.note b/LICENSE.note new file mode 100644 index 00000000..1482fef8 --- /dev/null +++ b/LICENSE.note @@ -0,0 +1,9 @@ +The DAISIE package as a whole is distributed under >= GPL-3, the license of which can be found in the distributed file LICENSE. The DAISIE package includes code written by two of the package authors that is distributed under BSL-1.0: + +* src/DAISIE_CS.cpp +* src/DAISIE_IW.cpp +* src/DAISIE_odeint.h +* src/DAISIE_types.h +* src/DAISIE_loglik_rhs_FORTRAN.f95 + +Full copies of the BSL-1.0 license used by these files is included in `inst/LICENSE_1_0.txt`, as is a license and copyright notice on said files, while details are also in `inst/COPYRIGHTS`. diff --git a/NAMESPACE b/NAMESPACE index 9f793cfe..4835adfd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -34,7 +34,6 @@ export(DAISIE_sim_relaxed_rate) export(DAISIE_sim_time_dep) export(DAISIE_sim_trait_dep) export(DAISIE_sim_trait_dep_2K) -export(are_area_pars) export(create_CS_version) export(create_area_pars) export(create_hyper_pars) @@ -42,6 +41,7 @@ export(create_pars) export(create_trait_pars) export(create_trait_pars_2K) export(daisie_odeint_cs) +export(daisie_odeint_iw) import(Rcpp) importFrom(doParallel,registerDoParallel) importFrom(foreach,"%dopar%") diff --git a/NEWS.md b/NEWS.md index 7819a59e..bc057db3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,27 @@ +# DAISIE 4.4.0 + +* No longer include patched version of `boost/numeric/odeint/stepper/bulirsch_stoer.hpp`, +address the issue by passing previously uninitialised variable as `boost::units::quantity`. +* Document return type of exported Rcpp functions. +* Move all internal non-error printing to console `message()` and `warning()`. +Add internal functions to address this. `verbose` variable is now numeric, +varying from 0 to 3. Increasing values increase amount of messages to be +printed. Change default of printing some output to golden rule of silence +`verbose == 0`. To print again, set `verbose >= 1`. +* Remove calls to `options(warn = -1)` that suppress warnings in non standard +way. Use `suppressWarnings()` where appropriate. +* Safely restore graphics settings after plot. +* Fix references in `DESCRIPTION`. +* Remove internal (unnecessary) calls to internal functions via `:::`. +* No longer use roxygen2 tag `internal` to document without index but use +`noRd` instead. `are_area_pars()` is now internal. +* Replace `\dontrun` examples in documentation with `\donttest`. Speed up +examples. +* License package C++ source files as BSL-1.0 (c) Hanno Hildenbrandt, FORTRAN +files as BSL-1.0 (c) Rampal S. Etienne. +* Add `LICENSE.note`, `inst/COPYRIGHTS` to clarify license and copyrights. Pipe +such files in `DESCRIPTION`. + # DAISIE 4.3.4 * Require C++17 via `CXX_STD` flag on Makevars[.win]. diff --git a/R/DAISIE_ML1.R b/R/DAISIE_ML1.R index 2f0df0d7..d3b3ca20 100644 --- a/R/DAISIE_ML1.R +++ b/R/DAISIE_ML1.R @@ -61,8 +61,7 @@ DAISIE_loglik_all_choosepar <- function(trparsopt, ) } if (is.nan(loglik) || is.na(loglik)) { - cat("There are parameter values used - which cause numerical problems.\n") + message("There are parameter values used which cause numerical problems.") loglik <- -Inf } } @@ -221,66 +220,56 @@ DAISIE_ML1 <- function( position = 'lambda_a', column_to_insert = nc) } - if (length(namepars[idparsopt]) == 0) { - optstr <- "nothing" - } else { - optstr <- namepars[idparsopt] - } - cat("You are optimizing", optstr, "\n") - if (length(namepars[idparsfix]) == 0) { - fixstr <- "nothing" - } else { - fixstr <- namepars[idparsfix] - } - cat("You are fixing", fixstr, "\n") + print_ml_par_settings( + namepars = namepars, + idparsopt = idparsopt, + idparsfix = idparsfix, + idparsnoshift = idparsnoshift, + all_no_shift = all_no_shift, + verbose = verbose + ) - if (sum(idparsnoshift %in% (all_no_shift)) != 5) { - noshiftstring <- namepars[idparsnoshift] - cat("You are not shifting", noshiftstring, "\n") - } idpars <- sort(c(idparsopt, idparsfix, idparsnoshift, idparseq)) missnumspec <- unlist(lapply(datalist, function(list) {list$missing_species})) # nolint if (max(missnumspec) > (res - 1)) { - cat( + warning( "The number of missing species is too large relative to the - resolution of the ODE.\n") + resolution of the ODE.") return(out2err) } if (max(missnumspec) > res/10) { warning( "The number of missing species is quite low relative to the - resolution of the ODE.\n") + resolution of the ODE.") } if ((length(idpars) != max(idpars))) { - cat("The parameters to be optimized and/or fixed are incoherent.\n") + warning("The parameters to be optimized and/or fixed are incoherent.") return(out2err) } if ((!all(idpars == 1:max(idpars))) || # nolint (length(initparsopt) != length(idparsopt)) || (length(parsfix) != length(idparsfix))) { - cat("The parameters to be optimized and/or fixed are incoherent.\n") + warning("The parameters to be optimized and/or fixed are incoherent.") return(out2err) } if (length(idparseq) == 0) { } else { if (ddmodel == 3) { - cat("Equilibrium optimization is not implemented for ddmodel = 3\n") + warning("Equilibrium optimization is not implemented for ddmodel = 3") } else { - cat( + message( "You are assuming equilibrium. Extinction and/or immigration will be considered a function of the other parameters, the species pool size, the number of endemics, - and/or the number of non-endemics\n" + and/or the number of non-endemics" ) } } - cat("Calculating the likelihood for the initial parameters.", "\n") - utils::flush.console() trparsopt <- initparsopt / (1 + initparsopt) trparsopt[which(initparsopt == Inf)] <- 1 trparsfix <- parsfix / (1 + parsfix) @@ -313,20 +302,17 @@ DAISIE_ML1 <- function( abstolint = tolint[1], reltolint = tolint[2] ) - cat( - "The loglikelihood for the initial parameter values is", - initloglik, - "\n" - ) + + print_init_ll(initloglik = initloglik, verbose = verbose) + if (initloglik == -Inf) { - cat( + warning( "The initial parameter values have a likelihood that is equal to 0 or - below machine precision. Try again with different initial values.\n" + below machine precision. Try again with different initial values." ) return(out2err) } - cat("Optimizing the likelihood - this may take a while.", "\n") - utils::flush.console() + out <- DDD::optimizer( optimmethod = optimmethod, optimpars = optimpars, @@ -347,9 +333,9 @@ DAISIE_ML1 <- function( num_cycles = num_cycles ) if (out$conv != 0) { - cat( + warning( "Optimization has not converged. - Try again with different initial values.\n") + Try again with different initial values.") out2 <- out2err out2$conv <- out$conv return(out2) @@ -414,7 +400,7 @@ DAISIE_ML1 <- function( conv = unlist(out$conv) ) pars_to_print <- MLpars1[1:6] - parnames <- c('lambda^c','mu','K','gamma','lambda^a','prob_init_pres') + parnames <- c("lambda^c", "mu", "K", "gamma", "lambda^a", "prob_init_pres") } else { out2 <- data.frame( lambda_c = MLpars1[1], @@ -431,17 +417,16 @@ DAISIE_ML1 <- function( } print_parameters_and_loglik(pars = pars_to_print, loglik = ML, - verbose = TRUE, + verbose = verbose, parnames = parnames, type = 'island_ML') if (eqmodel > 0) { M <- calcMN(datalist, MLpars1) ExpEIN <- DAISIE_ExpEIN(datalist[[1]]$island_age, MLpars1, M) # nolint start - cat("The expected number of endemics, non-endemics, and the total at - these parameters is: ", - ExpEIN[[1]], - ExpEIN[[2]], - ExpEIN[[3]] + message( + paste0("The expected number of endemics, non-endemics, and the total at ", + "these parameters is: "), + paste(ExpEIN[[1]], ExpEIN[[2]], ExpEIN[[3]]) ) # nolint end } return(invisible(out2)) diff --git a/R/DAISIE_ML2.R b/R/DAISIE_ML2.R index 3bd3702c..c716139c 100644 --- a/R/DAISIE_ML2.R +++ b/R/DAISIE_ML2.R @@ -30,7 +30,7 @@ DAISIE_loglik_all_choosepar2 <- function( } } if (is.nan(loglik) || is.na(loglik)) { - cat("There are parameter values used which cause numerical problems.\n") + warning("There are parameter values used which cause numerical problems.") loglik <- -Inf } return(loglik) @@ -120,8 +120,6 @@ DAISIE_ML2 <- function( # - cond = conditioning; currently only cond = 0 is possible # . cond == 0 : no conditioning # . cond == 1 : conditioning on presence on the island - - options(warn = -1) out2err <- data.frame(lambda_c = NA, mu = NA, K = NA, gamma = NA, lambda_a = NA, loglik = NA, df = NA, conv = NA) out2err <- invisible(out2err) numisl <- length(datalist) @@ -131,17 +129,16 @@ DAISIE_ML2 <- function( } if (missnumspec > (res - 1)) { - cat("The number of missing species is too large relative to the resolution of the ODE.\n") + warning("The number of missing species is too large relative to the resolution of the ODE.") return(out2err) } if (all((sort(unique(as.vector(idparsmat))) != sort(c(idparsopt, idparsfix)))) || (length(initparsopt) != length(idparsopt)) || (length(parsfix) != length(idparsfix))) { - cat("The parameters to be optimized and/or fixed are incoherent.\n") + warning("The parameters to be optimized and/or fixed are incoherent.") return(out2err) } - cat("Calculating the likelihood for the initial parameters.", "\n") - utils::flush.console() + trparsopt <- initparsopt / (1 + initparsopt) trparsopt[which(initparsopt == Inf)] <- 1 trparsfix <- parsfix / (1 + parsfix) @@ -149,13 +146,13 @@ DAISIE_ML2 <- function( pars2 <- c(res, ddmodel, cond, 0, island_ontogeny) optimpars <- c(tol, maxiter) initloglik <- DAISIE_loglik_all_choosepar2(trparsopt = trparsopt, trparsfix = trparsfix, idparsopt = idparsopt, idparsfix = idparsfix, idparsmat = idparsmat, pars2 = pars2, datalist = datalist, methode, abstolint = tolint[1], reltolint = tolint[2]) - cat("The loglikelihood for the initial parameter values is", initloglik, "\n") + + print_init_ll(initloglik = initloglik, verbose = verbose) + if (initloglik == -Inf) { - cat("The initial parameter values have a likelihood that is equal to 0 or below machine precision. Try again with different initial values.\n") + warning("The initial parameter values have a likelihood that is equal to 0 or below machine precision. Try again with different initial values.") return(out2err) } - cat("Optimizing the likelihood - this may take a while.", "\n") - utils::flush.console() out <- DDD::optimizer( optimmethod = optimmethod, optimpars = optimpars, @@ -174,7 +171,7 @@ DAISIE_ML2 <- function( num_cycles = num_cycles ) if (out$conv != 0) { - cat("Optimization has not converged. Try again with different initial values.\n") + warning("Optimization has not converged. Try again with different initial values.") out2 <- out2err out2$conv <- out$conv return(out2err) @@ -206,7 +203,7 @@ DAISIE_ML2 <- function( conv = unlist(out$conv)) print_parameters_and_loglik(pars = MLpars1, loglik = ML, - verbose = TRUE, + verbose = verbose, type = 'multiple_island_ML') return(invisible(out2)) } diff --git a/R/DAISIE_ML4.R b/R/DAISIE_ML4.R index cc76e033..f739071d 100644 --- a/R/DAISIE_ML4.R +++ b/R/DAISIE_ML4.R @@ -39,8 +39,7 @@ DAISIE_loglik_all_choosepar4 <- function(trparsopt, ) } if (is.nan(loglik) || is.na(loglik)) { - cat("There are parameter values used - which cause numerical problems.\n") + message("There are parameter values used which cause numerical problems.") loglik <- -Inf } } @@ -122,33 +121,31 @@ DAISIE_ML4 <- function( } else { optstr <- namepars[idparsopt] } - cat("You are optimizing", optstr, "\n") - if (length(namepars[idparsfix]) == 0) { - fixstr <- "nothing" - } else { - fixstr <- namepars[idparsfix] - } - cat("You are fixing", fixstr, "\n") + print_ml_par_settings( + namepars = namepars, + idparsopt = idparsopt, + idparsfix = idparsfix, + idparsnoshift = NA, + all_no_shift = NA, + verbose = verbose + ) idpars <- sort(c(idparsopt, idparsfix)) missnumspec <- unlist(lapply(datalist, function(list) {list$missing_species})) # nolint if (sum(missnumspec) > (res - 1)) { - cat( - "The number of missing species is too large relative to the - resolution of the ODE.\n") + warning( + "The number of missing species is too large relative to the resolution of the ODE.") return(out2err) } if (length(idpars) != 6) { - cat("You have too few or too many parameters to be optimized or fixed.\n") + warning("You have too few or too many parameters to be optimized or fixed.") return(out2err) } if ((prod(idpars == (1:6)) != 1) || # nolint (length(initparsopt) != length(idparsopt)) || (length(parsfix) != length(idparsfix))) { - cat("The parameters to be optimized and/or fixed are incoherent.\n") + warning("The parameters to be optimized and/or fixed are incoherent.") return(out2err) } - cat("Calculating the likelihood for the initial parameters.", "\n") - utils::flush.console() trparsopt <- initparsopt / (1 + initparsopt) trparsopt[which(initparsopt == Inf)] <- 1 trparsfix <- parsfix / (1 + parsfix) @@ -174,20 +171,16 @@ DAISIE_ML4 <- function( abstolint = tolint[1], reltolint = tolint[2] ) - cat( - "The loglikelihood for the initial parameter values is", - initloglik, - "\n" - ) + + print_init_ll(initloglik = initloglik, verbose = verbose) + if (initloglik == -Inf) { - cat( + warning( "The initial parameter values have a likelihood that is equal to 0 or - below machine precision. Try again with different initial values.\n" + below machine precision. Try again with different initial values." ) return(out2err) } - cat("Optimizing the likelihood - this may take a while.", "\n") - utils::flush.console() out <- DDD::optimizer( optimmethod = optimmethod, optimpars = optimpars, @@ -206,9 +199,9 @@ DAISIE_ML4 <- function( num_cycles = num_cycles ) if (out$conv != 0) { - cat( - "Optimization has not converged. - Try again with different initial values.\n") + warning( + "Optimization has not converged` + Try again with different initial values.") out2 <- out2err out2$conv <- out$conv return(out2) @@ -238,7 +231,7 @@ DAISIE_ML4 <- function( ) print_parameters_and_loglik(pars = MLpars1[1:6], loglik = ML, - verbose = TRUE, + verbose = verbose, parnames = c('lambda^c','mu','K','gamma','lambda^a','sd'), type = 'island_ML') return(invisible(out2)) diff --git a/R/DAISIE_ML_IW.R b/R/DAISIE_ML_IW.R index 8fd289c4..b2c19933 100644 --- a/R/DAISIE_ML_IW.R +++ b/R/DAISIE_ML_IW.R @@ -32,7 +32,7 @@ DAISIE_loglik_IW_choosepar <- function( ) } if (is.nan(loglik) || is.na(loglik)) { - cat("There are parameter values used which cause numerical problems.\n") + warning("There are parameter values used which cause numerical problems.") loglik <- -Inf } } @@ -92,7 +92,7 @@ DAISIE_ML_IW <- function( tolint = c(1E-16, 1E-14), jitter = 0, num_cycles = 1) { - options(warn = -1) + out2err <- data.frame(lambda_c = NA, mu = NA, K = NA, gamma = NA, lambda_a = NA, loglik = NA, df = NA, conv = NA) out2err <- invisible(out2err) if (is.null(datalist[[1]]$brts_table)) { @@ -105,27 +105,31 @@ DAISIE_ML_IW <- function( np = datalist[[1]]$not_present if (is.null(np)) { np = datalist[[1]]$not_present_type1 + datalist[[1]]$not_present_type2 - cat('Number of species not present is misspecified.\n') + warning('Number of species not present is misspecified.\n') return(invisible(out2err)) } M <- length(datalist) - 1 + np idpars <- sort(c(idparsopt, idparsfix)) if ((prod(idpars == (1:5)) != 1) || (length(initparsopt) != length(idparsopt)) || (length(parsfix) != length(idparsfix))) { - cat("The parameters to be optimized and/or fixed are incoherent.\n") + warning("The parameters to be optimized and/or fixed are incoherent.\n") return(out2err) } if (length(idparsopt) > 11) { - cat("The number of parameters to be optimized is too high.\n") + warning("The number of parameters to be optimized is too high.\n") return(out2err) } namepars <- c("lambda_c", "mu", "K'", "gamma", "lambda_a") - if (length(namepars[idparsopt]) == 0) { optstr = "nothing" } else { optstr = namepars[idparsopt] } - cat("You are optimizing", optstr, "\n") - if(length(namepars[idparsfix]) == 0) { fixstr = "nothing" } else { fixstr = namepars[idparsfix] } - cat("You are fixing", fixstr, "\n") - cat("Calculating the likelihood for the initial parameters.", "\n") - utils::flush.console() + + print_ml_par_settings( + namepars = namepars, + idparsopt = idparsopt, + idparsfix = idparsfix, + idparsnoshift = NA, + all_no_shift = NA, + verbose = verbose + ) + trparsopt <- initparsopt / (1 + initparsopt) trparsopt[which(initparsopt == Inf)] <- 1 trparsfix <- parsfix / (1 + parsfix) @@ -133,13 +137,12 @@ DAISIE_ML_IW <- function( pars2 <- c(res, ddmodel, cond, verbose) optimpars <- c(tol, maxiter) initloglik <- DAISIE_loglik_IW_choosepar(trparsopt = trparsopt, trparsfix = trparsfix, idparsopt = idparsopt, idparsfix = idparsfix, M = M, pars2 = pars2, datalist = datalist, methode = methode, abstolint = tolint[1], reltolint = tolint[2]) - cat("The loglikelihood for the initial parameter values is", initloglik, "\n") + message("The loglikelihood for the initial parameter values is ", initloglik) if (initloglik == -Inf) { - cat("The initial parameter values have a likelihood that is equal to 0 or below machine precision. Try again with different initial values.\n") + warning("The initial parameter values have a likelihood that is equal to 0 or below machine precision. Try again with different initial values.\n") return(out2err) } - cat("Optimizing the likelihood - this may take a while.", "\n") - utils::flush.console() + message("Optimizing the likelihood - this may take a while.") out <- DDD::optimizer( optimmethod = optimmethod, optimpars = optimpars, @@ -158,7 +161,7 @@ DAISIE_ML_IW <- function( num_cycles = num_cycles ) if (out$conv != 0) { - cat("Optimization has not converged. Try again with different initial values.\n") + warning("Optimization has not converged. Try again with different initial values.") out2 <- out2err out2$conv <- out$conv return(out2) @@ -173,7 +176,7 @@ DAISIE_ML_IW <- function( out2 <- data.frame(lambda_c = MLpars1[1], mu = MLpars1[2], K = MLpars1[3], gamma = MLpars1[4], lambda_a = MLpars1[5], loglik = ML, df = length(initparsopt), conv = unlist(out$conv)) print_parameters_and_loglik(pars = MLpars1[1:5], loglik = ML, - verbose = TRUE, + verbose = verbose, type = 'island_ML') return(invisible(out2)) } diff --git a/R/DAISIE_MW_ML.R b/R/DAISIE_MW_ML.R index cf36cf04..a49f8529 100644 --- a/R/DAISIE_MW_ML.R +++ b/R/DAISIE_MW_ML.R @@ -156,23 +156,27 @@ DAISIE_MW_loglik_choosepar = function( { if(.Platform$OS.type != "unix") { - cat('cluster does not work on a non-unix environment, choose local instead.\n') + warning('cluster does not work on a non-unix environment, choose local instead.') return(-Inf) } doMC::registerDoMC(cpus - 1) } X = NULL; rm(X) - loglik = foreach::foreach(X = datalist, - .combine = sum, - .export = c("pars2"), - .packages = c('DAISIE','foreach','deSolve','doParallel')) %dopar% - DAISIE_loglik_all(pars1 = X[[1]]$pars1new, - pars2 = pars2, - datalist = X, - methode = methode, - CS_version = CS_version, - abstolint = abstolint, - reltolint = reltolint) + + suppressWarnings({ + loglik = foreach::foreach( + X = datalist, + .combine = sum, + .export = c("pars2"), + .packages = c('DAISIE','foreach','deSolve','doParallel')) %dopar% + DAISIE_loglik_all(pars1 = X[[1]]$pars1new, + pars2 = pars2, + datalist = X, + methode = methode, + CS_version = CS_version, + abstolint = abstolint, + reltolint = reltolint) + }) } else { loglik = 0 if(pars2[4] == 0.5) pb <- utils::txtProgressBar(min = 0, max = length(datalist), style = 3) @@ -191,7 +195,7 @@ DAISIE_MW_loglik_choosepar = function( } if(is.nan(loglik) || is.na(loglik)) { - cat("There are parameter values used which cause numerical problems.\n") + warning("There are parameter values used which cause numerical problems.") loglik = -Inf } } @@ -390,7 +394,6 @@ DAISIE_MW_ML = function( num_cycles = 1 ) { - options(warn=-1) distance_dep_options1 <- distance_dep_options1_fun() numpars <- 10 + is.element(distance_dep,distance_dep_options1) + 2 * (distance_dep == 'sigmoidal_col_ana') if(numpars == 11) @@ -408,12 +411,12 @@ DAISIE_MW_ML = function( idpars = sort(c(idparsopt,idparsfix)) if((prod(idpars == (1:numpars)) != 1) || (length(initparsopt) != length(idparsopt)) || (length(parsfix) != length(idparsfix))) { - cat("The parameters to be optimized and/or fixed are incoherent.\n") + warning("The parameters to be optimized and/or fixed are incoherent.\n") return(out2err) } if(length(idparsopt) > numpars) { - cat("The number of parameters to be optimized is too high.\n") + warning("The number of parameters to be optimized is too high.\n") return(out2err) } namepars = c("lambda_c0","y","mu_0","x","K_0","z","gamma_0","alpha","lambda_a0","beta") @@ -424,12 +427,16 @@ DAISIE_MW_ML = function( { namepars = c(namepars,"d0_col","d0_ana") } - if(length(namepars[idparsopt]) == 0) { optstr = "nothing" } else { optstr = namepars[idparsopt] } - cat("You are optimizing",optstr,"\n") - if(length(namepars[idparsfix]) == 0) { fixstr = "nothing" } else { fixstr = namepars[idparsfix] } - cat("You are fixing",fixstr,"\n") - cat("Calculating the likelihood for the initial parameters.","\n") - utils::flush.console() + + print_ml_par_settings( + namepars = namepars, + idparsopt = idparsopt, + idparsfix = idparsfix, + idparsnoshift = NA, + all_no_shift = NA, + verbose = verbose + ) + trparsopt = initparsopt/(1 + initparsopt) trparsopt[which(initparsopt == Inf)] = 1 trparsfix = parsfix/(1 + parsfix) @@ -437,14 +444,13 @@ DAISIE_MW_ML = function( pars2 = c(res,ddmodel,cond,verbose,island_ontogeny) optimpars = c(tol,maxiter) initloglik = DAISIE_MW_loglik_choosepar(trparsopt = trparsopt,trparsfix = trparsfix,idparsopt = idparsopt,idparsfix = idparsfix,pars2 = pars2,datalist = datalist,methode = methode,CS_version = CS_version,abstolint = tolint[1],reltolint = tolint[2],distance_type = distance_type,parallel = parallel,cpus = cpus,distance_dep = distance_dep) - cat("The loglikelihood for the initial parameter values is",initloglik,"\n") + message("The loglikelihood for the initial parameter values is ", initloglik) if(initloglik == -Inf) { - cat("The initial parameter values have a likelihood that is equal to 0 or below machine precision. Try again with different initial values.\n") + warning("The initial parameter values have a likelihood that is equal to 0 or below machine precision. Try again with different initial values.\n") return(out2err) } - cat("Optimizing the likelihood - this may take a while.","\n") - utils::flush.console() + message("Optimizing the likelihood - this may take a while.") out = DDD::optimizer(optimmethod = optimmethod, optimpars = optimpars, fun = DAISIE_MW_loglik_choosepar, @@ -465,7 +471,7 @@ DAISIE_MW_ML = function( num_cycles = num_cycles) if(out$conv != 0) { - cat("Optimization has not converged. Try again with different initial values.\n") + warning("Optimization has not converged. Try again with different initial values.\n") out2 = out2err out2$conv = out$conv return(out2) @@ -491,7 +497,7 @@ DAISIE_MW_ML = function( } print_parameters_and_loglik(pars = MLpars1, loglik = ML, - verbose = TRUE, + verbose = verbose, type = 'global_ML', distance_dep = distance_dep) return(invisible(out2)) diff --git a/R/DAISIE_PEI.R b/R/DAISIE_PEI.R index 34e0c01b..3aba936d 100644 --- a/R/DAISIE_PEI.R +++ b/R/DAISIE_PEI.R @@ -1,6 +1,6 @@ DAISIE_probdist_rhs <- function(t, x, m) { x <- pmax(x, 0) - #print(t) + #message(t) #utils::flush.console() nx <- sqrt(length(x)) dim(x) <- c(nx, nx) @@ -222,14 +222,14 @@ DAISIE_numcol_dist = function(pars1, dim(ee) <- c(lx, lx) expEtpapprox <- sum(ee * probstp) expEINtp <- DAISIE_ExpEIN(tvec[1], pars1, 1) - cat("The total sum of the probabilities at the first time is", sum(probstp), "\n") - cat("The approximation for the expected number of endemics is", expEtpapprox, "\n") - cat("The true value for the expected number of endemics is", expEINtp[[1]], "\n") + message("The total sum of the probabilities at the first time is ", sum(probstp)) + message("The approximation for the expected number of endemics is ", expEtpapprox) + message("The true value for the expected number of endemics is ", expEINtp[[1]]) expEteqapprox <- sum(ee * probseq) expEINteq <- DAISIE_ExpEIN(Inf, pars1, 1) - cat("The total sum of the probabilities at the second time is", sum(probstp), "\n") - cat("The approximation for the expected number of endemics is", expEteqapprox, "\n") - cat("The true value for the expected number of endemics is", expEINteq[[1]], "\n") + message("The total sum of the probabilities at the second time is ", sum(probstp)) + message("The approximation for the expected number of endemics is ", expEteqapprox) + message("The true value for the expected number of endemics is ", expEINteq[[1]]) utils::flush.console() M <- pars2[2] if (!is.na(pars1[11])) { @@ -239,10 +239,8 @@ DAISIE_numcol_dist = function(pars1, } pC <- stats::dbinom(0:Mnonfinches, Mnonfinches, 1 - probs00) expC <- Mnonfinches * (1 - probs00) - cat( - 'The approximation for the expected number of colonizations is', - expC, - "\n" + message( + "The approximation for the expected number of colonizations is ", expC ) out <- list(pC, expC, expEINtp, expEtpapprox, expEINteq, expEteqapprox) names(out) <- list( @@ -350,13 +348,13 @@ DAISIE_KLdist <- function(pars1, pars2, tvec) { ee <- rep(0:(lx - 1), lx) dim(ee) <- c(lx, lx) expEapprox <- sum(ee * probstp) - print(sum(probstp)) - print(expEapprox) - print(DAISIE_ExpEIN(teq, pars1, M)[[1]]) + message(sum(probstp)) + message(expEapprox) + message(DAISIE_ExpEIN(teq, pars1, M)[[1]]) expEapprox <- sum(ee * probseq) - print(sum(probseq)) - print(expEapprox) - print(DAISIE_ExpEIN(Inf, pars1, M)[[1]]) + message(sum(probseq)) + message(expEapprox) + message(DAISIE_ExpEIN(Inf, pars1, M)[[1]]) KLdist <- sum(probseq * log(probseq / probstp)) return(KLdist) } diff --git a/R/DAISIE_SR_ML_CS.R b/R/DAISIE_SR_ML_CS.R index 76b0b3fd..6164e53a 100644 --- a/R/DAISIE_SR_ML_CS.R +++ b/R/DAISIE_SR_ML_CS.R @@ -33,12 +33,11 @@ DAISIE_SR_loglik_all_choosepar <- function( methode = methode, CS_version = CS_version, abstolint = abstolint, - reltolint = reltolint, - verbose = FALSE + reltolint = reltolint ) } if (is.nan(loglik) || is.na(loglik)) { - cat("There are parameter values used which cause numerical problems.\n") + warning("There are parameter values used which cause numerical problems.\n") loglik <- -Inf } } @@ -162,10 +161,13 @@ DAISIE_SR_loglik_all_choosepar <- function( #' @keywords models #' @examples #' -#' \dontrun{ -#' ### When all species have the same rates, and we want to optimize all 5 parameters, -#' # we use: -#' +#' \donttest{ +#' ## In all following DAISIE_ML calls very high tolerances and low system size +#' ## are used for fast computation for this example. Use default or better +#' ## tol, tolint an res values in actual analyses. +#' ################## +#' ### When all species have the same rates, and we want to optimize all 5 +#' ### parameters, we use: #' utils::data(Galapagos_datalist) #' DAISIE_ML( #' datalist = Galapagos_datalist, @@ -173,7 +175,10 @@ DAISIE_SR_loglik_all_choosepar <- function( #' ddmodel = 11, #' idparsopt = 1:5, #' parsfix = NULL, -#' idparsfix = NULL +#' idparsfix = NULL, +#' tol = c(0.1, 0.02, 0.01), +#' tolint = c(1e-4, 1e-2), +#' res = 50 #' ) #' #' ### When all species have the same rates, and we want to optimize all parameters @@ -185,7 +190,10 @@ DAISIE_SR_loglik_all_choosepar <- function( #' initparsopt = c(2.5,2.7,0.009,1.01), #' idparsopt = c(1,2,4,5), #' parsfix = Inf, -#' idparsfix = 3 +#' idparsfix = 3, +#' tol = c(0.1, 0.02, 0.01), +#' tolint = c(1e-4, 1e-2), +#' res = 50 #' ) #' #' ### When all species have the same rates except that the finches have a different @@ -199,7 +207,10 @@ DAISIE_SR_loglik_all_choosepar <- function( #' idparsopt = c(1,2,4,5,6), #' parsfix = c(Inf,Inf,0.163), #' idparsfix = c(3,8,11), -#' idparsnoshift = c(7,9,10) +#' idparsnoshift = c(7,9,10), +#' tol = c(0.1, 0.02, 0.01), +#' tolint = c(1e-4, 1e-2), +#' res = 50 #' ) #' #' ### When all species have the same rates except that the finches have a different @@ -214,7 +225,10 @@ DAISIE_SR_loglik_all_choosepar <- function( #' idparsopt = c(1,2,4,5,6,7,8), #' parsfix = c(Inf,0.163), #' idparsfix = c(3,11), -#' idparsnoshift = c(9,10) +#' idparsnoshift = c(9,10), +#' tol = c(0.1, 0.02, 0.01), +#' tolint = c(1e-4, 1e-2), +#' res = 50 #' ) #' #' @@ -230,7 +244,10 @@ DAISIE_SR_loglik_all_choosepar <- function( #' idparsopt = c(1,2,4,5,7,11), #' parsfix = c(Inf,Inf), #' idparsfix = c(3,8), -#' idparsnoshift = c(6,9,10) +#' idparsnoshift = c(6,9,10), +#' tol = c(0.1, 0.02, 0.01), +#' tolint = c(1e-4, 1e-2), +#' res = 50 #' ) #' #' ### When we have two islands with the same rates except for immigration and anagenesis rate, @@ -244,7 +261,10 @@ DAISIE_SR_loglik_all_choosepar <- function( #' idparsmat = rbind(1:5,c(1:3,6,7)), #' idparsopt = 1:7, #' parsfix = NULL, -#' idparsfix = NULL +#' idparsfix = NULL, +#' tol = c(0.1, 0.02, 0.01), +#' tolint = c(1e-4, 1e-2), +#' res = 50 #' ) #' #' ### When we consider the four Macaronesia archipelagoes and set all parameters the same @@ -261,7 +281,10 @@ DAISIE_SR_loglik_all_choosepar <- function( #' idparsmat = rbind(1:5,c(6,2,3,7,5),1:5,1:5), #' idparsopt = c(2,4,5,6,7), #' parsfix = c(0,Inf), -#' idparsfix = c(1,3) +#' idparsfix = c(1,3), +#' tol = c(0.1, 0.02, 0.01), +#' tolint = c(1e-4, 1e-2), +#' res = 50 #' ) #' #' } @@ -328,7 +351,6 @@ DAISIE_SR_ML_CS <- DAISIE_SR_ML <- function( # . cond == 0 : no conditioning # . cond == 1 : conditioning on presence on the island - options(warn = -1) out2err <- data.frame(lambda_c = NA, mu = NA, K = NA, gamma = NA, lambda_a2 = NA, lambda_c2 = NA, mu2 = NA, K2 = NA, gamma2 = NA, lambda_a2 = NA, tshift = NA, loglik = NA, df = NA, conv = NA) out2err <- invisible(out2err) idpars <- sort(c(idparsopt, idparsfix, idparsnoshift)) @@ -336,40 +358,45 @@ DAISIE_SR_ML_CS <- DAISIE_SR_ML <- function( list$missing_species })) if (CS_version != 1) { - cat("This version of CS is not yet implemented\n") + warning("This version of CS is not yet implemented") return(out2err) } if (sum(missnumspec) > (res - 1)) { - cat("The number of missing species is too large relative to the resolution of the ODE.\n") + warning("The number of missing species is too large relative to the resolution of the ODE.") return(out2err) } if ((prod(idpars == (1:11)) != 1) || (length(initparsopt) != length(idparsopt)) || (length(parsfix) != length(idparsfix))) { - cat("The parameters to be optimized and/or fixed are incoherent.\n") + warning("The parameters to be optimized and/or fixed are incoherent.") return(out2err) } if (length(idparsopt) > 11) { - cat("The number of parameters to be optimized is too high.\n") + warning("The number of parameters to be optimized is too high.") return(out2err) } - namepars <- c("lambda_c", "mu", "K", "gamma", "lambda_a", "lambda_c2", "mu2", "K2", "gamma2", "lambda_a2", "tshift") - if (length(namepars[idparsopt]) == 0) { - optstr <- "nothing" - } else { - optstr <- namepars[idparsopt] - } - cat("You are optimizing", optstr, "\n") - if (length(namepars[idparsfix]) == 0) { - fixstr <- "nothing" - } else { - fixstr <- namepars[idparsfix] - } - cat("You are fixing", fixstr, "\n") - if (sum(idparsnoshift == (6:10)) != 5) { - noshiftstring <- namepars[idparsnoshift] - cat("You are not shifting", noshiftstring, "\n") - } - cat("Calculating the likelihood for the initial parameters.", "\n") - utils::flush.console() + namepars <- c( + "lambda_c", + "mu", + "K", + "gamma", + "lambda_a", + "lambda_c2", + "mu2", + "K2", + "gamma2", + "lambda_a2", + "tshift" + ) + + print_ml_par_settings( + namepars = namepars, + idparsopt = idparsopt, + idparsfix = idparsfix, + idparsnoshift = idparsnoshift, + # Basic case, only needs to be specified case by case on ML1 + all_no_shift = 6:10, + verbose = verbose + ) + trparsopt <- initparsopt / (1 + initparsopt) trparsopt[which(initparsopt == Inf)] <- 1 trparsfix <- parsfix / (1 + parsfix) @@ -377,34 +404,32 @@ DAISIE_SR_ML_CS <- DAISIE_SR_ML <- function( pars2 <- c(res, ddmodel, cond, verbose, island_ontogeny, tol, maxiter) optimpars <- c(tol, maxiter) initloglik <- DAISIE_SR_loglik_all_choosepar(trparsopt = trparsopt, trparsfix = trparsfix, idparsopt = idparsopt, idparsfix = idparsfix, idparsnoshift = idparsnoshift, pars2 = pars2, datalist = datalist, methode = methode, CS_version = CS_version, abstolint = tolint[1], reltolint = tolint[2]) - cat("The loglikelihood for the initial parameter values is", initloglik, "\n") + message("The loglikelihood for the initial parameter values is ", initloglik) if (initloglik == -Inf) { - cat("The initial parameter values have a likelihood that is equal to 0 or below machine precision. Try again with different initial values.\n") + message("The initial parameter values have a likelihood that is equal to 0 or below machine precision. Try again with different initial values.") return(out2err) } - cat("Optimizing the likelihood - this may take a while.", "\n") - utils::flush.console() - out <- - DDD::optimizer( - optimmethod = optimmethod, - optimpars = optimpars, - fun = DAISIE_SR_loglik_all_choosepar, - trparsopt = trparsopt, - idparsopt = idparsopt, - trparsfix = trparsfix, - idparsfix = idparsfix, - idparsnoshift = idparsnoshift, - pars2 = pars2, - datalist = datalist, - methode = methode, - CS_version = CS_version, - abstolint = tolint[1], - reltolint = tolint[2], - jitter = jitter, - num_cycles = num_cycles - ) + message("Optimizing the likelihood - this may take a while.", "\n") + out <- DDD::optimizer( + optimmethod = optimmethod, + optimpars = optimpars, + fun = DAISIE_SR_loglik_all_choosepar, + trparsopt = trparsopt, + idparsopt = idparsopt, + trparsfix = trparsfix, + idparsfix = idparsfix, + idparsnoshift = idparsnoshift, + pars2 = pars2, + datalist = datalist, + methode = methode, + CS_version = CS_version, + abstolint = tolint[1], + reltolint = tolint[2], + jitter = jitter, + num_cycles = num_cycles + ) if (out$conv != 0) { - cat("Optimization has not converged. Try again with different initial values.\n") + warning("Optimization has not converged. Try again with different initial values.") out2 <- out2err out2$conv <- out$conv return(out2) @@ -429,6 +454,6 @@ DAISIE_SR_ML_CS <- DAISIE_SR_ML <- function( out2 <- data.frame(lambda_c = MLpars1[1], mu = MLpars1[2], K = MLpars1[3], gamma = MLpars1[4], lambda_a = MLpars1[5], lambda_c2 = MLpars1[6], mu2 = MLpars1[7], K2 = MLpars1[8], gamma2 = MLpars1[9], lambda_a2 = MLpars1[10], tshift = MLpars1[11], loglik = ML, df = length(initparsopt), conv = unlist(out$conv)) s1 <- sprintf("Maximum likelihood parameter estimates: lambda_c: %f, mu: %f, K: %f, gamma: %f, lambda_a: %f, lambda_c2: %f, mu2: %f, K2: %f, gamma2: %f, lambda_a2: %f, time of shift: %f", MLpars1[1], MLpars1[2], MLpars1[3], MLpars1[4], MLpars1[5], MLpars1[6], MLpars1[7], MLpars1[8], MLpars1[9], MLpars1[10], MLpars1[11]) s2 <- sprintf("Maximum loglikelihood: %f", ML) - cat("\n", s1, "\n", s2, "\n") + message("\n", s1, "\n", s2, "\n") return(invisible(out2)) } diff --git a/R/DAISIE_SR_loglik_CS.R b/R/DAISIE_SR_loglik_CS.R index e8a35ea7..2fc4671a 100644 --- a/R/DAISIE_SR_loglik_CS.R +++ b/R/DAISIE_SR_loglik_CS.R @@ -73,10 +73,10 @@ DAISIE_SR_loglik_CS_M1 <- DAISIE_SR_loglik <- function( missnumspec, methode = "lsodes", abstolint = abstolint, - reltolint = reltolint, - verbose = FALSE + reltolint = reltolint ) { - if (is.na(pars2[4])) { + verbose <- pars2[4] + if (is.na(verbose)) { pars2[4] <- 0 } ddep <- pars2[2] @@ -233,7 +233,7 @@ DAISIE_SR_loglik_CS_M1 <- DAISIE_SR_loglik <- function( } print_parameters_and_loglik(pars = c(stac,pars1[1:5]), loglik = loglik, - verbose = pars2[4], + verbose = verbose, type = 'clade_loglik') return(as.numeric(loglik)) } @@ -321,7 +321,6 @@ DAISIE_SR_loglik_CS_M1 <- DAISIE_SR_loglik <- function( #' @param methode Method of the ODE-solver. See package deSolve for details. #' Default is "lsodes" #' @param abstolint Absolute tolerance of the integration -#' @param verbose Logical controling if progress is printed to console. #' @param reltolint Relative tolerance of the integration #' #' @return The loglikelihood @@ -348,9 +347,9 @@ DAISIE_SR_loglik_CS <- DAISIE_SR_loglik_all <- function( methode = "lsodes", CS_version = 1, abstolint = 1E-16, - reltolint = 1E-10, - verbose = FALSE + reltolint = 1E-10 ) { + verbose <- pars2[4] pars1 = as.numeric(pars1) check_shift_loglik = shift_before_certain_brts(datalist, pars1) if(check_shift_loglik != 0){ @@ -365,8 +364,7 @@ DAISIE_SR_loglik_CS <- DAISIE_SR_loglik_all <- function( missnumspec = 0, methode = methode, abstolint = abstolint, - reltolint = reltolint, - verbose = FALSE + reltolint = reltolint ) if (is.null(datalist[[1]]$not_present)) { not_present <- (datalist[[1]]$not_present_type1 + datalist[[1]]$not_present_type2) @@ -387,8 +385,7 @@ DAISIE_SR_loglik_CS <- DAISIE_SR_loglik_all <- function( missnumspec = datalist[[i]]$missing_species, methode = methode, abstolint = abstolint, - reltolint = reltolint, - verbose = FALSE + reltolint = reltolint ) } } diff --git a/R/DAISIE_SR_sim.R b/R/DAISIE_SR_sim.R index 7b824f54..8133fe9a 100644 --- a/R/DAISIE_SR_sim.R +++ b/R/DAISIE_SR_sim.R @@ -75,20 +75,7 @@ #' @references Hauffe, T., D. Delicado, R.S. Etienne and L. Valente (2020). #' Lake expansion increases equilibrium diversity via the target effect of #' island biogeography -#' @keywords internal -#' @examples -#' # Simulate 15 islands for 4 million years with a shift in immigration rate -#' # at 0.195 Ma, and plot the species-through-time plot. Pool size 296. -#' -#' pars_before_shift = c(0.079, 0.973, Inf, 0.136, 0.413) -#' pars_after_shift = c(0.079, 0.973, Inf, 0.652, 0.413) -#' tshift = 0.195 -#' island_shift_replicates = DAISIE:::DAISIE_SR_sim( -#' time = 4, -#' M = 296, -#' pars = c(pars_before_shift, pars_after_shift, tshift), -#' replicates = 15 -#' ) +#' @noRd DAISIE_SR_sim <- function(time, M, pars, @@ -118,7 +105,7 @@ DAISIE_SR_sim <- function(time, } island_replicates[[rep]] = full_list if (verbose) - print(paste("Island replicate ", rep, sep = "")) + message("Island replicate ", rep) } island_replicates = DAISIE_format_CS( island_replicates = island_replicates, diff --git a/R/DAISIE_check_format.R b/R/DAISIE_check_format.R index 094fd812..da07a498 100644 --- a/R/DAISIE_check_format.R +++ b/R/DAISIE_check_format.R @@ -37,9 +37,9 @@ are_rates <- function(rates) { #' #' @inheritParams default_params_doc #' -#' @keywords internal #' @return \code{TRUE} if object max_rates is a list of rates, #' \code{FALSE} otherwise. +#' @noRd are_max_rates <- function(max_rates) { if (!all(sapply(max_rates, is.numeric))) return(FALSE) if (!"ana_max_rate" %in% names(max_rates)) return(FALSE) @@ -62,27 +62,7 @@ are_max_rates <- function(max_rates) { #' @author Joshua Lambert, Pedro Neves #' @seealso \code{\link{are_rates}}, \code{\link{are_max_rates}} #' -#' @keywords internal -#' -#' @examples -#' rates <- list( -#' ext_rate = 0.1, -#' immig_rate = 0.1, -#' ana_rate = 0.1, -#' clado_rate = 0.1 -#' ) -#' max_rates <- list( -#' ext_max_rate = 1, -#' immig_max_rate = 1, -#' ana_max_rate = 1, -#' clado_max_rate = 1 -#' ) -#' testthat::expect_true( -#' DAISIE:::are_max_rates_gt_rates( -#' rates = rates, -#' max_rates = max_rates -#' ) -#' ) +#' @noRd are_max_rates_gt_rates <- function(rates, max_rates) { if (!all(sapply(rates, is.numeric))) return(FALSE) if (!all(sapply(max_rates, is.numeric))) return(FALSE) @@ -99,7 +79,7 @@ are_max_rates_gt_rates <- function(rates, max_rates) { #' #' @seealso is_island_ontogeny_runtime #' @return Boolean stating if island_ontogeny is correct. -#' @keywords internal +#' @noRd is_island_ontogeny_input <- function(island_ontogeny) { if (class(island_ontogeny) != class(character())) return(FALSE) if (island_ontogeny != "const" && island_ontogeny != "beta") return(FALSE) @@ -112,7 +92,7 @@ is_island_ontogeny_input <- function(island_ontogeny) { #' #' @seealso is_sea_level_runtime #' @return Boolean stating if sea_level is correct. -#' @keywords internal +#' @noRd is_sea_level_input <- function(sea_level) { if (class(sea_level) != class(character())) return(FALSE) if (sea_level != "const" && sea_level != "sine") return(FALSE) @@ -128,18 +108,7 @@ is_sea_level_input <- function(sea_level) { #' @return TRUE if the input is a valid collection of simulation #' outputs. #' @author Richel J.C Bilderbeek, Pedro Neves -#' @examples -#' testthat::expect_false(DAISIE:::is_simulation_outputs("nonsense")) -#' -#' simulation_outputs <- DAISIE_sim_cr( -#' time = 2, -#' M = 1000, -#' pars = c(2, 1, 20, 0.0001, 1), -#' replicates = 1, -#' plot_sims = FALSE -#' ) -#' testthat::expect_true(DAISIE:::is_simulation_outputs(simulation_outputs)) -#' @keywords internal +#' @noRd is_simulation_outputs <- function(simulation_outputs) { for (n_replicate in seq_along(simulation_outputs)) { if (!"island_age" %in% names(simulation_outputs[[n_replicate]][[1]])) @@ -164,22 +133,10 @@ is_simulation_outputs <- function(simulation_outputs) { #' #' @inheritParams default_params_doc #' -#' @export #' @return Boolean that indicates if list conforms to expected area parameters #' as created by \link{create_area_pars} #' @author Richel J.C Bilderbeek, Joshua Lambert, Pedro Neves -#' @keywords internal -#' -#' @examples -#' testit::assert(DAISIE:::are_area_pars( -#' create_area_pars( -#' max_area = 10, -#' current_area = 4, -#' proportional_peak_t = 0.5, -#' total_island_age = 5, -#' sea_level_amplitude = 5, -#' sea_level_frequency = 10, -#' island_gradient_angle = 0))) +#' @noRd are_area_pars <- function(area_pars) { if (is.null(area_pars) == TRUE) return(TRUE) if (class(area_pars) != class(list())) return(FALSE) @@ -208,12 +165,7 @@ are_area_pars <- function(area_pars) { #' @return \code{TRUE} if list contains hyperparameters, \code{FALSE} otherwise. #' @author Pedro Neves, Joshua Lambert #' -#' @keywords internal -#' -#' @examples -#' testit::assert( -#' DAISIE:::are_hyper_pars(create_hyper_pars(d = 0.027, x = 0.15)) -#' ) +#' @noRd are_hyper_pars <- function(hyper_pars) { if (!is.list(hyper_pars)) return(FALSE) if (!is.numeric(unlist(hyper_pars))) return(FALSE) @@ -231,18 +183,7 @@ are_hyper_pars <- function(hyper_pars) { #' @return Boolean that indicates if list conforms to expected area parameters #' as created by \link{create_trait_pars} #' -#' @keywords internal -#' -#' @examples -#' testit::assert(DAISIE:::are_trait_pars( -#' create_trait_pars( -#' trans_rate = 0.5, -#' immig_rate2 = 0.1, -#' ext_rate2 = 0.2, -#' ana_rate2 = 0.3, -#' clado_rate2 = 0.4, -#' trans_rate2 = 0.5, -#' M2 = 1000)) == TRUE) +#' @noRd are_trait_pars <- function(trait_pars) { if (is.null(trait_pars) == TRUE) return(TRUE) if (class(trait_pars) != class(list())) return(FALSE) diff --git a/R/DAISIE_dataprep.R b/R/DAISIE_dataprep.R index 95a36060..d38340e8 100644 --- a/R/DAISIE_dataprep.R +++ b/R/DAISIE_dataprep.R @@ -196,11 +196,11 @@ DAISIE_dataprep = function(datatable, if(max(the_brts)>island_age){ if (verbose == TRUE) { - print(paste("Colonisation time of ", + message("Colonisation time of ", max(the_brts), " for ", as.character(datatable[i, "Clade_name"]), - " is older than island age", sep = "")) + " is older than island age") } if(datatable[i,"Status"] == "Endemic" | datatable[i,"Status"] == "endemic" ){ datatable[i,"Status"] <-"Endemic_MaxAge"} diff --git a/R/DAISIE_format_CS_full_stt.R b/R/DAISIE_format_CS_full_stt.R index d46f23fd..4d92c5a8 100644 --- a/R/DAISIE_format_CS_full_stt.R +++ b/R/DAISIE_format_CS_full_stt.R @@ -147,10 +147,9 @@ DAISIE_format_CS_full_stt <- function(island_replicates, } several_islands[[rep]] <- island_list if (verbose == TRUE) { - message(paste0("Island being formatted: ", - rep, - "/", - length(island_replicates))) + message( + "Island being formatted: ", rep, "/", length(island_replicates) + ) } } return(several_islands) diff --git a/R/DAISIE_format_GW.R b/R/DAISIE_format_GW.R index 8a100753..61cf16c0 100644 --- a/R/DAISIE_format_GW.R +++ b/R/DAISIE_format_GW.R @@ -94,11 +94,9 @@ DAISIE_format_GW <- function(island_replicates, several_islands[[rep]] <- island_list if (verbose == TRUE) { - print(paste("Island being formatted: ", - rep, - "/", - length(island_replicates), - sep = "")) + message( + "Island being formatted: ", rep, "/", length(island_replicates) + ) } } return(several_islands) diff --git a/R/DAISIE_format_IW.R b/R/DAISIE_format_IW.R index f9509aa4..9584c632 100644 --- a/R/DAISIE_format_IW.R +++ b/R/DAISIE_format_IW.R @@ -5,39 +5,7 @@ #' #' @return List with CS DAISIE simulation output #' -#' @keywords internal -#' -#' @examples -#' island_replicates <- list() -#' island_replicates[[1]] <- DAISIE:::DAISIE_sim_core_cr( -#' time = 5, -#' mainland_n = 1000, -#' pars = c(2, 2, 40, 0.1, 1), -#' area_pars = DAISIE::create_area_pars( -#' max_area = 1, -#' current_area = 1, -#' proportional_peak_t = 0, -#' total_island_age = 0, -#' sea_level_amplitude = 0, -#' sea_level_frequency = 0, -#' island_gradient_angle = 0), -#' hyper_pars = create_hyper_pars(d = 0.2, x = 0.1), -#' nonoceanic_pars = c(0, 0) -#') -#' formatted_island_sampled <- DAISIE:::DAISIE_format_IW( -#' island_replicates = island_replicates, -#' time = 5, -#' M = 1000, -#' sample_freq = 25, -#' verbose = FALSE -#') -#' formatted_island_full <- DAISIE:::DAISIE_format_IW( -#' island_replicates = island_replicates, -#' time = 5, -#' M = 1000, -#' sample_freq = Inf, -#' verbose = FALSE -#') +#' @noRd DAISIE_format_IW <- function(island_replicates, time, M, diff --git a/R/DAISIE_loglik_CS.R b/R/DAISIE_loglik_CS.R index f290b764..d3677680 100644 --- a/R/DAISIE_loglik_CS.R +++ b/R/DAISIE_loglik_CS.R @@ -1048,7 +1048,7 @@ print_parameters_and_loglik <- function(pars, type = 'island_loglik', distance_dep = NULL) { - if (verbose >= 1) { + if (isTRUE(verbose >= 2)) { if(type == 'clade_loglik') { s1a <- sprintf("Status of colonist: %d", pars[1]) s1b <- sprintf("Parameters:") @@ -1056,12 +1056,12 @@ print_parameters_and_loglik <- function(pars, s2 <- paste(sprintf("%f", pars[-1]), collapse = ', ') s12 <- paste(s1, s2, collapse = ' ') s3 <- paste(sprintf("Loglikelihood: %f", loglik), collapse = '') - cat(s12, s3, sep = ', ') + message(paste(s12, s3, sep = ', ')) } else { if(type == 'global_ML') { s1 <- s1output(pars, distance_dep) s3 <- sprintf("Maximum Loglikelihood: %f", loglik) - cat(s1,s3,sep = '\n') + message(paste(s1, s3, sep = '\n')) } else { if(is.null(ncol(pars))) { lpars <- length(pars) @@ -1079,7 +1079,7 @@ print_parameters_and_loglik <- function(pars, s1 <- sprintf("Maximum likelihood parameters: ") s2 <- paste(sprintf("%f", pars), collapse = ', ') s3 <- sprintf("Maximum Loglikelihood: %f", loglik) - cat(s1, parnames, s2, s3, sep = '\n') + message(paste(s1, parnames, s2, s3, sep = '\n')) } else { if(type == 'multiple_island_ML') { s1 <- sprintf("Maximum likelihood parameters: ") @@ -1088,13 +1088,13 @@ print_parameters_and_loglik <- function(pars, s2 <- paste(s2,paste(sprintf("%f", pars[i,]), collapse = ', '), sep = '\n') } s3 <- sprintf("Maximum Loglikelihood: %f", loglik) - cat(s1, s2, s3, sep = '\n') + message(paste(s1, s2, s3, sep = '\n')) } else { if(type == 'island_loglik') { s1 <- sprintf("Parameters: ") s2 <- paste(sprintf("%f", pars), collapse = ', ') s3 <- sprintf("Loglikelihood: %f", loglik) - cat(s1, parnames, s2, s3, sep = '\n') + message(paste(s1, parnames, s2, s3, sep = '\n')) } else { stop('Type of printing output unknown') } @@ -1102,8 +1102,6 @@ print_parameters_and_loglik <- function(pars, } } } - cat('\n') - utils::flush.console() } } @@ -1221,7 +1219,7 @@ DAISIE_integrate_const <- function(initprobs,tvec,rhs_func,pars,rtol,atol,method # During code coverage, 'function_as_text' may become: # # if (TRUE) { - # covr:::count("DAISIE_loglik_CS.R:58:3:58:25:3:25:4657:4657") + # covr::count("DAISIE_loglik_CS.R:58:3:58:25:3:25:4657:4657") # lx <- (length(x) - 1)/2 # } # diff --git a/R/DAISIE_loglik_IW.R b/R/DAISIE_loglik_IW.R index 72c7aa50..6a059c48 100644 --- a/R/DAISIE_loglik_IW.R +++ b/R/DAISIE_loglik_IW.R @@ -305,7 +305,7 @@ DAISIE_loglik_IW <- function( } if(is.null(np)) { - cat('Number of species not present is misspecified.\n') + warning('Number of species not present is misspecified.') loglik <- NA return(loglik) } @@ -315,7 +315,7 @@ DAISIE_loglik_IW <- function( if(length(pars1) == 6) { M <- pars1[6] } else { - cat("pars1 should contain 5 or 6 values.\n") + warning("pars1 should contain 5 or 6 values.") loglik <- NA return(loglik) } @@ -381,10 +381,9 @@ DAISIE_loglik_IW <- function( expandvec <- NULL for (k in 0:(length(brts) - 2)) { - if (pars2[4] == 2) + if (isTRUE(identical(pars2[4], 3))) { - cat(paste('k = ',k,', sysdim = ',sysdim,'\n',sep = '')) - utils::flush.console() + message(paste('k = ',k ,', sysdim = ', sysdim, sep = '')) } dime <- list(lxm = lxm, lxe = lxe, sysdim = sysdim) if (sysdimchange == 1) { @@ -503,7 +502,7 @@ DAISIE_loglik_IW <- function( probs <- .Call("daisie_odeint_iw", probs, c(min(brts),0), iw_parms, methode, abstolint, reltolint) } else { y <- deSolve::ode(y = probs, - times = c(min(brts),0), + times = c(min(brts), 0), func = DAISIE_loglik_rhs_IW, parms = iw_parms, rtol = reltolint, diff --git a/R/DAISIE_make_archipelago.R b/R/DAISIE_make_archipelago.R index 07189041..f06ccd07 100644 --- a/R/DAISIE_make_archipelago.R +++ b/R/DAISIE_make_archipelago.R @@ -53,7 +53,7 @@ DAISIE_make_global <- function(archipelago_list, M, phylo_data, archipelago_data global_object <- list() for (i in 1:length(archipelago_list)) { the_archipelago <- as.character(archipelago_list[i]) - print(the_archipelago) + message(the_archipelago) global_object[[i]] <- DAISIE_make_archipelago(the_archipelago, M, phylo_data, archipelago_data) } return(global_object) diff --git a/R/DAISIE_max_rates.R b/R/DAISIE_max_rates.R index 45e6857e..77fa596e 100644 --- a/R/DAISIE_max_rates.R +++ b/R/DAISIE_max_rates.R @@ -60,8 +60,6 @@ update_max_rates <- function(gam, ana_max_rate = ana_max_rate, clado_max_rate = clado_max_rate ) - # print("max rates") - # print(max_rates) return(max_rates) } @@ -72,33 +70,7 @@ update_max_rates <- function(gam, #' #' @return Numeric maximum area during the simulation. #' -#' @keywords internal -#' -#' @examples -#' timeval <- 1 -#' total_time <- 10 -#' area_pars <- DAISIE::create_area_pars( -#' max_area = 5000, -#' current_area = 4000, -#' proportional_peak_t = 0.5, -#' total_island_age = 15, -#' sea_level_amplitude = 0, -#' sea_level_frequency = 0, -#' island_gradient_angle = 0 -#' ) -#' island_ontogeny <- 1 -#' sea_level <- 0 -#' peak <- DAISIE:::calc_peak(total_time = total_time, area_pars = area_pars) -#' testthat::expect_silent( -#' global_max_area_time <- DAISIE:::get_global_max_area( -#' total_time = total_time, -#' peak = peak, -#' area_pars = area_pars, -#' island_ontogeny = island_ontogeny, -#' sea_level = sea_level -#' ) -#' ) -#' +#' @noRd #' @author Pedro Neves, Joshua Lambert, Shu Xie get_global_max_area <- function(total_time, area_pars, @@ -139,34 +111,7 @@ get_global_max_area <- function(total_time, #' @inheritParams default_params_doc #' #' @return Numeric with time at which area is minimum during the simulation -#' -#' @examples -#' timeval <- 1 -#' total_time <- 10 -#' area_pars <- DAISIE::create_area_pars( -#' max_area = 5000, -#' current_area = 4000, -#' proportional_peak_t = 0.5, -#' total_island_age = 15, -#' sea_level_amplitude = 0, -#' sea_level_frequency = 0, -#' island_gradient_angle = 0 -#' ) -#' island_ontogeny <- 1 -#' sea_level <- 0 -#' peak <- DAISIE:::calc_peak(total_time = total_time, area_pars = area_pars) -#' -#' testthat::expect_silent( -#' DAISIE:::get_global_min_area( -#' total_time = total_time, -#' area_pars = area_pars, -#' peak = peak, -#' island_ontogeny = island_ontogeny, -#' sea_level = sea_level -#' ) -#' ) -#' -#' @keywords internal +#' @noRd #' #' @author Pedro Neves, Joshua Lambert, Shu Xie get_global_min_area <- function(total_time, diff --git a/R/DAISIE_plot_comparison_stts.R b/R/DAISIE_plot_comparison_stts.R index 1de3c0ee..409a4c17 100644 --- a/R/DAISIE_plot_comparison_stts.R +++ b/R/DAISIE_plot_comparison_stts.R @@ -2,14 +2,12 @@ #' #' @inheritParams default_params_doc #' -#' @seealso \code{\link{DAISIE_plot_sims}}, \code{\link{DAISIE_plot_stt}}, -#' \code{\link{DAISIE_convert_to_classic_plot}} +#' @seealso \code{\link{DAISIE_plot_sims}}, \code{\link{DAISIE_plot_stt}} #' @family plotting #' @return Standard \code{\link{DAISIE_plot_stt}} with overlaid additional #' STT curves for comparison. -#' @keywords internal -#' #' @author Pedro Neves +#' @noRd DAISIE_plot_comparison_stts <- function( time, plot_lists_simulations, diff --git a/R/DAISIE_plot_sims.R b/R/DAISIE_plot_sims.R index 37c00aa1..0af46f65 100644 --- a/R/DAISIE_plot_sims.R +++ b/R/DAISIE_plot_sims.R @@ -52,7 +52,7 @@ DAISIE_plot_sims <- function( plot_lists <- DAISIE_convert_to_classic_plot(island_replicates, trait_pars = trait_pars) } else { - stop("Plotting STT with sample_freq = Inf not yet available. \n") + stop("Plotting STT with sample_freq = Inf not yet available.") } if (type == "all") { types <- names(plot_lists) @@ -60,7 +60,8 @@ DAISIE_plot_sims <- function( types <- type } num_plots <- sum(!sapply(plot_lists[types], FUN = is.null)) - graphics::par(mfrow = c(1, num_plots)) + oldpar <- graphics::par(mfrow = c(1, num_plots)) + on.exit(graphics::par(oldpar)) for (type_here in types) { DAISIE_plot_stt( plot_plus_one = plot_plus_one, diff --git a/R/DAISIE_plot_stt.R b/R/DAISIE_plot_stt.R index c82b6d1a..2f0a0fc9 100644 --- a/R/DAISIE_plot_stt.R +++ b/R/DAISIE_plot_stt.R @@ -3,16 +3,9 @@ #' @inheritParams default_params_doc #' #' @seealso \code{\link{DAISIE_plot_stt}}, \code{\link{DAISIE_plot_sims}} -#' @examples -#' utils::data("islands_1type_1000reps", package = "DAISIE") -#' simulation_outuputs <- DAISIE:::DAISIE_convert_to_classic_plot( -#' islands_1type_1000reps -#' ) -#' -#' #' @return a list with wrangled data to be used for plotting STT plots with #' DAISIE_plot_stt -#' @keywords internal +#' @noRd DAISIE_convert_to_classic_plot <- function(simulation_outputs, trait_pars = NULL) { if (!is_simulation_outputs(simulation_outputs)) { diff --git a/R/DAISIE_rates.R b/R/DAISIE_rates.R index 77586314..ee8a574c 100644 --- a/R/DAISIE_rates.R +++ b/R/DAISIE_rates.R @@ -283,14 +283,7 @@ island_area <- function(timeval, #' @inheritParams default_params_doc #' #' @return Numeric with per capita extinction rate, given A(t), x, and mu0. -#' @keywords internal -#' -#' @examples -#' ext_rate_per_capita <- DAISIE:::get_ext_rate_per_capita( -#' mu = 0.5, -#' x = 1, -#' A = 1000 -#' ) +#' @noRd get_ext_rate_per_capita <- function(mu, x, extcutoff = 1000, @@ -404,15 +397,7 @@ get_ana_rate <- function(laa, #' #' @return Numeric with the per-capita cladogenesis rate given a base #' cladogenesis rate, K, A and the d hyperparameter. -#' @keywords internal -#' -#' @examples -#' lac <- 0.4 -#' d <- 0 -#' num_spec <- 2 -#' K <- 10 -#' A <- 1 -#' clado_rate_pc <- DAISIE:::get_clado_rate_per_capita(lac, d, num_spec, K, A) +#' @noRd get_clado_rate_per_capita <- function(lac, d, num_spec, @@ -494,15 +479,7 @@ get_clado_rate <- function(lac, #' @inheritParams default_params_doc #' #' @return A numeric with the per-capita immigration rate given A(t) and K. -#' @keywords internal -#' -#' @examples -#' immig_rate_per_capita <- DAISIE:::get_immig_rate_per_capita( -#' gam = 0.001, -#' num_spec = 5, -#' K = 20, -#' A = 1000 -#' ) +#' @noRd get_immig_rate_per_capita <- function(gam, num_spec, K, diff --git a/R/DAISIE_sim_MW.R b/R/DAISIE_sim_MW.R index b5795011..6f8d4365 100644 --- a/R/DAISIE_sim_MW.R +++ b/R/DAISIE_sim_MW.R @@ -245,9 +245,9 @@ DAISIE_sim_MW <- DAISIE_sim_global <- function( Archipelago <- as.character(Archipelago) archipelago_specific <- cbind(Archipelago,Area,Distance,Age,lambda_c,mu,K,gamma,lamda_a) - print('Input data and local parameters for each island:') - print(archipelago_specific) - print('Start of the simulations:') + message('Input data and local parameters for each island:') + message(archipelago_specific) + message('Start of the simulations:') global_sim <- list() for (i in 1:nrow(archipelago_specific)) { @@ -270,7 +270,13 @@ DAISIE_sim_MW <- DAISIE_sim_global <- function( global_sim[[i]][[a]][[1]]$name <- the_archipelago } - print(paste('Simulation of',as.character(archipelago_specific[i,'Archipelago']),'for',island_age,'Myrs each completed',sep=' ')) + message( + "Simulation of ", + as.character(archipelago_specific[i,'Archipelago']), + " for ", + island_age, + "Myrs each completed" + ) } return(global_sim) } diff --git a/R/DAISIE_sim_core_time_dep.R b/R/DAISIE_sim_core_time_dep.R index a3c988db..f1388641 100644 --- a/R/DAISIE_sim_core_time_dep.R +++ b/R/DAISIE_sim_core_time_dep.R @@ -109,11 +109,6 @@ DAISIE_sim_core_time_dep <- function( num_immigrants = num_immigrants, mainland_n = mainland_n ) - # print("rates") - # print(rates) - # print(island_spec) - # print(timeval) - # testit::assert(are_rates(rates)) possible_event <- DAISIE_sample_event_time_dep( max_rates = max_rates ) diff --git a/R/DAISIE_sim_cr_cs.R b/R/DAISIE_sim_cr_cs.R index 7e6e4839..d43bf2ce 100644 --- a/R/DAISIE_sim_cr_cs.R +++ b/R/DAISIE_sim_cr_cs.R @@ -44,7 +44,7 @@ DAISIE_sim_cr_cs <- function(total_time, } island_replicates[[rep]] <- full_list if (verbose == TRUE) { - print(paste("Island replicate ", rep, sep = "")) + message("Island replicate ", rep) } } } else if (length(pars) == 10) { @@ -113,7 +113,7 @@ DAISIE_sim_cr_cs <- function(total_time, } island_replicates[[rep]] <- full_list if (verbose == TRUE) { - print(paste("Island replicate ", rep, sep = "")) + message("Island replicate ", rep) } } } diff --git a/R/DAISIE_sim_cr_gw.R b/R/DAISIE_sim_cr_gw.R index 072224f5..5c0aeab0 100644 --- a/R/DAISIE_sim_cr_gw.R +++ b/R/DAISIE_sim_cr_gw.R @@ -37,7 +37,7 @@ DAISIE_sim_cr_gw <- function(total_time, } island_replicates[[rep]] <- full_list if (verbose == TRUE) { - print(paste("Island replicate ", rep, sep = "")) + message("Island replicate ", rep) } } island_replicates <- DAISIE_format_GW( diff --git a/R/DAISIE_sim_cr_iw.R b/R/DAISIE_sim_cr_iw.R index d2db9bad..0769782e 100644 --- a/R/DAISIE_sim_cr_iw.R +++ b/R/DAISIE_sim_cr_iw.R @@ -36,7 +36,7 @@ DAISIE_sim_cr_iw <- function(total_time, number_present <- length(present) } if (verbose == TRUE) { - print(paste("Island replicate ", rep, sep = "")) + message("Island replicate ", rep) } } island_replicates <- DAISIE_format_IW( diff --git a/R/DAISIE_sim_cr_shift.R b/R/DAISIE_sim_cr_shift.R index 3b1741c5..3bbea482 100644 --- a/R/DAISIE_sim_cr_shift.R +++ b/R/DAISIE_sim_cr_shift.R @@ -105,7 +105,7 @@ DAISIE_sim_cr_shift <- function( shift_times = shift_times ) if (verbose == TRUE) { - print(paste("Island replicate ", rep, sep = "")) + message("Island replicate ", rep) } } island_replicates <- DAISIE_format_IW(island_replicates = island_replicates, @@ -141,7 +141,7 @@ DAISIE_sim_cr_shift <- function( } island_replicates[[rep]] <- full_list if (verbose == TRUE) { - print(paste("Island replicate ", rep, sep = "")) + message("Island replicate ", rep) } } island_replicates <- DAISIE_format_CS( @@ -176,7 +176,7 @@ DAISIE_sim_cr_shift <- function( } island_replicates[[rep]] <- full_list if (verbose == TRUE) { - print(paste("Island replicate ", rep, sep = "")) + message("Island replicate ", rep) } } island_replicates <- DAISIE_format_GW(island_replicates = island_replicates, diff --git a/R/DAISIE_sim_min_type2.R b/R/DAISIE_sim_min_type2.R index 31a13f48..016ae579 100644 --- a/R/DAISIE_sim_min_type2.R +++ b/R/DAISIE_sim_min_type2.R @@ -68,14 +68,15 @@ DAISIE_sim_min_type2 <- function(time, island_replicates[[length(island_replicates) + 1]] <- list() island_replicates[[length(island_replicates)]] <- full_list if (verbose == TRUE) { - print(paste("Number of island replicates with type 2 species: ", - length(island_replicates), - sep = "")) + message( + "Number of island replicates with type 2 species: ", + length(island_replicates) + ) } } counter <- counter + 1 if (verbose == TRUE) { - print(paste("Island ", counter, sep = "")) + message("Island ", counter) } } return(island_replicates) diff --git a/R/DAISIE_sim_relaxed_rate.R b/R/DAISIE_sim_relaxed_rate.R index 1c2271df..451632d6 100644 --- a/R/DAISIE_sim_relaxed_rate.R +++ b/R/DAISIE_sim_relaxed_rate.R @@ -149,7 +149,7 @@ DAISIE_sim_relaxed_rate <- function( } island_replicates[[rep]] <- full_list if (verbose == TRUE) { - print(paste("Island replicate ", rep, sep = "")) + message("Island replicate ", rep) } } island_replicates <- DAISIE_format_CS( diff --git a/R/DAISIE_sim_time_dep_cs.R b/R/DAISIE_sim_time_dep_cs.R index 61991812..d54814ba 100644 --- a/R/DAISIE_sim_time_dep_cs.R +++ b/R/DAISIE_sim_time_dep_cs.R @@ -53,7 +53,7 @@ DAISIE_sim_time_dep_cs <- function(total_time, } island_replicates[[rep]] <- full_list if (verbose == TRUE) { - print(paste("Island replicate ", rep, sep = "")) + message("Island replicate ", rep) } } island_replicates <- DAISIE_format_CS( diff --git a/R/DAISIE_sim_time_dep_gw.R b/R/DAISIE_sim_time_dep_gw.R index ccd57bcd..4891b7eb 100644 --- a/R/DAISIE_sim_time_dep_gw.R +++ b/R/DAISIE_sim_time_dep_gw.R @@ -49,7 +49,7 @@ DAISIE_sim_time_dep_gw <- function(total_time, } island_replicates[[rep]] <- full_list if (verbose == TRUE) { - print(paste("Island replicate ", rep, sep = "")) + message("Island replicate ", rep) } } island_replicates <- DAISIE_format_GW( diff --git a/R/DAISIE_sim_time_dep_iw.R b/R/DAISIE_sim_time_dep_iw.R index 18863a2b..bd91a10b 100644 --- a/R/DAISIE_sim_time_dep_iw.R +++ b/R/DAISIE_sim_time_dep_iw.R @@ -48,7 +48,7 @@ DAISIE_sim_time_dep_iw <- function(total_time, number_present <- length(present) } if (verbose == TRUE) { - print(paste("Island replicate ", rep, sep = "")) + message("Island replicate ", rep) } } island_replicates <- DAISIE_format_IW( diff --git a/R/DAISIE_sim_trait_dep.R b/R/DAISIE_sim_trait_dep.R index 4beeb503..4f575444 100644 --- a/R/DAISIE_sim_trait_dep.R +++ b/R/DAISIE_sim_trait_dep.R @@ -91,7 +91,7 @@ DAISIE_sim_trait_dep <- function( trait_pars = trait_pars ) if (verbose == TRUE) { - print(paste("Island replicate ", rep, sep = "")) + message("Island replicate ", rep) } } island_replicates <- DAISIE_format_IW( @@ -168,7 +168,7 @@ DAISIE_sim_trait_dep <- function( } island_replicates[[rep]] <- full_list if (verbose == TRUE) { - print(paste("Island replicate ", rep, sep = "")) + message("Island replicate ", rep) } } island_replicates <- DAISIE_format_CS( diff --git a/R/DAISIE_sim_trait_dep_2K.R b/R/DAISIE_sim_trait_dep_2K.R index 5496884e..24e98a5a 100644 --- a/R/DAISIE_sim_trait_dep_2K.R +++ b/R/DAISIE_sim_trait_dep_2K.R @@ -92,7 +92,7 @@ DAISIE_sim_trait_dep_2K <- function( trait_pars = trait_pars ) if (verbose == TRUE) { - print(paste("Island replicate ", rep, sep = "")) + message("Island replicate ", rep) } } island_replicates <- DAISIE_format_IW( @@ -171,7 +171,7 @@ DAISIE_sim_trait_dep_2K <- function( } island_replicates[[rep]] <- full_list if (verbose == TRUE) { - print(paste("Island replicate ", rep, sep = "")) + message("Island replicate ", rep) } } island_replicates <- DAISIE_format_CS( diff --git a/R/DAISIE_sumstats_rates.R b/R/DAISIE_sumstats_rates.R index ae9ebdc6..062945e3 100644 --- a/R/DAISIE_sumstats_rates.R +++ b/R/DAISIE_sumstats_rates.R @@ -5,38 +5,8 @@ #' #' @inheritParams default_params_doc #' @author Pedro Neves -#' @keywords internal +#' @noRd #' @return A named list with mean and median values of specified parameters -#' @examples -#' pars <- c(0.01, 1, 20, 0.01, 1) -#' area_pars <- create_area_pars( -#' max_area = 13500, -#' current_area = 3500, -#' proportional_peak_t = 0.1, -#' total_island_age = 15, -#' sea_level_amplitude = 0, -#' sea_level_frequency = 0, -#' island_gradient_angle = 0 -#' ) -#' hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) -#' island_ontogeny <- 1 -#' sea_level <- 0 -#' extcutoff <- 1100 -#' resol <- 100 -#' total_time <- 10 -#' mainland_n <- 1000 -#' -#' mean_med <- DAISIE:::DAISIE_calc_sumstats_pcrates( -#' pars = pars, -#' total_time = total_time, -#' area_pars = area_pars, -#' hyper_pars = hyper_pars, -#' island_ontogeny = island_ontogeny, -#' sea_level = sea_level, -#' extcutoff = extcutoff, -#' mainland_n = mainland_n, -#' resol = resol -#' ) DAISIE_calc_sumstats_pcrates <- function( pars, total_time, diff --git a/R/DAISIE_utils.R b/R/DAISIE_utils.R index 8c34aa30..35bc8d67 100644 --- a/R/DAISIE_utils.R +++ b/R/DAISIE_utils.R @@ -279,8 +279,7 @@ sample_relaxed_rate <- function(pars, #' @inheritParams default_params_doc #' #' @return Numeric, 0 for null-ontogeny, 1 for beta function -#' @keywords internal -#' @examples translated_ontogeny <- DAISIE:::translate_island_ontogeny("const") +#' @noRd translate_island_ontogeny <- function(island_ontogeny) { if (island_ontogeny == "const" || island_ontogeny == 0) { @@ -297,8 +296,7 @@ translate_island_ontogeny <- function(island_ontogeny) { #' @inheritParams default_params_doc #' #' @return Numeric, 0 for null-sea-level, 1 for sine function -#' @keywords internal -#' @examples translated_sea_level <- DAISIE:::translate_sea_level("const") +#' @noRd translate_sea_level <- function(sea_level) { if (sea_level == "const" || sea_level == 0) { @@ -321,11 +319,7 @@ translate_sea_level <- function(sea_level) { #' #' @return A list of non-endemic species, endemic species and the new #' mainland species pool -#' @examples DAISIE:::DAISIE_nonoceanic_spec( -#' prob_samp = 0.1, -#' prob_nonend = 0.9, -#' mainland_n = 1000) -#' @keywords internal +#' @noRd DAISIE_nonoceanic_spec <- function(prob_samp, prob_nonend, mainland_n) { testit::assert(prob_samp <= 1) testit::assert(prob_samp >= 0) @@ -453,3 +447,75 @@ add_column_to_dataframe <- function(df, position, column_to_insert) { names(df)[names(df) == 'nc'] <- names(column_to_insert) return(df) } + + +#' Print optimisation settings +#' +#' @inheritParams default_params_doc +#' @param all_no_shift numeric vector with the standard no shifted values +#' depending on a model. Internal parameter to DAISIE_ML1, set to NA upstream +#' if not needed to prevent shift message being generated. +#' +#' @return Invisible `NULL`. Prints a `message()` to the console with the parameters +#' that are to be optimized, fixed, and shifted if `verbose >= 1`. +#' @noRd +print_ml_par_settings <- function(namepars, + idparsopt, + idparsfix, + idparsnoshift, + all_no_shift, + verbose) { + if (isTRUE(verbose >= 1)) { + + if (length(namepars[idparsopt]) == 0) { + optstr <- "nothing" + } else { + optstr <- namepars[idparsopt] + } + + opt_print <- paste0("You are optimizing: ", paste(optstr, collapse = " ")) + if (length(namepars[idparsfix]) == 0) { + fixstr <- "nothing" + } else { + fixstr <- namepars[idparsfix] + } + fix_print <- paste0("You are fixing: ", paste(fixstr, collapse = " ")) + + if (any(is.numeric(idparsnoshift)) && + sum(idparsnoshift %in% (all_no_shift)) != 5) { + noshiftstring <- namepars[idparsnoshift] + shift_prt <- paste0( + "You are not shifting: ", + paste(noshiftstring, collapse = " ") + ) + message(paste(opt_print, fix_print, shift_prt, sep = "\n")) + } else { + message(paste(opt_print, fix_print, sep = "\n")) + } + + } + + invisible(NULL) +} + +#' Print likelihood for initial parameters +#' +#' @inheritParams default_params_doc +#' @param initloglik A numeric with the value of loglikehood obtained prior to +#' optimisation. Only used internally. +#' +#' @return Invisible `NULL`. Prints a `message()` to the console with the +#' initial loglikelihood if `verbose >= 1` +#' @noRd +print_init_ll <- function(initloglik, + verbose) { + if (isTRUE(verbose >= 1)) { + init_ll_msg1 <- "Calculating the likelihood for the initial parameters." + init_ll_msg2 <- paste0("The loglikelihood for the initial parameter values is ", initloglik) + init_ll_msg3 <- c("Optimizing the likelihood - this may take a while.") + message(paste(init_ll_msg1, init_ll_msg2, init_ll_msg3, sep = "\n")) + + } + + invisible(NULL) +} diff --git a/R/RcppExports.R b/R/RcppExports.R index 5d754b1e..6b86ed04 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -1,16 +1,21 @@ # Generated by using Rcpp::compileAttributes() -> do not edit by hand # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 +#' Driver for the boost::odeint solver for the CS model +#' +#' @name daisie_odeint_cs #' @export daisie_odeint_cs +#' @return Object of type `state_type`, which itself is +#' `vector_t`, with the result of the +#' integration depending on the runmod chosen. NULL -#' Driver for the boost::odeint solver -#' -#' @name daisie_odeint_cs +#' @export daisie_odeint_iw NULL -#' Driver for the boost::odeint solver +#' Driver for the boost::odeint solver for the IW model #' #' @name daisie_odeint_iw +#' @export daisie_odeint_iw NULL diff --git a/R/create_pars.R b/R/create_pars.R index 19eac88e..56a022bb 100644 --- a/R/create_pars.R +++ b/R/create_pars.R @@ -33,10 +33,8 @@ create_pars <- function(clado_rate, #' @export #' @author Richel J.C Bilderbeek, Joshua Lambert, Pedro Neves #' -#' #' @examples -#' testit::assert(DAISIE:::are_area_pars( -#' create_area_pars( +#' area_pars <- create_area_pars( #' max_area = 10, #' current_area = 1, #' proportional_peak_t = 0.5, @@ -44,9 +42,9 @@ create_pars <- function(clado_rate, #' sea_level_amplitude = 5, #' sea_level_frequency = 10, #' island_gradient_angle = 0 -#' ) -#' ) -#' ) +#' +#' +#' ) create_area_pars <- function(max_area, current_area, proportional_peak_t, @@ -105,15 +103,15 @@ create_hyper_pars <- function(d, x) { #' @export #' #' @examples -#' testit::assert(DAISIE:::are_trait_pars( -#' create_trait_pars( -#' trans_rate = 0.5, -#' immig_rate2 = 0.1, -#' ext_rate2 = 0.2, -#' ana_rate2 = 0.3, -#' clado_rate2 = 0.4, -#' trans_rate2 = 0.5, -#' M2 = 1000)) == TRUE) +#' trait_pars <- create_trait_pars( +#' trans_rate = 0.5, +#' immig_rate2 = 0.1, +#' ext_rate2 = 0.2, +#' ana_rate2 = 0.3, +#' clado_rate2 = 0.4, +#' trans_rate2 = 0.5, +#' M2 = 1000 +#' ) create_trait_pars <- function(trans_rate, immig_rate2, ext_rate2, diff --git a/R/default_params_doc.R b/R/default_params_doc.R index e205477a..1cc094b0 100644 --- a/R/default_params_doc.R +++ b/R/default_params_doc.R @@ -73,12 +73,15 @@ #' of species is present, STT is plotted for all species. If two types are #' present, three plots are produced: STT for all, STT for type 1 and STT for #' type 2. -#' @param verbose In simulation and dataprep functions a logical, -#' \code{Default = TRUE} gives intermediate output should be printed. +#' @param verbose A numeric vector of length 1, which in simulations and +#' `DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +#' should be printed. #' For ML functions a numeric determining if intermediate output should be -#' printed, \code{Default = 0} does not print, \code{verbose = 1} prints -#' intermediate output of the parameters and loglikelihood, \code{verbose = 2} -#' means also intermediate progress during loglikelihood computation is shown. +#' printed. The default: `0` does not print, `1` prints the initial +#' likelihood and the settings that were selected (which parameters are +#' to be optimised, fixed or shifted), `2` prints the same as `1 and also the +#' intermediate output of the parameters and loglikelihood, while `3` the +#' same as `2` and prints intermediate progress during likelihood computation. #' @param area_pars A named list containing area and sea level parameters as #' created by \code{\link{create_area_pars}()}: #' \itemize{ @@ -101,8 +104,7 @@ #' @param island_ontogeny In \code{\link{DAISIE_sim_time_dep}()}, #' \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of #' island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -#' describing area through time. String checked by -#' \code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +#' describing area through time. \cr In all other functions a #' numeric describing the type of island ontogeny. Can be \code{0} for #' constant, \code{1} for a beta function describing area through time. In ML #' functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -110,8 +112,7 @@ #' Will return an error if called in that case. #' @param sea_level In \code{\link{DAISIE_sim_time_dep}()} and plotting a #' string describing the type of sea level. Can be \code{"const"} or -#' \code{"sine"} for a sine function describing area through time. String -#' checked by \code{\link{is_sea_level_input}()}. +#' \code{"sine"} for a sine function describing area through time. #' \cr In all other functions a numeric describing the type of sea level. Can #' be \code{0} for constant, \code{1} for a sine function describing area #' through time. diff --git a/inst/COPYRIGHTS b/inst/COPYRIGHTS new file mode 100644 index 00000000..30e48cc6 --- /dev/null +++ b/inst/COPYRIGHTS @@ -0,0 +1,31 @@ +Files: src/DAISIE_CS.cpp src/DAISIE_IW.cpp src/DAISIE_odeint.h src/DAISIE_types.h +Copyright: 2023 Hanno Hildenbrandt +License: BSL-1.0 + +Files: src/DAISIE_loglik_rhs_FORTRAN.95 +Copyright: 2023 Rampal S. Etienne +License: BSL-1.0 + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +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, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/inst/LICENSE_1_0.txt b/inst/LICENSE_1_0.txt new file mode 100644 index 00000000..36b7cd93 --- /dev/null +++ b/inst/LICENSE_1_0.txt @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +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, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/man/DAISIE_ML.Rd b/man/DAISIE_ML.Rd index 057774ac..098d672d 100644 --- a/man/DAISIE_ML.Rd +++ b/man/DAISIE_ML.Rd @@ -122,8 +122,7 @@ on the island. This last option is not yet available for the IW model \cr} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -182,12 +181,15 @@ model, for a relaxed-rate model a list with the following elements: \code{"immigration"}, or \code{"anagenesis"}.} }} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} \item{tolint}{Vector of two elements containing the absolute and relative tolerance of the integration.} diff --git a/man/DAISIE_ML1.Rd b/man/DAISIE_ML1.Rd index a908afc6..158de7c1 100644 --- a/man/DAISIE_ML1.Rd +++ b/man/DAISIE_ML1.Rd @@ -154,12 +154,15 @@ model, for a relaxed-rate model a list with the following elements: \code{"immigration"}, or \code{"anagenesis"}.} }} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} \item{tolint}{Vector of two elements containing the absolute and relative tolerance of the integration.} @@ -167,8 +170,7 @@ tolerance of the integration.} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time diff --git a/man/DAISIE_ML2.Rd b/man/DAISIE_ML2.Rd index d7c726c7..1521dfe1 100644 --- a/man/DAISIE_ML2.Rd +++ b/man/DAISIE_ML2.Rd @@ -105,8 +105,7 @@ on the island. This last option is not yet available for the IW model \cr} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -136,12 +135,15 @@ and \code{"ode45"} from \code{\link[deSolve]{ode}()} for `subplex` (see `\link[subplex]{subplex}()` for full details). Alternative is \code{"simplex"} which was the method in previous versions.} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} \item{tolint}{Vector of two elements containing the absolute and relative tolerance of the integration.} diff --git a/man/DAISIE_ML4.Rd b/man/DAISIE_ML4.Rd index b30ae271..e31fc101 100644 --- a/man/DAISIE_ML4.Rd +++ b/man/DAISIE_ML4.Rd @@ -129,12 +129,15 @@ model, for a relaxed-rate model a list with the following elements: \code{"immigration"}, or \code{"anagenesis"}.} }} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} \item{tolint}{Vector of two elements containing the absolute and relative tolerance of the integration.} @@ -142,8 +145,7 @@ tolerance of the integration.} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time diff --git a/man/DAISIE_ML_IW.Rd b/man/DAISIE_ML_IW.Rd index 50ef9088..51b53994 100644 --- a/man/DAISIE_ML_IW.Rd +++ b/man/DAISIE_ML_IW.Rd @@ -115,12 +115,15 @@ and \code{"ode45"} from \code{\link[deSolve]{ode}()} for `subplex` (see `\link[subplex]{subplex}()` for full details). Alternative is \code{"simplex"} which was the method in previous versions.} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} \item{tolint}{Vector of two elements containing the absolute and relative tolerance of the integration.} diff --git a/man/DAISIE_SR_ML.Rd b/man/DAISIE_SR_ML.Rd index 288c28c4..f4e0f720 100644 --- a/man/DAISIE_SR_ML.Rd +++ b/man/DAISIE_SR_ML.Rd @@ -166,10 +166,13 @@ used, otherwise the information in the data is overruled. } \examples{ -\dontrun{ -### When all species have the same rates, and we want to optimize all 5 parameters, -# we use: - +\donttest{ +## In all following DAISIE_ML calls very high tolerances and low system size +## are used for fast computation for this example. Use default or better +## tol, tolint an res values in actual analyses. +################## +### When all species have the same rates, and we want to optimize all 5 +### parameters, we use: utils::data(Galapagos_datalist) DAISIE_ML( datalist = Galapagos_datalist, @@ -177,7 +180,10 @@ DAISIE_ML( ddmodel = 11, idparsopt = 1:5, parsfix = NULL, - idparsfix = NULL + idparsfix = NULL, + tol = c(0.1, 0.02, 0.01), + tolint = c(1e-4, 1e-2), + res = 50 ) ### When all species have the same rates, and we want to optimize all parameters @@ -189,7 +195,10 @@ DAISIE_ML( initparsopt = c(2.5,2.7,0.009,1.01), idparsopt = c(1,2,4,5), parsfix = Inf, - idparsfix = 3 + idparsfix = 3, + tol = c(0.1, 0.02, 0.01), + tolint = c(1e-4, 1e-2), + res = 50 ) ### When all species have the same rates except that the finches have a different @@ -203,7 +212,10 @@ DAISIE_ML( idparsopt = c(1,2,4,5,6), parsfix = c(Inf,Inf,0.163), idparsfix = c(3,8,11), - idparsnoshift = c(7,9,10) + idparsnoshift = c(7,9,10), + tol = c(0.1, 0.02, 0.01), + tolint = c(1e-4, 1e-2), + res = 50 ) ### When all species have the same rates except that the finches have a different @@ -218,7 +230,10 @@ DAISIE_ML( idparsopt = c(1,2,4,5,6,7,8), parsfix = c(Inf,0.163), idparsfix = c(3,11), - idparsnoshift = c(9,10) + idparsnoshift = c(9,10), + tol = c(0.1, 0.02, 0.01), + tolint = c(1e-4, 1e-2), + res = 50 ) @@ -234,7 +249,10 @@ DAISIE_ML( idparsopt = c(1,2,4,5,7,11), parsfix = c(Inf,Inf), idparsfix = c(3,8), - idparsnoshift = c(6,9,10) + idparsnoshift = c(6,9,10), + tol = c(0.1, 0.02, 0.01), + tolint = c(1e-4, 1e-2), + res = 50 ) ### When we have two islands with the same rates except for immigration and anagenesis rate, @@ -248,7 +266,10 @@ DAISIE_ML( idparsmat = rbind(1:5,c(1:3,6,7)), idparsopt = 1:7, parsfix = NULL, - idparsfix = NULL + idparsfix = NULL, + tol = c(0.1, 0.02, 0.01), + tolint = c(1e-4, 1e-2), + res = 50 ) ### When we consider the four Macaronesia archipelagoes and set all parameters the same @@ -265,7 +286,10 @@ DAISIE_ML( idparsmat = rbind(1:5,c(6,2,3,7,5),1:5,1:5), idparsopt = c(2,4,5,6,7), parsfix = c(0,Inf), - idparsfix = c(1,3) + idparsfix = c(1,3), + tol = c(0.1, 0.02, 0.01), + tolint = c(1e-4, 1e-2), + res = 50 ) } diff --git a/man/DAISIE_SR_loglik_CS.Rd b/man/DAISIE_SR_loglik_CS.Rd index 31eb60fb..63064fba 100644 --- a/man/DAISIE_SR_loglik_CS.Rd +++ b/man/DAISIE_SR_loglik_CS.Rd @@ -14,8 +14,7 @@ DAISIE_SR_loglik_CS( methode = "lsodes", CS_version = 1, abstolint = 1e-16, - reltolint = 1e-10, - verbose = FALSE + reltolint = 1e-10 ) } \arguments{ @@ -104,8 +103,6 @@ model, for a relaxed-rate model a list with the following elements: \item{abstolint}{Absolute tolerance of the integration} \item{reltolint}{Relative tolerance of the integration} - -\item{verbose}{Logical controling if progress is printed to console.} } \value{ The loglikelihood diff --git a/man/DAISIE_SR_sim.Rd b/man/DAISIE_SR_sim.Rd deleted file mode 100644 index e275045f..00000000 --- a/man/DAISIE_SR_sim.Rd +++ /dev/null @@ -1,129 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_SR_sim.R -\name{DAISIE_SR_sim} -\alias{DAISIE_SR_sim} -\title{DEPRECATED - Simulate islands with given parameters.} -\usage{ -DAISIE_SR_sim( - time, - M, - pars, - replicates, - sample_freq = 25, - plot_sims = TRUE, - ddep = 11, - verbose = FALSE, - ... -) -} -\arguments{ -\item{time}{Length of the simulation in time units. For example, if an -island is know to be 4 million years old, setting time = 4 will simulate -entire life span of the island; setting time = 2 will stop the simulation at -the mid-life of the island.} - -\item{M}{The size of the mainland pool, i.e the number of species that can -potentially colonize the island} - -\item{pars}{Contains the model parameters: \cr \cr \code{pars[1]} -corresponds to lambda^c (cladogenesis rate) before the shift \cr \code{pars[2]} corresponds -to mu (extinction rate) before the shift \cr \code{pars[3]} corresponds to K (clade-level -carrying capacity) before the shift. Set K=Inf for non-diversity dependence.\cr -\code{pars[4]} corresponds to gamma (immigration rate) before the shift \cr \code{pars[5]} -corresponds to lambda^a (anagenesis rate) before the shift \cr \code{pars[6]} corresponds to -lambda^c (cladogenesis rate) after the shift \cr \code{pars[7]} -corresponds to mu (extinction rate) after the shift \cr \code{pars[8]} -corresponds to K (clade-level carrying capacity) after the shift. Set -K=Inf for non-diversity dependence. \cr \code{pars[9]} corresponds to gamma -(immigration rate) after the shift \cr \code{pars[10]} corresponds to -lambda^a (anagenesis rate) after the shift \cr \code{pars[11]} corresponds to -the time of shift. This is defined as time before the end of the simulation. For example, -setting time = 4 and pars[11] = 1.5 will simulate with pars[1:5] from 4 to 1.5 and -with pars[6:10] from 1.5 to 0.} - -\item{replicates}{Number of island replicates to be simulated.} - -\item{sample_freq}{Specifies the number of units time should be divided by -for plotting purposes. Larger values will lead to plots with higher -resolution, but will also run slower.} - -\item{plot_sims}{Default=TRUE plots species-through-time (STT) plots. It -detects how many types of species are present. If only one type of species -is present, STT is plotted for all species. If two types are present, three -plots are produced: STT for all, STT for type 1 and STT for type 2.} - -\item{ddep}{= diversity-dependent model,mode of diversity-dependence \cr \cr -\code{ddep == 0} no diversity-dependence -\code{ddep == 1} linear dependence in speciation rate (anagenesis and cladogenesis) -\code{ddep == 11} linear dependence in speciation rate and immigration rate -\code{ddep == 3} linear dependence in extinction rate} - -\item{verbose}{\code{Default=TRUE} Give intermediate output, also if -everything goes OK.} - -\item{...}{Any arguments to pass on to plotting functions.} -} -\value{ -Each simulated dataset is an element of the list, which can be -called using [[x]]. For example if the object is called island_replicates, -the 1st replicate can be called using island_replicates[[1]] Each of the -island replicates is a list in itself. The first (e.g. -island_replicates[[x]][[1]]) element of that list has the following -components: \cr \code{$island_age} - the island age \cr Then, we have:\cr \code{$not_present} -- the number of mainland lineages that are not present on the island \cr -\code{$stt_all} - STT table for all species on the island (nI - number of -non-endemic species; nA - number of anagenetic species, nC - number of -cladogenetic species, present - number of independent colonisations present)\cr -The subsequent elements of the list each contain information on a single -colonist lineage on the island and has 4 components:\cr -\code{$branching_times} - island age and stem age of the population/species -in the case of Non-endemic, Non-endemic_MaxAge and Endemic anagenetic -species. For cladogenetic species these should be island age and branching -times of the radiation including the stem age of the radiation.\cr -\code{$stac} - the status of the colonist \cr * Non_endemic_MaxAge: 1 \cr * -Endemic: 2 \cr * Endemic&Non_Endemic: 3 \cr * Non_endemic: 4 \cr -\code{$missing_species} - number of island species that were not sampled for -particular clade (only applicable for endemic clades) \cr \code{$type_1or2} -- whether the colonist belongs to type 1 or type 2 \cr -} -\description{ -This function simulates islands with given cladogenesis, extinction, Kprime, -immigration and anagenesis parameters that shift at some time. -Runs the function with clade-specific -carrying capacity, where diversity-dependence operates only within single -clades, i.e. only among species originating from the same mainland -colonist. - -Returns R list object that contains the simulated islands. -} -\details{ -This function's use has been deprecated in favor -of \code{\link{DAISIE_sim_cr_shift}()}. Please use that -function instead. -} -\examples{ -# Simulate 15 islands for 4 million years with a shift in immigration rate -# at 0.195 Ma, and plot the species-through-time plot. Pool size 296. - -pars_before_shift = c(0.079, 0.973, Inf, 0.136, 0.413) -pars_after_shift = c(0.079, 0.973, Inf, 0.652, 0.413) -tshift = 0.195 -island_shift_replicates = DAISIE:::DAISIE_SR_sim( - time = 4, - M = 296, - pars = c(pars_before_shift, pars_after_shift, tshift), - replicates = 15 - ) -} -\references{ -Hauffe, T., D. Delicado, R.S. Etienne and L. Valente (2020). -Lake expansion increases equilibrium diversity via the target effect of -island biogeography -} -\seealso{ -\code{\link{DAISIE_plot_sims}()} -} -\author{ -Luis Valente, Albert Phillimore, and Torsten Hauffe -} -\keyword{internal} diff --git a/man/DAISIE_calc_sumstats_pcrates.Rd b/man/DAISIE_calc_sumstats_pcrates.Rd deleted file mode 100644 index 4f8d70d5..00000000 --- a/man/DAISIE_calc_sumstats_pcrates.Rd +++ /dev/null @@ -1,141 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_sumstats_rates.R -\name{DAISIE_calc_sumstats_pcrates} -\alias{DAISIE_calc_sumstats_pcrates} -\title{Calculate summary statistics of per capita rates} -\usage{ -DAISIE_calc_sumstats_pcrates( - pars, - total_time, - area_pars, - hyper_pars, - island_ontogeny = 1, - sea_level = 0, - extcutoff = 100, - mainland_n = 1000, - resol = 100 -) -} -\arguments{ -\item{pars}{A numeric vector containing the model parameters: -\itemize{ - \item{\code{pars[1]}: lambda^c (cladogenesis rate)} - \item{\code{pars[2]}: mu (extinction rate)} - \item{\code{pars[3]}: K (carrying capacity), set K=Inf for diversity - independence.} - \item{\code{pars[4]}: gamma (immigration rate)} - \item{\code{pars[5]}: lambda^a (anagenesis rate)} - \item{\code{pars[6]}: lambda^c (cladogenesis rate) for either type 2 species - or rate set 2 in rate shift model} - \item{\code{pars[7]}: mu (extinction rate) for either type 2 species or rate - set 2 in rate shift model} - \item{\code{pars[8]}: K (carrying capacity) for either type 2 species or rate - set 2 in rate shift model, set K=Inf for diversity independence.} - \item{\code{pars[9]}: gamma (immigration rate) for either type 2 species - or rate set 2 in rate shift model} - \item{\code{pars[10]}: lambda^a (anagenesis rate) for either type 2 - species or rate set 2 in rate shift model} -} -Elements 6:10 are required only when type 2 species are included -or in the rate shift model. For \code{\link{DAISIE_sim_relaxed_rate}()} -\code{pars[6]} is the standard deviation of the gamma distribution for the -relaxed parameter and the parameter chosen by the \code{relaxed_par} -argument is the mean of the gamma distribution for the relaxed parameter.} - -\item{total_time}{Numeric defining the length of the simulation in time -units.} - -\item{area_pars}{A named list containing area and sea level parameters as -created by \code{\link{create_area_pars}()}: -\itemize{ - \item{[1]: maximum area} - \item{[2]: current area} - \item{[3]: value from 0 to 1 indicating where in the island's history the - peak area is achieved} - \item{[4]: total island age} - \item{[5]: amplitude of area fluctuation from sea level} - \item{[6]: frequency of sine wave of area change from sea level} - \item{[7]: angle of the slope of the island} -}} - -\item{hyper_pars}{A named list of numeric hyperparameters for the rate -calculations as returned by \code{\link{create_hyper_pars}()}: -\itemize{ - \item{[1]: is d the scaling parameter for exponent for calculating - cladogenesis rate} - \item{[2]: is x the exponent for calculating extinction rate} -}} - -\item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, -\code{\link{DAISIE_ML_CS}} and plotting a string describing the type of -island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a -numeric describing the type of island ontogeny. Can be \code{0} for -constant, \code{1} for a beta function describing area through time. In ML -functions \code{island_ontogeny = NA} assumes constant ontogeny. Time -dependent estimation is not yet available as development is still ongoing. -Will return an error if called in that case.} - -\item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a -string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. -\cr In all other functions a numeric describing the type of sea level. Can -be \code{0} for constant, \code{1} for a sine function describing area -through time.} - -\item{extcutoff}{A numeric with the cutoff for the the maximum extinction -rate preventing it from being too large and slowing down simulation.} - -\item{mainland_n}{A numeric stating the number of mainland species, that -is the number of species that can potentially colonize the island. -If using a clade-specific diversity dependence, this value is set to 1. -If using an island-wide diversity dependence, this value is set to the -number of mainland species.} - -\item{resol}{numeric for resolution of summary stats calculation. Should be -> 1.} -} -\value{ -A named list with mean and median values of specified parameters -} -\description{ -Calculates the summary statistics of per capita rates throught an ontogeny -simulation -} -\examples{ -pars <- c(0.01, 1, 20, 0.01, 1) -area_pars <- create_area_pars( - max_area = 13500, - current_area = 3500, - proportional_peak_t = 0.1, - total_island_age = 15, - sea_level_amplitude = 0, - sea_level_frequency = 0, - island_gradient_angle = 0 -) -hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) -island_ontogeny <- 1 -sea_level <- 0 -extcutoff <- 1100 -resol <- 100 -total_time <- 10 -mainland_n <- 1000 - -mean_med <- DAISIE:::DAISIE_calc_sumstats_pcrates( - pars = pars, - total_time = total_time, - area_pars = area_pars, - hyper_pars = hyper_pars, - island_ontogeny = island_ontogeny, - sea_level = sea_level, - extcutoff = extcutoff, - mainland_n = mainland_n, - resol = resol -) -} -\author{ -Pedro Neves -} -\keyword{internal} diff --git a/man/DAISIE_convert_to_classic_plot.Rd b/man/DAISIE_convert_to_classic_plot.Rd deleted file mode 100644 index 01a2872d..00000000 --- a/man/DAISIE_convert_to_classic_plot.Rd +++ /dev/null @@ -1,44 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_plot_stt.R -\name{DAISIE_convert_to_classic_plot} -\alias{DAISIE_convert_to_classic_plot} -\title{Prepare input for DAISIE_stt} -\usage{ -DAISIE_convert_to_classic_plot(simulation_outputs, trait_pars = NULL) -} -\arguments{ -\item{simulation_outputs}{A list with matrices and vectors of simulation -produced by DAISIE_sim functions.} - -\item{trait_pars}{A named list containing diversification rates considering - two trait states created by \code{\link{create_trait_pars}}: -\itemize{ - \item{[1]:A numeric with the per capita transition rate with state1} - \item{[2]:A numeric with the per capita immigration rate with state2} - \item{[3]:A numeric with the per capita extinction rate with state2} - \item{[4]:A numeric with the per capita anagenesis rate with state2} - \item{[5]:A numeric with the per capita cladogenesis rate with state2} - \item{[6]:A numeric with the per capita transition rate with state2} - \item{[7]:A numeric with the number of species with trait state 2 on - mainland} -}} -} -\value{ -a list with wrangled data to be used for plotting STT plots with -DAISIE_plot_stt -} -\description{ -Prepare input for DAISIE_stt -} -\examples{ -utils::data("islands_1type_1000reps", package = "DAISIE") -simulation_outuputs <- DAISIE:::DAISIE_convert_to_classic_plot( -islands_1type_1000reps -) - - -} -\seealso{ -\code{\link{DAISIE_plot_stt}}, \code{\link{DAISIE_plot_sims}} -} -\keyword{internal} diff --git a/man/DAISIE_format_CS.Rd b/man/DAISIE_format_CS.Rd index 84773fb1..e5101da8 100644 --- a/man/DAISIE_format_CS.Rd +++ b/man/DAISIE_format_CS.Rd @@ -37,12 +37,15 @@ species that can potentially colonize the island.} divided by for plotting purposes. Larger values will lead to plots with higher resolution, but will also run slower.} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} \item{trait_pars}{A named list containing diversification rates considering two trait states created by \code{\link{create_trait_pars}}: diff --git a/man/DAISIE_format_CS_full_stt.Rd b/man/DAISIE_format_CS_full_stt.Rd index 811b3e56..28b99beb 100644 --- a/man/DAISIE_format_CS_full_stt.Rd +++ b/man/DAISIE_format_CS_full_stt.Rd @@ -32,12 +32,15 @@ will stop the simulation at the mid-life of the island.} \item{M}{Numeric defining the size of mainland pool, i.e. the number of species that can potentially colonize the island.} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} \item{trait_pars}{A named list containing diversification rates considering two trait states created by \code{\link{create_trait_pars}}: diff --git a/man/DAISIE_format_CS_sampled_stt.Rd b/man/DAISIE_format_CS_sampled_stt.Rd index 2d6e2f28..844c2b9a 100644 --- a/man/DAISIE_format_CS_sampled_stt.Rd +++ b/man/DAISIE_format_CS_sampled_stt.Rd @@ -37,12 +37,15 @@ species that can potentially colonize the island.} divided by for plotting purposes. Larger values will lead to plots with higher resolution, but will also run slower.} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} \item{trait_pars}{A named list containing diversification rates considering two trait states created by \code{\link{create_trait_pars}}: diff --git a/man/DAISIE_format_GW.Rd b/man/DAISIE_format_GW.Rd index 8c4b8e38..6da3ee03 100644 --- a/man/DAISIE_format_GW.Rd +++ b/man/DAISIE_format_GW.Rd @@ -41,12 +41,15 @@ higher resolution, but will also run slower.} mainland species is divided by the number of guilds when \code{divdepmodel = "GW"}} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} } \value{ List with GW DAISIE simulation output diff --git a/man/DAISIE_format_IW.Rd b/man/DAISIE_format_IW.Rd deleted file mode 100644 index 75b1972b..00000000 --- a/man/DAISIE_format_IW.Rd +++ /dev/null @@ -1,99 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_format_IW.R -\name{DAISIE_format_IW} -\alias{DAISIE_format_IW} -\title{Formats island-wide simulation output into -standard DAISIE list output} -\usage{ -DAISIE_format_IW( - island_replicates, - time, - M, - sample_freq = 25, - verbose = TRUE, - trait_pars = NULL -) -} -\arguments{ -\item{island_replicates}{List output from -\code{\link{DAISIE_sim_core_cr}()}, -\code{\link{DAISIE_sim_core_time_dep}()}, -\code{\link{DAISIE_sim_core_cr_shift}()} or -\code{\link{DAISIE_sim_min_type2}()} functions. Minimally, this must be a -list that has as many elements as replicates. Each element must be a list -with the elements \code{island_age}, \code{not_present} and \code{stt_all}. -\code{stt_all} must be a data frame with the column names \code{Time}, -\code{nI}, \code{nA}, \code{nC} and \code{present}.} - -\item{time}{Numeric defining the length of the simulation in time units. -For example, if an island is known to be 4 million years old, setting -time = 4 will simulate the entire life span of the island; setting time = 2 -will stop the simulation at the mid-life of the island.} - -\item{M}{Numeric defining the size of mainland pool, i.e. the number of -species that can potentially colonize the island.} - -\item{sample_freq}{Numeric specifing the number of units times should be -divided by for plotting purposes. Larger values will lead to plots with -higher resolution, but will also run slower.} - -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. -For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} - -\item{trait_pars}{A named list containing diversification rates considering - two trait states created by \code{\link{create_trait_pars}}: -\itemize{ - \item{[1]:A numeric with the per capita transition rate with state1} - \item{[2]:A numeric with the per capita immigration rate with state2} - \item{[3]:A numeric with the per capita extinction rate with state2} - \item{[4]:A numeric with the per capita anagenesis rate with state2} - \item{[5]:A numeric with the per capita cladogenesis rate with state2} - \item{[6]:A numeric with the per capita transition rate with state2} - \item{[7]:A numeric with the number of species with trait state 2 on - mainland} -}} -} -\value{ -List with CS DAISIE simulation output -} -\description{ -Formats island-wide simulation output into -standard DAISIE list output -} -\examples{ -island_replicates <- list() -island_replicates[[1]] <- DAISIE:::DAISIE_sim_core_cr( - time = 5, - mainland_n = 1000, - pars = c(2, 2, 40, 0.1, 1), - area_pars = DAISIE::create_area_pars( - max_area = 1, - current_area = 1, - proportional_peak_t = 0, - total_island_age = 0, - sea_level_amplitude = 0, - sea_level_frequency = 0, - island_gradient_angle = 0), - hyper_pars = create_hyper_pars(d = 0.2, x = 0.1), - nonoceanic_pars = c(0, 0) -) -formatted_island_sampled <- DAISIE:::DAISIE_format_IW( - island_replicates = island_replicates, - time = 5, - M = 1000, - sample_freq = 25, - verbose = FALSE -) -formatted_island_full <- DAISIE:::DAISIE_format_IW( - island_replicates = island_replicates, - time = 5, - M = 1000, - sample_freq = Inf, - verbose = FALSE -) -} -\keyword{internal} diff --git a/man/DAISIE_format_IW_full_stt.Rd b/man/DAISIE_format_IW_full_stt.Rd index 88f07bb4..280ef37f 100644 --- a/man/DAISIE_format_IW_full_stt.Rd +++ b/man/DAISIE_format_IW_full_stt.Rd @@ -24,12 +24,15 @@ units.} \item{M}{Numeric defining the size of mainland pool, i.e. the number of species that can potentially colonize the island.} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} } \value{ List with IW DAISIE simulation output diff --git a/man/DAISIE_format_IW_sampled_stt.Rd b/man/DAISIE_format_IW_sampled_stt.Rd index 91e0cfe9..602cbbad 100644 --- a/man/DAISIE_format_IW_sampled_stt.Rd +++ b/man/DAISIE_format_IW_sampled_stt.Rd @@ -34,12 +34,15 @@ species that can potentially colonize the island.} divided by for plotting purposes. Larger values will lead to plots with higher resolution, but will also run slower.} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} } \value{ List with IW DAISIE simulation output diff --git a/man/DAISIE_loglik_integrand.Rd b/man/DAISIE_loglik_integrand.Rd index aec1eaee..f85af8e1 100644 --- a/man/DAISIE_loglik_integrand.Rd +++ b/man/DAISIE_loglik_integrand.Rd @@ -61,12 +61,15 @@ and \code{"ode45"} from \code{\link[deSolve]{ode}()} for \item{reltolint}{Numeric relative tolerance of the integration} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} \item{pick}{Numeric determining which parameter is selected for the relaxed-rate model} diff --git a/man/DAISIE_loglik_integrate.Rd b/man/DAISIE_loglik_integrate.Rd index 80ba5b8f..e5b7a6c8 100644 --- a/man/DAISIE_loglik_integrate.Rd +++ b/man/DAISIE_loglik_integrate.Rd @@ -66,12 +66,15 @@ and \code{"ode45"} from \code{\link[deSolve]{ode}()} for \item{reltolint}{Numeric relative tolerance of the integration} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} } \value{ A loglikelihood value diff --git a/man/DAISIE_nonoceanic_spec.Rd b/man/DAISIE_nonoceanic_spec.Rd deleted file mode 100644 index 57d9a1d4..00000000 --- a/man/DAISIE_nonoceanic_spec.Rd +++ /dev/null @@ -1,32 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_utils.R -\name{DAISIE_nonoceanic_spec} -\alias{DAISIE_nonoceanic_spec} -\title{Calculates the species on the island initially when \code{nonoceanic_pars[1] -!= 0}} -\usage{ -DAISIE_nonoceanic_spec(prob_samp, prob_nonend, mainland_n) -} -\arguments{ -\item{prob_samp}{probability of a species being sampled -from the mainland pool} - -\item{prob_nonend}{probability of a species sampled being non-endemic} - -\item{mainland_n}{number of species in the mainland pool} -} -\value{ -A list of non-endemic species, endemic species and the new -mainland species pool -} -\description{ -Calculates the species on the island initially when \code{nonoceanic_pars[1] -!= 0} -} -\examples{ -DAISIE:::DAISIE_nonoceanic_spec( -prob_samp = 0.1, -prob_nonend = 0.9, -mainland_n = 1000) -} -\keyword{internal} diff --git a/man/DAISIE_plot_area.Rd b/man/DAISIE_plot_area.Rd index f0330d36..94b48ce8 100644 --- a/man/DAISIE_plot_area.Rd +++ b/man/DAISIE_plot_area.Rd @@ -38,8 +38,7 @@ present and the \code{area_pars}.} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -50,8 +49,7 @@ Will return an error if called in that case.} \item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. +\code{"sine"} for a sine function describing area through time. \cr In all other functions a numeric describing the type of sea level. Can be \code{0} for constant, \code{1} for a sine function describing area through time.} diff --git a/man/DAISIE_plot_cladogenesis.Rd b/man/DAISIE_plot_cladogenesis.Rd index 79f95847..3a8481f2 100644 --- a/man/DAISIE_plot_cladogenesis.Rd +++ b/man/DAISIE_plot_cladogenesis.Rd @@ -46,8 +46,7 @@ present and the \code{area_pars}.} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -56,8 +55,7 @@ Will return an error if called in that case.} \item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. +\code{"sine"} for a sine function describing area through time. \cr In all other functions a numeric describing the type of sea level. Can be \code{0} for constant, \code{1} for a sine function describing area through time.} diff --git a/man/DAISIE_plot_comparison_stts.Rd b/man/DAISIE_plot_comparison_stts.Rd deleted file mode 100644 index 3d108871..00000000 --- a/man/DAISIE_plot_comparison_stts.Rd +++ /dev/null @@ -1,51 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_plot_comparison_stts.R -\name{DAISIE_plot_comparison_stts} -\alias{DAISIE_plot_comparison_stts} -\title{Plot STT and overlay additional STT curves.} -\usage{ -DAISIE_plot_comparison_stts( - time, - plot_lists_simulations, - plot_lists_simulations_MLE, - type, - kind_of_plot = "line" -) -} -\arguments{ -\item{time}{Numeric defining the length of the simulation in time units. -For example, if an island is known to be 4 million years old, setting -time = 4 will simulate the entire life span of the island; setting time = 2 -will stop the simulation at the mid-life of the island.} - -\item{plot_lists_simulations}{List with simulation output after parsing by -\code{DAISIE_prepare_data_plotting}.} - -\item{plot_lists_simulations_MLE}{List with simulation output after parsing -by \code{DAISIE_prepare_data_plotting}, but obtained by simulating MLE -output.} - -\item{type}{String to indicate if stt of all species or all possible stt -should be plotted. Default is \code{"all_species"}, \code{"type1_species"} -or \code{"type2_species"} should be plotted.} - -\item{kind_of_plot}{Character vector stating how STT plot resulting from MLE -based simulations should be plotted. Default is \code{"line"} for multiple -individual lines. Can also be \code{"shade"} for the 5\% quantile.} -} -\value{ -Standard \code{\link{DAISIE_plot_stt}} with overlaid additional - STT curves for comparison. -} -\description{ -Plot STT and overlay additional STT curves. -} -\seealso{ -\code{\link{DAISIE_plot_sims}}, \code{\link{DAISIE_plot_stt}}, - \code{\link{DAISIE_convert_to_classic_plot}} -} -\author{ -Pedro Neves -} -\concept{plotting} -\keyword{internal} diff --git a/man/DAISIE_plot_extinction.Rd b/man/DAISIE_plot_extinction.Rd index 9562e0dd..837f1d30 100644 --- a/man/DAISIE_plot_extinction.Rd +++ b/man/DAISIE_plot_extinction.Rd @@ -52,8 +52,7 @@ calculations as returned by \code{\link{create_hyper_pars}()}: \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -62,8 +61,7 @@ Will return an error if called in that case.} \item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. +\code{"sine"} for a sine function describing area through time. \cr In all other functions a numeric describing the type of sea level. Can be \code{0} for constant, \code{1} for a sine function describing area through time.} diff --git a/man/DAISIE_plot_immigration.Rd b/man/DAISIE_plot_immigration.Rd index f74e4a57..dc1a5b79 100644 --- a/man/DAISIE_plot_immigration.Rd +++ b/man/DAISIE_plot_immigration.Rd @@ -61,8 +61,7 @@ calculations as returned by \code{\link{create_hyper_pars}()}: \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -71,8 +70,7 @@ Will return an error if called in that case.} \item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. +\code{"sine"} for a sine function describing area through time. \cr In all other functions a numeric describing the type of sea level. Can be \code{0} for constant, \code{1} for a sine function describing area through time.} diff --git a/man/DAISIE_plot_pc_rates.Rd b/man/DAISIE_plot_pc_rates.Rd index d7758da5..d793f82c 100644 --- a/man/DAISIE_plot_pc_rates.Rd +++ b/man/DAISIE_plot_pc_rates.Rd @@ -49,8 +49,7 @@ argument is the mean of the gamma distribution for the relaxed parameter.} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -59,8 +58,7 @@ Will return an error if called in that case.} \item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. +\code{"sine"} for a sine function describing area through time. \cr In all other functions a numeric describing the type of sea level. Can be \code{0} for constant, \code{1} for a sine function describing area through time.} diff --git a/man/DAISIE_sim.Rd b/man/DAISIE_sim.Rd index f46a0e23..f058e824 100644 --- a/man/DAISIE_sim.Rd +++ b/man/DAISIE_sim.Rd @@ -138,12 +138,15 @@ conditioning on island age and non-extinction of the island biota \cr. cond > 1 : conditioning on island age and having at least cond colonizations on the island. This last option is not yet available for the IW model \cr} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} \item{...}{Any arguments to pass on to plotting functions.} } diff --git a/man/DAISIE_sim_core_time_dep.Rd b/man/DAISIE_sim_core_time_dep.Rd index f2ba6171..40f1f75a 100644 --- a/man/DAISIE_sim_core_time_dep.Rd +++ b/man/DAISIE_sim_core_time_dep.Rd @@ -66,8 +66,7 @@ argument is the mean of the gamma distribution for the relaxed parameter.} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -76,8 +75,7 @@ Will return an error if called in that case.} \item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. +\code{"sine"} for a sine function describing area through time. \cr In all other functions a numeric describing the type of sea level. Can be \code{0} for constant, \code{1} for a sine function describing area through time.} diff --git a/man/DAISIE_sim_core_trait_dep.Rd b/man/DAISIE_sim_core_trait_dep.Rd index 36faea6f..5c665b20 100644 --- a/man/DAISIE_sim_core_trait_dep.Rd +++ b/man/DAISIE_sim_core_trait_dep.Rd @@ -56,8 +56,7 @@ argument is the mean of the gamma distribution for the relaxed parameter.} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -66,8 +65,7 @@ Will return an error if called in that case.} \item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. +\code{"sine"} for a sine function describing area through time. \cr In all other functions a numeric describing the type of sea level. Can be \code{0} for constant, \code{1} for a sine function describing area through time.} diff --git a/man/DAISIE_sim_cr_cs.Rd b/man/DAISIE_sim_cr_cs.Rd index c65e1af2..4befd59b 100644 --- a/man/DAISIE_sim_cr_cs.Rd +++ b/man/DAISIE_sim_cr_cs.Rd @@ -111,12 +111,15 @@ conditioning on island age and non-extinction of the island biota \cr. cond > 1 : conditioning on island age and having at least cond colonizations on the island. This last option is not yet available for the IW model \cr} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} } \value{ A list. The highest level of the least corresponds to each individual diff --git a/man/DAISIE_sim_cr_gw.Rd b/man/DAISIE_sim_cr_gw.Rd index 93c267f6..f23853c9 100644 --- a/man/DAISIE_sim_cr_gw.Rd +++ b/man/DAISIE_sim_cr_gw.Rd @@ -89,12 +89,15 @@ created by \code{\link{create_area_pars}()}: \item{[7]: angle of the slope of the island} }} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} } \value{ A list. The highest level of the least corresponds to each individual diff --git a/man/DAISIE_sim_cr_iw.Rd b/man/DAISIE_sim_cr_iw.Rd index 09a8e647..456184c9 100644 --- a/man/DAISIE_sim_cr_iw.Rd +++ b/man/DAISIE_sim_cr_iw.Rd @@ -90,12 +90,15 @@ conditioning on island age and non-extinction of the island biota \cr. cond > 1 : conditioning on island age and having at least cond colonizations on the island. This last option is not yet available for the IW model \cr} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} } \value{ A list. The highest level of the least corresponds to each individual diff --git a/man/DAISIE_sim_cr_shift.Rd b/man/DAISIE_sim_cr_shift.Rd index 2b4a9893..8a45c848 100644 --- a/man/DAISIE_sim_cr_shift.Rd +++ b/man/DAISIE_sim_cr_shift.Rd @@ -120,12 +120,15 @@ conditioning on island age and non-extinction of the island biota \cr. cond > 1 : conditioning on island age and having at least cond colonizations on the island. This last option is not yet available for the IW model \cr} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} \item{...}{Any arguments to pass on to plotting functions.} } diff --git a/man/DAISIE_sim_min_type2.Rd b/man/DAISIE_sim_min_type2.Rd index c5be7d4f..12e98058 100644 --- a/man/DAISIE_sim_min_type2.Rd +++ b/man/DAISIE_sim_min_type2.Rd @@ -81,12 +81,15 @@ calculations as returned by \code{\link{create_hyper_pars}()}: \item{[2]: is x the exponent for calculating extinction rate} }} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} } \description{ Internal function of the DAISIE simulation diff --git a/man/DAISIE_sim_relaxed_rate.Rd b/man/DAISIE_sim_relaxed_rate.Rd index fc62a68b..685f9175 100644 --- a/man/DAISIE_sim_relaxed_rate.Rd +++ b/man/DAISIE_sim_relaxed_rate.Rd @@ -106,12 +106,15 @@ conditioning on island age and non-extinction of the island biota \cr. cond > 1 : conditioning on island age and having at least cond colonizations on the island. This last option is not yet available for the IW model \cr} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} \item{...}{Any arguments to pass on to plotting functions.} } diff --git a/man/DAISIE_sim_time_dep.Rd b/man/DAISIE_sim_time_dep.Rd index 00f29ee9..20e2c258 100644 --- a/man/DAISIE_sim_time_dep.Rd +++ b/man/DAISIE_sim_time_dep.Rd @@ -115,8 +115,7 @@ type 2.} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -125,8 +124,7 @@ Will return an error if called in that case.} \item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. +\code{"sine"} for a sine function describing area through time. \cr In all other functions a numeric describing the type of sea level. Can be \code{0} for constant, \code{1} for a sine function describing area through time.} @@ -139,12 +137,15 @@ conditioning on island age and non-extinction of the island biota \cr. cond > 1 : conditioning on island age and having at least cond colonizations on the island. This last option is not yet available for the IW model \cr} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} \item{...}{Any arguments to pass on to plotting functions.} } diff --git a/man/DAISIE_sim_time_dep_cs.Rd b/man/DAISIE_sim_time_dep_cs.Rd index 66b8180c..101556c9 100644 --- a/man/DAISIE_sim_time_dep_cs.Rd +++ b/man/DAISIE_sim_time_dep_cs.Rd @@ -94,8 +94,7 @@ higher resolution, but will also run slower.} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -104,8 +103,7 @@ Will return an error if called in that case.} \item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. +\code{"sine"} for a sine function describing area through time. \cr In all other functions a numeric describing the type of sea level. Can be \code{0} for constant, \code{1} for a sine function describing area through time.} @@ -127,12 +125,15 @@ conditioning on island age and non-extinction of the island biota \cr. cond > 1 : conditioning on island age and having at least cond colonizations on the island. This last option is not yet available for the IW model \cr} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} } \value{ A list. The highest level of the least corresponds to each individual diff --git a/man/DAISIE_sim_time_dep_gw.Rd b/man/DAISIE_sim_time_dep_gw.Rd index 9afbf070..56f83128 100644 --- a/man/DAISIE_sim_time_dep_gw.Rd +++ b/man/DAISIE_sim_time_dep_gw.Rd @@ -98,8 +98,7 @@ higher resolution, but will also run slower.} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -108,8 +107,7 @@ Will return an error if called in that case.} \item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. +\code{"sine"} for a sine function describing area through time. \cr In all other functions a numeric describing the type of sea level. Can be \code{0} for constant, \code{1} for a sine function describing area through time.} @@ -126,12 +124,15 @@ present and the \code{area_pars}.} \item{extcutoff}{A numeric with the cutoff for the the maximum extinction rate preventing it from being too large and slowing down simulation.} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} } \value{ A list. The highest level of the least corresponds to each individual diff --git a/man/DAISIE_sim_time_dep_iw.Rd b/man/DAISIE_sim_time_dep_iw.Rd index 602576e8..a5ee8e7a 100644 --- a/man/DAISIE_sim_time_dep_iw.Rd +++ b/man/DAISIE_sim_time_dep_iw.Rd @@ -94,8 +94,7 @@ higher resolution, but will also run slower.} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -104,8 +103,7 @@ Will return an error if called in that case.} \item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. +\code{"sine"} for a sine function describing area through time. \cr In all other functions a numeric describing the type of sea level. Can be \code{0} for constant, \code{1} for a sine function describing area through time.} @@ -127,12 +125,15 @@ conditioning on island age and non-extinction of the island biota \cr. cond > 1 : conditioning on island age and having at least cond colonizations on the island. This last option is not yet available for the IW model \cr} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} } \value{ A list. The highest level of the least corresponds to each individual diff --git a/man/DAISIE_sim_trait_dep.Rd b/man/DAISIE_sim_trait_dep.Rd index 6e082fe5..1a3cb8e7 100644 --- a/man/DAISIE_sim_trait_dep.Rd +++ b/man/DAISIE_sim_trait_dep.Rd @@ -83,8 +83,7 @@ type 2.} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -93,8 +92,7 @@ Will return an error if called in that case.} \item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. +\code{"sine"} for a sine function describing area through time. \cr In all other functions a numeric describing the type of sea level. Can be \code{0} for constant, \code{1} for a sine function describing area through time.} @@ -128,12 +126,15 @@ conditioning on island age and non-extinction of the island biota \cr. cond > 1 : conditioning on island age and having at least cond colonizations on the island. This last option is not yet available for the IW model \cr} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} \item{trait_pars}{A named list containing diversification rates considering two trait states created by \code{\link{create_trait_pars}}: diff --git a/man/DAISIE_sim_trait_dep_2K.Rd b/man/DAISIE_sim_trait_dep_2K.Rd index 414661a5..c2d86e39 100644 --- a/man/DAISIE_sim_trait_dep_2K.Rd +++ b/man/DAISIE_sim_trait_dep_2K.Rd @@ -83,8 +83,7 @@ type 2.} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -93,8 +92,7 @@ Will return an error if called in that case.} \item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. +\code{"sine"} for a sine function describing area through time. \cr In all other functions a numeric describing the type of sea level. Can be \code{0} for constant, \code{1} for a sine function describing area through time.} @@ -128,12 +126,15 @@ conditioning on island age and non-extinction of the island biota \cr. cond > 1 : conditioning on island age and having at least cond colonizations on the island. This last option is not yet available for the IW model \cr} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} \item{trait_pars}{A named list containing diversification rates considering two trait states created by \code{\link{create_trait_pars}}: diff --git a/man/are_area_pars.Rd b/man/are_area_pars.Rd deleted file mode 100644 index db25ed7f..00000000 --- a/man/are_area_pars.Rd +++ /dev/null @@ -1,44 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_check_format.R -\name{are_area_pars} -\alias{are_area_pars} -\title{Test if list has area parameters} -\usage{ -are_area_pars(area_pars) -} -\arguments{ -\item{area_pars}{A named list containing area and sea level parameters as -created by \code{\link{create_area_pars}()}: -\itemize{ - \item{[1]: maximum area} - \item{[2]: current area} - \item{[3]: value from 0 to 1 indicating where in the island's history the - peak area is achieved} - \item{[4]: total island age} - \item{[5]: amplitude of area fluctuation from sea level} - \item{[6]: frequency of sine wave of area change from sea level} - \item{[7]: angle of the slope of the island} -}} -} -\value{ -Boolean that indicates if list conforms to expected area parameters -as created by \link{create_area_pars} -} -\description{ -Test if list has area parameters -} -\examples{ -testit::assert(DAISIE:::are_area_pars( - create_area_pars( - max_area = 10, - current_area = 4, - proportional_peak_t = 0.5, - total_island_age = 5, - sea_level_amplitude = 5, - sea_level_frequency = 10, - island_gradient_angle = 0))) -} -\author{ -Richel J.C Bilderbeek, Joshua Lambert, Pedro Neves -} -\keyword{internal} diff --git a/man/are_hyper_pars.Rd b/man/are_hyper_pars.Rd deleted file mode 100644 index 3fa55fe2..00000000 --- a/man/are_hyper_pars.Rd +++ /dev/null @@ -1,32 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_check_format.R -\name{are_hyper_pars} -\alias{are_hyper_pars} -\title{Test if a list has hyperparameters} -\usage{ -are_hyper_pars(hyper_pars) -} -\arguments{ -\item{hyper_pars}{A named list of numeric hyperparameters for the rate -calculations as returned by \code{\link{create_hyper_pars}()}: -\itemize{ - \item{[1]: is d the scaling parameter for exponent for calculating - cladogenesis rate} - \item{[2]: is x the exponent for calculating extinction rate} -}} -} -\value{ -\code{TRUE} if list contains hyperparameters, \code{FALSE} otherwise. -} -\description{ -Test if a list has hyperparameters -} -\examples{ -testit::assert( - DAISIE:::are_hyper_pars(create_hyper_pars(d = 0.027, x = 0.15)) -) -} -\author{ -Pedro Neves, Joshua Lambert -} -\keyword{internal} diff --git a/man/are_max_rates.Rd b/man/are_max_rates.Rd deleted file mode 100644 index 7d16471f..00000000 --- a/man/are_max_rates.Rd +++ /dev/null @@ -1,20 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_check_format.R -\name{are_max_rates} -\alias{are_max_rates} -\title{Determines if object max_rates are max_rates} -\usage{ -are_max_rates(max_rates) -} -\arguments{ -\item{max_rates}{named list of numeric max rates as returned by -\code{\link{update_max_rates}()}.} -} -\value{ -\code{TRUE} if object max_rates is a list of rates, -\code{FALSE} otherwise. -} -\description{ -Determines if object max_rates are max_rates -} -\keyword{internal} diff --git a/man/are_max_rates_gt_rates.Rd b/man/are_max_rates_gt_rates.Rd deleted file mode 100644 index 8565c9e1..00000000 --- a/man/are_max_rates_gt_rates.Rd +++ /dev/null @@ -1,49 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_check_format.R -\name{are_max_rates_gt_rates} -\alias{are_max_rates_gt_rates} -\title{Check if maximum rates are greater or equal to rates} -\usage{ -are_max_rates_gt_rates(rates, max_rates) -} -\arguments{ -\item{rates}{named list of numeric rates as returned by -\code{\link{update_rates}()}.} - -\item{max_rates}{named list of numeric max rates as returned by -\code{\link{update_max_rates}()}.} -} -\value{ -\code{TRUE} if maximum rates are greater or equal than rates, -\code{FALSE} otherwise. -} -\description{ -Check if maximum rates are greater or equal to rates -} -\examples{ -rates <- list( - ext_rate = 0.1, - immig_rate = 0.1, - ana_rate = 0.1, - clado_rate = 0.1 -) -max_rates <- list( - ext_max_rate = 1, - immig_max_rate = 1, - ana_max_rate = 1, - clado_max_rate = 1 -) -testthat::expect_true( - DAISIE:::are_max_rates_gt_rates( - rates = rates, - max_rates = max_rates - ) -) -} -\seealso{ -\code{\link{are_rates}}, \code{\link{are_max_rates}} -} -\author{ -Joshua Lambert, Pedro Neves -} -\keyword{internal} diff --git a/man/are_trait_pars.Rd b/man/are_trait_pars.Rd deleted file mode 100644 index e4b47591..00000000 --- a/man/are_trait_pars.Rd +++ /dev/null @@ -1,41 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_check_format.R -\name{are_trait_pars} -\alias{are_trait_pars} -\title{Test if list has trait state parameters} -\usage{ -are_trait_pars(trait_pars) -} -\arguments{ -\item{trait_pars}{A named list containing diversification rates considering - two trait states created by \code{\link{create_trait_pars}}: -\itemize{ - \item{[1]:A numeric with the per capita transition rate with state1} - \item{[2]:A numeric with the per capita immigration rate with state2} - \item{[3]:A numeric with the per capita extinction rate with state2} - \item{[4]:A numeric with the per capita anagenesis rate with state2} - \item{[5]:A numeric with the per capita cladogenesis rate with state2} - \item{[6]:A numeric with the per capita transition rate with state2} - \item{[7]:A numeric with the number of species with trait state 2 on - mainland} -}} -} -\value{ -Boolean that indicates if list conforms to expected area parameters -as created by \link{create_trait_pars} -} -\description{ -Test if list has trait state parameters -} -\examples{ -testit::assert(DAISIE:::are_trait_pars( - create_trait_pars( - trans_rate = 0.5, - immig_rate2 = 0.1, - ext_rate2 = 0.2, - ana_rate2 = 0.3, - clado_rate2 = 0.4, - trans_rate2 = 0.5, - M2 = 1000)) == TRUE) -} -\keyword{internal} diff --git a/man/create_area_pars.Rd b/man/create_area_pars.Rd index c0e623be..34002ab7 100644 --- a/man/create_area_pars.Rd +++ b/man/create_area_pars.Rd @@ -42,8 +42,7 @@ for island ontogeny simulation Create named list of area parameters } \examples{ -testit::assert(DAISIE:::are_area_pars( -create_area_pars( +area_pars <- create_area_pars( max_area = 10, current_area = 1, proportional_peak_t = 0.5, @@ -51,9 +50,9 @@ create_area_pars( sea_level_amplitude = 5, sea_level_frequency = 10, island_gradient_angle = 0 - ) - ) - ) + + +) } \author{ Richel J.C Bilderbeek, Joshua Lambert, Pedro Neves diff --git a/man/create_trait_pars.Rd b/man/create_trait_pars.Rd index c8cba6b5..e17d089b 100644 --- a/man/create_trait_pars.Rd +++ b/man/create_trait_pars.Rd @@ -36,13 +36,13 @@ list of numerical values containing trait state parameters Create named list of trait state parameters } \examples{ -testit::assert(DAISIE:::are_trait_pars( - create_trait_pars( - trans_rate = 0.5, - immig_rate2 = 0.1, - ext_rate2 = 0.2, - ana_rate2 = 0.3, - clado_rate2 = 0.4, - trans_rate2 = 0.5, - M2 = 1000)) == TRUE) +trait_pars <- create_trait_pars( + trans_rate = 0.5, + immig_rate2 = 0.1, + ext_rate2 = 0.2, + ana_rate2 = 0.3, + clado_rate2 = 0.4, + trans_rate2 = 0.5, + M2 = 1000 + ) } diff --git a/man/daisie_odeint_cs.Rd b/man/daisie_odeint_cs.Rd index 71435a9e..71af420a 100644 --- a/man/daisie_odeint_cs.Rd +++ b/man/daisie_odeint_cs.Rd @@ -2,7 +2,12 @@ % Please edit documentation in R/RcppExports.R \name{daisie_odeint_cs} \alias{daisie_odeint_cs} -\title{Driver for the boost::odeint solver} +\title{Driver for the boost::odeint solver for the CS model} +\value{ +Object of type `state_type`, which itself is +`vector_t`, with the result of the +integration depending on the runmod chosen. +} \description{ -Driver for the boost::odeint solver +Driver for the boost::odeint solver for the CS model } diff --git a/man/daisie_odeint_iw.Rd b/man/daisie_odeint_iw.Rd index 8a8af05b..87e6efaa 100644 --- a/man/daisie_odeint_iw.Rd +++ b/man/daisie_odeint_iw.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/RcppExports.R \name{daisie_odeint_iw} \alias{daisie_odeint_iw} -\title{Driver for the boost::odeint solver} +\title{Driver for the boost::odeint solver for the IW model} \description{ -Driver for the boost::odeint solver +Driver for the boost::odeint solver for the IW model } diff --git a/man/default_params_doc.Rd b/man/default_params_doc.Rd index 3c74d4a7..a352fc87 100644 --- a/man/default_params_doc.Rd +++ b/man/default_params_doc.Rd @@ -219,12 +219,15 @@ of species is present, STT is plotted for all species. If two types are present, three plots are produced: STT for all, STT for type 1 and STT for type 2.} -\item{verbose}{In simulation and dataprep functions a logical, -\code{Default = TRUE} gives intermediate output should be printed. +\item{verbose}{A numeric vector of length 1, which in simulations and +`DAISIEdataprep()` can be `1` or `0`, where `1` gives intermediate output +should be printed. For ML functions a numeric determining if intermediate output should be -printed, \code{Default = 0} does not print, \code{verbose = 1} prints -intermediate output of the parameters and loglikelihood, \code{verbose = 2} -means also intermediate progress during loglikelihood computation is shown.} +printed. The default: `0` does not print, `1` prints the initial +likelihood and the settings that were selected (which parameters are +to be optimised, fixed or shifted), `2` prints the same as `1 and also the +intermediate output of the parameters and loglikelihood, while `3` the +same as `2` and prints intermediate progress during likelihood computation.} \item{area_pars}{A named list containing area and sea level parameters as created by \code{\link{create_area_pars}()}: @@ -250,8 +253,7 @@ calculations as returned by \code{\link{create_hyper_pars}()}: \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -260,8 +262,7 @@ Will return an error if called in that case.} \item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. +\code{"sine"} for a sine function describing area through time. \cr In all other functions a numeric describing the type of sea level. Can be \code{0} for constant, \code{1} for a sine function describing area through time.} diff --git a/man/get_clado_rate_per_capita.Rd b/man/get_clado_rate_per_capita.Rd deleted file mode 100644 index 66c08deb..00000000 --- a/man/get_clado_rate_per_capita.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_rates.R -\name{get_clado_rate_per_capita} -\alias{get_clado_rate_per_capita} -\title{Calculate per-capita cladogenesis rate} -\usage{ -get_clado_rate_per_capita(lac, d, num_spec, K, A = 1) -} -\arguments{ -\item{lac}{A numeric with the per capita cladogenesis rate.} - -\item{d}{Numeric defining the scaling parameter for exponent for -calculating cladogenesis rate.} - -\item{num_spec}{A numeric with the current number of species.} - -\item{K}{A numeric with carrying capacity.} - -\item{A}{A numeric value for island area at a given point in time.} -} -\value{ -Numeric with the per-capita cladogenesis rate given a base -cladogenesis rate, K, A and the d hyperparameter. -} -\description{ -This function is only called directly inside the RHS of the ontogeny -likelihood functions. In all other cases \code{\link{get_clado_rate}()} is to -be called instead. -} -\examples{ -lac <- 0.4 -d <- 0 -num_spec <- 2 -K <- 10 -A <- 1 -clado_rate_pc <- DAISIE:::get_clado_rate_per_capita(lac, d, num_spec, K, A) -} -\keyword{internal} diff --git a/man/get_ext_rate_per_capita.Rd b/man/get_ext_rate_per_capita.Rd deleted file mode 100644 index 66018299..00000000 --- a/man/get_ext_rate_per_capita.Rd +++ /dev/null @@ -1,34 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_rates.R -\name{get_ext_rate_per_capita} -\alias{get_ext_rate_per_capita} -\title{Function to describe per-capita changes in extinction rate through time} -\usage{ -get_ext_rate_per_capita(mu, x, extcutoff = 1000, A = 1) -} -\arguments{ -\item{mu}{A numeric with the per capita extinction rate.} - -\item{x}{Numeric defining the exponent for calculating extinction rate.} - -\item{extcutoff}{A numeric with the cutoff for the the maximum extinction -rate preventing it from being too large and slowing down simulation.} - -\item{A}{A numeric value for island area at a given point in time.} -} -\value{ -Numeric with per capita extinction rate, given A(t), x, and mu0. -} -\description{ -This function is only called directly inside the RHS of the ontogeny -likelihood functions. In all other cases \code{\link{get_ext_rate}()} is to -be called instead. -} -\examples{ -ext_rate_per_capita <- DAISIE:::get_ext_rate_per_capita( - mu = 0.5, - x = 1, - A = 1000 -) -} -\keyword{internal} diff --git a/man/get_global_max_area.Rd b/man/get_global_max_area.Rd deleted file mode 100644 index 76685f40..00000000 --- a/man/get_global_max_area.Rd +++ /dev/null @@ -1,85 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_max_rates.R -\name{get_global_max_area} -\alias{get_global_max_area} -\title{Get the maximum area} -\usage{ -get_global_max_area(total_time, area_pars, peak, island_ontogeny, sea_level) -} -\arguments{ -\item{total_time}{Numeric defining the length of the simulation in time -units.} - -\item{area_pars}{A named list containing area and sea level parameters as -created by \code{\link{create_area_pars}()}: -\itemize{ - \item{[1]: maximum area} - \item{[2]: current area} - \item{[3]: value from 0 to 1 indicating where in the island's history the - peak area is achieved} - \item{[4]: total island age} - \item{[5]: amplitude of area fluctuation from sea level} - \item{[6]: frequency of sine wave of area change from sea level} - \item{[7]: angle of the slope of the island} -}} - -\item{peak}{A numeric value specifying the peakiness (or shaprness) of the -ontogeny curve. Higher values imply peakier ontogeny. This value is -internally calculated by \code{\link{calc_peak}()} given the area at the -present and the \code{area_pars}.} - -\item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, -\code{\link{DAISIE_ML_CS}} and plotting a string describing the type of -island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a -numeric describing the type of island ontogeny. Can be \code{0} for -constant, \code{1} for a beta function describing area through time. In ML -functions \code{island_ontogeny = NA} assumes constant ontogeny. Time -dependent estimation is not yet available as development is still ongoing. -Will return an error if called in that case.} - -\item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a -string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. -\cr In all other functions a numeric describing the type of sea level. Can -be \code{0} for constant, \code{1} for a sine function describing area -through time.} -} -\value{ -Numeric maximum area during the simulation. -} -\description{ -Get the maximum area -} -\examples{ -timeval <- 1 -total_time <- 10 -area_pars <- DAISIE::create_area_pars( - max_area = 5000, - current_area = 4000, - proportional_peak_t = 0.5, - total_island_age = 15, - sea_level_amplitude = 0, - sea_level_frequency = 0, - island_gradient_angle = 0 -) -island_ontogeny <- 1 -sea_level <- 0 -peak <- DAISIE:::calc_peak(total_time = total_time, area_pars = area_pars) -testthat::expect_silent( - global_max_area_time <- DAISIE:::get_global_max_area( - total_time = total_time, - peak = peak, - area_pars = area_pars, - island_ontogeny = island_ontogeny, - sea_level = sea_level - ) -) - -} -\author{ -Pedro Neves, Joshua Lambert, Shu Xie -} -\keyword{internal} diff --git a/man/get_global_min_area.Rd b/man/get_global_min_area.Rd deleted file mode 100644 index bfb80a7d..00000000 --- a/man/get_global_min_area.Rd +++ /dev/null @@ -1,86 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_max_rates.R -\name{get_global_min_area} -\alias{get_global_min_area} -\title{Get the minimum area} -\usage{ -get_global_min_area(total_time, area_pars, peak, island_ontogeny, sea_level) -} -\arguments{ -\item{total_time}{Numeric defining the length of the simulation in time -units.} - -\item{area_pars}{A named list containing area and sea level parameters as -created by \code{\link{create_area_pars}()}: -\itemize{ - \item{[1]: maximum area} - \item{[2]: current area} - \item{[3]: value from 0 to 1 indicating where in the island's history the - peak area is achieved} - \item{[4]: total island age} - \item{[5]: amplitude of area fluctuation from sea level} - \item{[6]: frequency of sine wave of area change from sea level} - \item{[7]: angle of the slope of the island} -}} - -\item{peak}{A numeric value specifying the peakiness (or shaprness) of the -ontogeny curve. Higher values imply peakier ontogeny. This value is -internally calculated by \code{\link{calc_peak}()} given the area at the -present and the \code{area_pars}.} - -\item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, -\code{\link{DAISIE_ML_CS}} and plotting a string describing the type of -island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a -numeric describing the type of island ontogeny. Can be \code{0} for -constant, \code{1} for a beta function describing area through time. In ML -functions \code{island_ontogeny = NA} assumes constant ontogeny. Time -dependent estimation is not yet available as development is still ongoing. -Will return an error if called in that case.} - -\item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a -string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. -\cr In all other functions a numeric describing the type of sea level. Can -be \code{0} for constant, \code{1} for a sine function describing area -through time.} -} -\value{ -Numeric with time at which area is minimum during the simulation -} -\description{ -Get the minimum area -} -\examples{ -timeval <- 1 -total_time <- 10 -area_pars <- DAISIE::create_area_pars( - max_area = 5000, - current_area = 4000, - proportional_peak_t = 0.5, - total_island_age = 15, - sea_level_amplitude = 0, - sea_level_frequency = 0, - island_gradient_angle = 0 -) -island_ontogeny <- 1 -sea_level <- 0 -peak <- DAISIE:::calc_peak(total_time = total_time, area_pars = area_pars) - -testthat::expect_silent( - DAISIE:::get_global_min_area( - total_time = total_time, - area_pars = area_pars, - peak = peak, - island_ontogeny = island_ontogeny, - sea_level = sea_level - ) -) - -} -\author{ -Pedro Neves, Joshua Lambert, Shu Xie -} -\keyword{internal} diff --git a/man/get_immig_rate_per_capita.Rd b/man/get_immig_rate_per_capita.Rd deleted file mode 100644 index 2340f481..00000000 --- a/man/get_immig_rate_per_capita.Rd +++ /dev/null @@ -1,34 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_rates.R -\name{get_immig_rate_per_capita} -\alias{get_immig_rate_per_capita} -\title{Calculate per-capita immigration rate} -\usage{ -get_immig_rate_per_capita(gam, num_spec, K, A = 1) -} -\arguments{ -\item{gam}{A numeric with the per capita immigration rate.} - -\item{num_spec}{A numeric with the current number of species.} - -\item{K}{A numeric with carrying capacity.} - -\item{A}{A numeric value for island area at a given point in time.} -} -\value{ -A numeric with the per-capita immigration rate given A(t) and K. -} -\description{ -This function is only called directly inside the RHS of the ontogeny -likelihood functions. In all other cases \code{\link{get_immig_rate}()} is to -be called instead. -} -\examples{ -immig_rate_per_capita <- DAISIE:::get_immig_rate_per_capita( - gam = 0.001, - num_spec = 5, - K = 20, - A = 1000 -) -} -\keyword{internal} diff --git a/man/is_island_ontogeny_input.Rd b/man/is_island_ontogeny_input.Rd deleted file mode 100644 index 847b6877..00000000 --- a/man/is_island_ontogeny_input.Rd +++ /dev/null @@ -1,30 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_check_format.R -\name{is_island_ontogeny_input} -\alias{is_island_ontogeny_input} -\title{Check if island_ontogeny is correct after user input} -\usage{ -is_island_ontogeny_input(island_ontogeny) -} -\arguments{ -\item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, -\code{\link{DAISIE_ML_CS}} and plotting a string describing the type of -island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a -numeric describing the type of island ontogeny. Can be \code{0} for -constant, \code{1} for a beta function describing area through time. In ML -functions \code{island_ontogeny = NA} assumes constant ontogeny. Time -dependent estimation is not yet available as development is still ongoing. -Will return an error if called in that case.} -} -\value{ -Boolean stating if island_ontogeny is correct. -} -\description{ -Check if island_ontogeny is correct after user input -} -\seealso{ -is_island_ontogeny_runtime -} -\keyword{internal} diff --git a/man/is_sea_level_input.Rd b/man/is_sea_level_input.Rd deleted file mode 100644 index 67321f2c..00000000 --- a/man/is_sea_level_input.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_check_format.R -\name{is_sea_level_input} -\alias{is_sea_level_input} -\title{Check if sea_level is correct after user input} -\usage{ -is_sea_level_input(sea_level) -} -\arguments{ -\item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a -string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. -\cr In all other functions a numeric describing the type of sea level. Can -be \code{0} for constant, \code{1} for a sine function describing area -through time.} -} -\value{ -Boolean stating if sea_level is correct. -} -\description{ -Check if sea_level is correct after user input -} -\seealso{ -is_sea_level_runtime -} -\keyword{internal} diff --git a/man/is_simulation_outputs.Rd b/man/is_simulation_outputs.Rd deleted file mode 100644 index 3139dbc1..00000000 --- a/man/is_simulation_outputs.Rd +++ /dev/null @@ -1,37 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_check_format.R -\name{is_simulation_outputs} -\alias{is_simulation_outputs} -\title{Measures if the input is a valid collection of simulation -outputs.} -\usage{ -is_simulation_outputs(simulation_outputs) -} -\arguments{ -\item{simulation_outputs}{A list with matrices and vectors of simulation -produced by DAISIE_sim functions.} -} -\value{ -TRUE if the input is a valid collection of simulation -outputs. -} -\description{ -Measures if the input is a valid collection of simulation -outputs. -} -\examples{ -testthat::expect_false(DAISIE:::is_simulation_outputs("nonsense")) - -simulation_outputs <- DAISIE_sim_cr( - time = 2, - M = 1000, - pars = c(2, 1, 20, 0.0001, 1), - replicates = 1, - plot_sims = FALSE - ) -testthat::expect_true(DAISIE:::is_simulation_outputs(simulation_outputs)) -} -\author{ -Richel J.C Bilderbeek, Pedro Neves -} -\keyword{internal} diff --git a/man/island_area.Rd b/man/island_area.Rd index d0ca12f9..1da2d969 100644 --- a/man/island_area.Rd +++ b/man/island_area.Rd @@ -33,8 +33,7 @@ present and the \code{area_pars}.} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -43,8 +42,7 @@ Will return an error if called in that case.} \item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. +\code{"sine"} for a sine function describing area through time. \cr In all other functions a numeric describing the type of sea level. Can be \code{0} for constant, \code{1} for a sine function describing area through time.} diff --git a/man/translate_island_ontogeny.Rd b/man/translate_island_ontogeny.Rd deleted file mode 100644 index b491a2e6..00000000 --- a/man/translate_island_ontogeny.Rd +++ /dev/null @@ -1,30 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_utils.R -\name{translate_island_ontogeny} -\alias{translate_island_ontogeny} -\title{Translate user-friendly ontogeny codes to numerics} -\usage{ -translate_island_ontogeny(island_ontogeny) -} -\arguments{ -\item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, -\code{\link{DAISIE_ML_CS}} and plotting a string describing the type of -island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a -numeric describing the type of island ontogeny. Can be \code{0} for -constant, \code{1} for a beta function describing area through time. In ML -functions \code{island_ontogeny = NA} assumes constant ontogeny. Time -dependent estimation is not yet available as development is still ongoing. -Will return an error if called in that case.} -} -\value{ -Numeric, 0 for null-ontogeny, 1 for beta function -} -\description{ -Translate user-friendly ontogeny codes to numerics -} -\examples{ -translated_ontogeny <- DAISIE:::translate_island_ontogeny("const") -} -\keyword{internal} diff --git a/man/translate_sea_level.Rd b/man/translate_sea_level.Rd deleted file mode 100644 index a486c9be..00000000 --- a/man/translate_sea_level.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/DAISIE_utils.R -\name{translate_sea_level} -\alias{translate_sea_level} -\title{Translate user-friendly sea-level codes to numerics} -\usage{ -translate_sea_level(sea_level) -} -\arguments{ -\item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a -string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. -\cr In all other functions a numeric describing the type of sea level. Can -be \code{0} for constant, \code{1} for a sine function describing area -through time.} -} -\value{ -Numeric, 0 for null-sea-level, 1 for sine function -} -\description{ -Translate user-friendly sea-level codes to numerics -} -\examples{ -translated_sea_level <- DAISIE:::translate_sea_level("const") -} -\keyword{internal} diff --git a/man/update_rates.Rd b/man/update_rates.Rd index 0e9c3b2f..b20a6154 100644 --- a/man/update_rates.Rd +++ b/man/update_rates.Rd @@ -68,8 +68,7 @@ present and the \code{area_pars}.} \item{island_ontogeny}{In \code{\link{DAISIE_sim_time_dep}()}, \code{\link{DAISIE_ML_CS}} and plotting a string describing the type of island ontogeny. Can be \code{"const"}, \code{"beta"} for a beta function -describing area through time. String checked by -\code{\link{is_island_ontogeny_input}()}. \cr In all other functions a +describing area through time. \cr In all other functions a numeric describing the type of island ontogeny. Can be \code{0} for constant, \code{1} for a beta function describing area through time. In ML functions \code{island_ontogeny = NA} assumes constant ontogeny. Time @@ -78,8 +77,7 @@ Will return an error if called in that case.} \item{sea_level}{In \code{\link{DAISIE_sim_time_dep}()} and plotting a string describing the type of sea level. Can be \code{"const"} or -\code{"sine"} for a sine function describing area through time. String -checked by \code{\link{is_sea_level_input}()}. +\code{"sine"} for a sine function describing area through time. \cr In all other functions a numeric describing the type of sea level. Can be \code{0} for constant, \code{1} for a sine function describing area through time.} diff --git a/src/DAISIE_CS.cpp b/src/DAISIE_CS.cpp index 8afa8f8d..07373dd1 100644 --- a/src/DAISIE_CS.cpp +++ b/src/DAISIE_CS.cpp @@ -1,7 +1,14 @@ -// [[Rcpp::plugins(cpp14)]] +// +// Copyright (c) 2023, Hanno Hildenbrandt +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// + // [[Rcpp::depends(BH)]] -//' @export daisie_odeint_cs + #include "config.h" #include "DAISIE_odeint.h" @@ -18,9 +25,11 @@ namespace { static constexpr int default_max_cs_steps = 1000000; static int max_cs_steps = default_max_cs_steps; + // step-size factor for adams_bashforth_moulton integration static constexpr double default_abm_factor = 0.0001; - static double abm_factor = default_abm_factor; + double abm_factor = default_abm_factor; + // common parameter struct param_t @@ -48,9 +57,11 @@ namespace { } // odeint interface - void operator()(const state_type& x, state_type& dx, double t) const + void operator()(const state_type& x, state_type& dx, double /*t*/) const { - if (++p_.steps > max_cs_steps) throw std::runtime_error("cpp_daisie_cs_runmod: too many steps"); + if (++p_.steps > max_cs_steps) { + throw std::runtime_error("cpp_daisie_cs_runmod: too many steps"); + } const auto xx1 = padded_vector_view<2>(x.data().begin(), p_.lx); const auto xx2 = padded_vector_view<2>(x.data().begin() + p_.lx, p_.lx); @@ -113,9 +124,11 @@ namespace { } // odeint interface - void operator()(const state_type& x, state_type& dx, double) const + void operator()(const state_type& x, state_type& dx, double /*t*/) const { - if (++p_.steps > max_cs_steps) throw std::runtime_error("cpp_daisie_cs_runmod_1: too many steps"); + if (++p_.steps > max_cs_steps) { + throw std::runtime_error("cpp_daisie_cs_runmod_1: too many steps"); + } const auto xx1 = padded_vector_view<2>(x.data().begin(), p_.lx); const auto xx2 = padded_vector_view<2>(x.data().begin() + p_.lx, p_.lx); @@ -196,9 +209,11 @@ namespace { } // odeint interface - void operator()(const state_type& x, state_type& dx, double) const + void operator()(const state_type& x, state_type& dx, double /*t*/) const { - if (++p_.steps > max_cs_steps) throw std::runtime_error("cpp_daisie_cs_runmod_2: too many steps"); + if (++p_.steps > max_cs_steps) { + throw std::runtime_error("cpp_daisie_cs_runmod_2: too many steps"); + } const auto xx1 = padded_vector_view<2>(x.data().begin(), p_.lx); const auto xx2 = padded_vector_view<2>(x.data().begin() + p_.lx, p_.lx); @@ -262,9 +277,13 @@ namespace { } // anonymous namespace -//' Driver for the boost::odeint solver +//' Driver for the boost::odeint solver for the CS model //' //' @name daisie_odeint_cs +//' @export daisie_odeint_cs +//' @return Object of type `state_type`, which itself is +//' `vector_t`, with the result of the +//' integration depending on the runmod chosen. RcppExport SEXP daisie_odeint_cs(SEXP rrunmod, SEXP ry, SEXP rtimes, SEXP rlx, SEXP rkk, SEXP rpar, SEXP Stepper, SEXP ratol, SEXP rrtol) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; diff --git a/src/DAISIE_IW.cpp b/src/DAISIE_IW.cpp index ae84a11a..e46f8939 100644 --- a/src/DAISIE_IW.cpp +++ b/src/DAISIE_IW.cpp @@ -1,6 +1,13 @@ +// +// Copyright (c) 2023, Hanno Hildenbrandt +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// + //' @export daisie_odeint_iw -// [[Rcpp::plugins(cpp14)]] // [[Rcpp::plugins(openmp)]] // [[Rcpp::depends(BH)]] // [[Rcpp::depends(RcppEigen)]] @@ -216,9 +223,13 @@ namespace { } // anonymous namespace -//' Driver for the boost::odeint solver +//' Driver for the boost::odeint solver for the IW model //' //' @name daisie_odeint_iw +//' @export daisie_odeint_iw + //' @return Object of type `state_type`, which itself is + //' `vector_t`, with the result of the + //' integration depending on the runmod chosen. RcppExport SEXP daisie_odeint_iw(SEXP ry, SEXP rtimes, SEXP rpars, SEXP Stepper, SEXP atolint, SEXP reltolint) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; diff --git a/src/DAISIE_loglik_rhs_FORTRAN.f95 b/src/DAISIE_loglik_rhs_FORTRAN.f95 index 5c121830..e7ffdc93 100644 --- a/src/DAISIE_loglik_rhs_FORTRAN.f95 +++ b/src/DAISIE_loglik_rhs_FORTRAN.f95 @@ -1,3 +1,10 @@ +! +! Copyright (c) 2023, Rampal S. Etienne +! +! Distributed under the Boost Software License, Version 1.0. (See +! accompanying file LICENSE_1_0.txt or copy at +! http://www.boost.org/LICENSE_1_0.txt) +! !========================================================================== ! Helper function: ! fill vec with N elements from parms, starting at position ii diff --git a/src/DAISIE_odeint.h b/src/DAISIE_odeint.h index 20fa9fa2..088c8141 100644 --- a/src/DAISIE_odeint.h +++ b/src/DAISIE_odeint.h @@ -1,25 +1,47 @@ -// [[Rcpp::plugins(cpp14)]] +// +// Copyright (c) 2023, Hanno Hildenbrandt +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// -#pragma once #ifndef DAISIE_ODEINT_H_INCLUDED #define DAISIE_ODEINT_H_INCLUDED #include "config.h" -#include "ublas_types.h" -#include "patched_bulrisch_stoer.h" // shadow buggy boost header +#include "DAISIE_types.h" #include #include #include #include + +#ifdef USE_BULRISCH_STOER_PATCH + +#include +#include + +using bstime_t = boost::units::quantity; + +#else // USE_BULRISCH_STOER_PATCH + +// The default. Causes unitialized member m_last_dt in +// boost::odeint::bulrisch_stoer<>, declared in +// boost/numreic/odeint/stepper/bulrisch_stoer.hpp +using bstime_t = double; + +#endif // USE_BULRISCH_STOER_PATCH + + using namespace Rcpp; using namespace boost::numeric::odeint; - // type of the ode state using state_type = vector_t; + // zero-value padded view into vector template class padded_vector_view @@ -44,7 +66,7 @@ class padded_vector_view namespace daisie_odeint { - extern double abm_factor; + extern double abm_factor; // defined in DAISIE_CS.cpp template @@ -133,8 +155,8 @@ namespace daisie_odeint { } else if ("odeint::bulirsch_stoer" == stepper) { // outlier in calling convention - using stepper_t = bulirsch_stoer; - integrate_adaptive(stepper_t(atol, rtol), rhs, y, t0, t1, 0.1 * (t1 - t0)); + using stepper_t = bulirsch_stoer; + integrate_adaptive(stepper_t(atol, rtol), rhs, y, bstime_t{t0}, bstime_t{t1}, bstime_t{0.1 * (t1 - t0)}); } else if (0 == stepper.compare(0, stepper.size() - 2, "odeint::adams_bashforth")) { const char steps = stepper.back(); diff --git a/src/DAISIE_types.h b/src/DAISIE_types.h index 78ae8f2f..2a0eb312 100644 --- a/src/DAISIE_types.h +++ b/src/DAISIE_types.h @@ -1,3 +1,124 @@ -#pragma once +// +// Copyright (c) 2023, Hanno Hildenbrandt +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef DAISIE_TYPES_H_INCLUDED +#define DAISIE_TYPES_H_INCLUDED + #include "config.h" -#include "odeint_types.h" +#include +#include +#include + + +namespace ublas = boost::numeric::ublas; + + +template using vector_t = ublas::vector; +template using matrix_t = ublas::matrix; + + +// forward declarations Rcpp <-> boost::numeric::ublas +namespace Rcpp { + + namespace traits { + + template SEXP wrap(const vector_t&); + template SEXP wrap(const matrix_t&); + + template vector_t as(SEXP); + template matrix_t as(SEXP); + + template class Exporter>; + template class Exporter>; + + } + +} + + +#include + + +namespace Rcpp { + + namespace traits { + + template inline SEXP wrap(const vector_t& obj) { + const int RTYPE = Rcpp::traits::r_sexptype_traits::rtype; + return Rcpp::Vector(obj.begin(), obj.end()); + } + + + template inline SEXP wrap(const matrix_t& obj) { + const size_t nr = static_cast(obj.size1()); + const size_t nc = static_cast(obj.size2()); + const int RTYPE = Rcpp::traits::r_sexptype_traits::rtype; + Rcpp::Matrix rmat(nr, nc); + for (size_t i = 0; i < nr; ++i) { + for (size_t j = 0; j < nc; ++j) { + rmat(i, j) = obj(i, j); + } + } + return rmat; + } + + + template + class Exporter> + { + private: + static constexpr int RTYPE = Rcpp::traits::r_sexptype_traits::rtype; + Rcpp::Vector rvec; + + public: + Exporter(SEXP x) : rvec(x) { + if (TYPEOF(x) != RTYPE) { + throw std::invalid_argument("Wrong R type for mapped 1D array"); + } + } + + vector_t get() { + vector_t x(rvec.size()); + std::copy(rvec.begin(), rvec.end(), x.begin()); + return x; + } + }; + + + template + class Exporter> + { + private: + static constexpr int RTYPE = Rcpp::traits::r_sexptype_traits::rtype; + Rcpp::Matrix rmat; + + public: + Exporter(SEXP x) : rmat(x) { + if (TYPEOF(x) != RTYPE) { + throw std::invalid_argument("Wrong R type for mapped 2D array"); + } + } + + matrix_t get() { + const size_t nr = static_cast(rmat.rows()); + const size_t nc = static_cast(rmat.cols()); + matrix_t x(nr, nc); + for (size_t i = 0; i < nr; ++i) { + for (size_t j = 0; j < nc; ++j) { + x(i, j) = rmat(i, j); + } + } + return x; + } + }; + + } + +} + +#endif diff --git a/src/R_init_DAISIE.c b/src/R_init_DAISIE.c index e5fd4b78..450941a3 100644 --- a/src/R_init_DAISIE.c +++ b/src/R_init_DAISIE.c @@ -1,3 +1,11 @@ +// +// Copyright (c) 2023, Hanno Hildenbrandt +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// + // [[Rcpp::plugins(cpp14)]] #include"config.h" diff --git a/src/config.h b/src/config.h index 32cfa85b..c74d5afd 100644 --- a/src/config.h +++ b/src/config.h @@ -1,28 +1,29 @@ +// +// Copyright (c) 2023, Hanno Hildenbrandt +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// + #ifndef ODEINT_CONFIG_H_INCLUDED #define ODEINT_CONFIG_H_INCLUDED // [[Rcpp::plugins(cpp14)]] -// Special case to make use of some steppers that would include -// boost/functional.hpp -// moved to Makevars[.win] -/* -#if __cplusplus >= 201703L -# ifdef _HAS_AUTO_PTR_ETC -# undef _HAS_AUTO_PTR_ETC -# endif -# define _HAS_AUTO_PTR_ETC 0 -#endif - */ - // Special case to make use of some steppers that would include // boost/get_pointer.hpp #ifndef BOOST_NO_AUTO_PTR # define BOOST_NO_AUTO_PTR #endif -// uncomment if unitialized member variable bulirsch_stoer::m_dt_last -// is fixed in boost (BH) +// Addresses unitialized member variable bulirsch_stoer<>::m_dt_last. +// +// The issue is *not* fixed in BOOST_VERSION 1.81.1. +// We need to check for fixes in upcomming boost (BH) releases. +// +// Uncomment if unitialized member variable bulirsch_stoer::m_dt_last +// is fixed in boost (BH): #define USE_BULRISCH_STOER_PATCH #endif diff --git a/src/patched_bulrisch_stoer.h b/src/patched_bulrisch_stoer.h deleted file mode 100644 index cad4f521..00000000 --- a/src/patched_bulrisch_stoer.h +++ /dev/null @@ -1,661 +0,0 @@ -/* - Patched version of - boost/numeric/odeint/stepper/bulirsch_stoer.hpp - - Addresses unitialized member variable bulirsch_stoer<>::m_dt_last. - - Include this header before boost/numeric/odeint to shadow - boost/numeriuc/odeint/stepper/bulrisch_stoer.hpp - - The issue is *not* fixed in BOOST_VERSION == 1.81.0. - We need to check for fixes in upcomming boost (BH) releases. - - Hanno Hildenbrandt 2023 -*/ - -/* - [auto_generated] - boost/numeric/odeint/stepper/bulirsch_stoer.hpp - - [begin_description] - Implementation of the Burlish-Stoer method. As described in - Ernst Hairer, Syvert Paul Norsett, Gerhard Wanner - Solving Ordinary Differential Equations I. Nonstiff Problems. - Springer Series in Comput. Mathematics, Vol. 8, Springer-Verlag 1987, Second revised edition 1993. - [end_description] - - Copyright 2011-2013 Mario Mulansky - Copyright 2011-2013 Karsten Ahnert - Copyright 2012 Christoph Koke - - Distributed under the Boost Software License, Version 1.0. - (See accompanying file LICENSE_1_0.txt or - copy at http://www.boost.org/LICENSE_1_0.txt) -*/ - -#ifdef USE_BULRISCH_STOER_PATCH - -#ifndef BOOST_NUMERIC_ODEINT_STEPPER_BULIRSCH_STOER_HPP_INCLUDED -#define BOOST_NUMERIC_ODEINT_STEPPER_BULIRSCH_STOER_HPP_INCLUDED - - -#include - -#include - -#include // for min/max guidelines - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace boost { -namespace numeric { -namespace odeint { - -template< - class State , - class Value = double , - class Deriv = State , - class Time = Value , - class Algebra = typename algebra_dispatcher< State >::algebra_type , - class Operations = typename operations_dispatcher< State >::operations_type , - class Resizer = initially_resizer - > -class bulirsch_stoer { - -public: - - typedef State state_type; - typedef Value value_type; - typedef Deriv deriv_type; - typedef Time time_type; - typedef Algebra algebra_type; - typedef Operations operations_type; - typedef Resizer resizer_type; -#ifndef DOXYGEN_SKIP - typedef state_wrapper< state_type > wrapped_state_type; - typedef state_wrapper< deriv_type > wrapped_deriv_type; - typedef controlled_stepper_tag stepper_category; - - typedef bulirsch_stoer< State , Value , Deriv , Time , Algebra , Operations , Resizer > controlled_error_bs_type; - - typedef typename inverse_time< time_type >::type inv_time_type; - - typedef std::vector< value_type > value_vector; - typedef std::vector< time_type > time_vector; - typedef std::vector< inv_time_type > inv_time_vector; //should be 1/time_type for boost.units - typedef std::vector< value_vector > value_matrix; - typedef std::vector< size_t > int_vector; - typedef std::vector< wrapped_state_type > state_table_type; -#endif //DOXYGEN_SKIP - const static size_t m_k_max = 8; - - bulirsch_stoer( - value_type eps_abs = 1E-6 , value_type eps_rel = 1E-6 , - value_type factor_x = 1.0 , value_type factor_dxdt = 1.0 , - time_type max_dt = static_cast(0)) - : m_error_checker( eps_abs , eps_rel , factor_x, factor_dxdt ) , m_midpoint() , - m_last_step_rejected( false ) , m_first( true ) , - m_dt_last(static_cast(-1)) , // !!! patched !!! - m_max_dt(max_dt) , - m_interval_sequence( m_k_max+1 ) , - m_coeff( m_k_max+1 ) , - m_cost( m_k_max+1 ) , - m_facmin_table( m_k_max+1 ) , - m_table( m_k_max ) , - STEPFAC1( 0.65 ) , STEPFAC2( 0.94 ) , STEPFAC3( 0.02 ) , STEPFAC4( 4.0 ) , KFAC1( 0.8 ) , KFAC2( 0.9 ) - { - BOOST_USING_STD_MIN(); - BOOST_USING_STD_MAX(); - /* initialize sequence of stage numbers and work */ - for( unsigned short i = 0; i < m_k_max+1; i++ ) - { - m_interval_sequence[i] = 2 * (i+1); - if( i == 0 ) - m_cost[i] = m_interval_sequence[i]; - else - m_cost[i] = m_cost[i-1] + m_interval_sequence[i]; - m_coeff[i].resize(i); - m_facmin_table[i] = pow BOOST_PREVENT_MACRO_SUBSTITUTION( STEPFAC3 , static_cast< value_type >(1) / static_cast< value_type >( 2*i+1 ) ); - for( size_t k = 0 ; k < i ; ++k ) - { - const value_type r = static_cast< value_type >( m_interval_sequence[i] ) / static_cast< value_type >( m_interval_sequence[k] ); - m_coeff[i][k] = 1.0 / ( r*r - static_cast< value_type >( 1.0 ) ); // coefficients for extrapolation - } - } - reset(); - } - - - /* - * Version 1 : try_step( sys , x , t , dt ) - * - * The overloads are needed to solve the forwarding problem - */ - template< class System , class StateInOut > - controlled_step_result try_step( System system , StateInOut &x , time_type &t , time_type &dt ) - { - return try_step_v1( system , x , t, dt ); - } - - /** - * \brief Second version to solve the forwarding problem, can be used with Boost.Range as StateInOut. - */ - template< class System , class StateInOut > - controlled_step_result try_step( System system , const StateInOut &x , time_type &t , time_type &dt ) - { - return try_step_v1( system , x , t, dt ); - } - - /* - * Version 2 : try_step( sys , x , dxdt , t , dt ) - * - * this version does not solve the forwarding problem, boost.range can not be used - */ - template< class System , class StateInOut , class DerivIn > - controlled_step_result try_step( System system , StateInOut &x , const DerivIn &dxdt , time_type &t , time_type &dt ) - { - m_xnew_resizer.adjust_size( x , detail::bind( &controlled_error_bs_type::template resize_m_xnew< StateInOut > , detail::ref( *this ) , detail::_1 ) ); - controlled_step_result res = try_step( system , x , dxdt , t , m_xnew.m_v , dt ); - if( res == success ) - { - boost::numeric::odeint::copy( m_xnew.m_v , x ); - } - return res; - } - - /* - * Version 3 : try_step( sys , in , t , out , dt ) - * - * this version does not solve the forwarding problem, boost.range can not be used - */ - template< class System , class StateIn , class StateOut > - typename boost::disable_if< boost::is_same< StateIn , time_type > , controlled_step_result >::type - try_step( System system , const StateIn &in , time_type &t , StateOut &out , time_type &dt ) - { - typename odeint::unwrap_reference< System >::type &sys = system; - m_dxdt_resizer.adjust_size( in , detail::bind( &controlled_error_bs_type::template resize_m_dxdt< StateIn > , detail::ref( *this ) , detail::_1 ) ); - sys( in , m_dxdt.m_v , t ); - return try_step( system , in , m_dxdt.m_v , t , out , dt ); - } - - - /* - * Full version : try_step( sys , in , dxdt_in , t , out , dt ) - * - * contains the actual implementation - */ - template< class System , class StateIn , class DerivIn , class StateOut > - controlled_step_result try_step( System system , const StateIn &in , const DerivIn &dxdt , time_type &t , StateOut &out , time_type &dt ) - { - if( m_max_dt != static_cast(0) && detail::less_with_sign(m_max_dt, dt, dt) ) - { - // given step size is bigger then max_dt - // set limit and return fail - dt = m_max_dt; - return fail; - } - - BOOST_USING_STD_MIN(); - BOOST_USING_STD_MAX(); - - static const value_type val1( 1.0 ); - - if( m_resizer.adjust_size( in , detail::bind( &controlled_error_bs_type::template resize_impl< StateIn > , detail::ref( *this ) , detail::_1 ) ) ) - { - reset(); // system resized -> reset - } - - if( dt != m_dt_last ) - { - reset(); // step size changed from outside -> reset - } - - bool reject( true ); - - time_vector h_opt( m_k_max+1 ); - inv_time_vector work( m_k_max+1 ); - - time_type new_h = dt; - - /* m_current_k_opt is the estimated current optimal stage number */ - for( size_t k = 0 ; k <= m_current_k_opt+1 ; k++ ) - { - /* the stage counts are stored in m_interval_sequence */ - m_midpoint.set_steps( m_interval_sequence[k] ); - if( k == 0 ) - { - m_midpoint.do_step( system , in , dxdt , t , out , dt ); - /* the first step, nothing more to do */ - } - else - { - m_midpoint.do_step( system , in , dxdt , t , m_table[k-1].m_v , dt ); - extrapolate( k , m_table , m_coeff , out ); - // get error estimate - m_algebra.for_each3( m_err.m_v , out , m_table[0].m_v , - typename operations_type::template scale_sum2< value_type , value_type >( val1 , -val1 ) ); - const value_type error = m_error_checker.error( m_algebra , in , dxdt , m_err.m_v , dt ); - h_opt[k] = calc_h_opt( dt , error , k ); - work[k] = static_cast( m_cost[k] ) / h_opt[k]; - - if( (k == m_current_k_opt-1) || m_first ) - { // convergence before k_opt ? - if( error < 1.0 ) - { - //convergence - reject = false; - if( (work[k] < KFAC2*work[k-1]) || (m_current_k_opt <= 2) ) - { - // leave order as is (except we were in first round) - m_current_k_opt = min BOOST_PREVENT_MACRO_SUBSTITUTION( static_cast(m_k_max)-1 , max BOOST_PREVENT_MACRO_SUBSTITUTION( 2 , static_cast(k)+1 ) ); - new_h = h_opt[k]; - new_h *= static_cast( m_cost[k+1] ) / static_cast( m_cost[k] ); - } else { - m_current_k_opt = min BOOST_PREVENT_MACRO_SUBSTITUTION( static_cast(m_k_max)-1 , max BOOST_PREVENT_MACRO_SUBSTITUTION( 2 , static_cast(k) ) ); - new_h = h_opt[k]; - } - break; - } - else if( should_reject( error , k ) && !m_first ) - { - reject = true; - new_h = h_opt[k]; - break; - } - } - if( k == m_current_k_opt ) - { // convergence at k_opt ? - if( error < 1.0 ) - { - //convergence - reject = false; - if( (work[k-1] < KFAC2*work[k]) ) - { - m_current_k_opt = max BOOST_PREVENT_MACRO_SUBSTITUTION( 2 , static_cast(m_current_k_opt)-1 ); - new_h = h_opt[m_current_k_opt]; - } - else if( (work[k] < KFAC2*work[k-1]) && !m_last_step_rejected ) - { - m_current_k_opt = min BOOST_PREVENT_MACRO_SUBSTITUTION( static_cast(m_k_max-1) , static_cast(m_current_k_opt)+1 ); - new_h = h_opt[k]; - new_h *= static_cast(m_cost[m_current_k_opt])/static_cast(m_cost[k]); - } else - new_h = h_opt[m_current_k_opt]; - break; - } - else if( should_reject( error , k ) ) - { - reject = true; - new_h = h_opt[m_current_k_opt]; - break; - } - } - if( k == m_current_k_opt+1 ) - { // convergence at k_opt+1 ? - if( error < 1.0 ) - { //convergence - reject = false; - if( work[k-2] < KFAC2*work[k-1] ) - m_current_k_opt = max BOOST_PREVENT_MACRO_SUBSTITUTION( 2 , static_cast(m_current_k_opt)-1 ); - if( (work[k] < KFAC2*work[m_current_k_opt]) && !m_last_step_rejected ) - m_current_k_opt = min BOOST_PREVENT_MACRO_SUBSTITUTION( static_cast(m_k_max)-1 , static_cast(k) ); - new_h = h_opt[m_current_k_opt]; - } else - { - reject = true; - new_h = h_opt[m_current_k_opt]; - } - break; - } - } - } - - if( !reject ) - { - t += dt; - } - - if( !m_last_step_rejected || boost::numeric::odeint::detail::less_with_sign(new_h, dt, dt) ) - { - // limit step size - if( m_max_dt != static_cast(0) ) - { - new_h = detail::min_abs(m_max_dt, new_h); - } - m_dt_last = new_h; - dt = new_h; - } - - m_last_step_rejected = reject; - m_first = false; - - if( reject ) - return fail; - else - return success; - } - - /** \brief Resets the internal state of the stepper */ - void reset() - { - m_first = true; - m_last_step_rejected = false; - // crude estimate of optimal order - m_current_k_opt = 4; - /* no calculation because log10 might not exist for value_type! - const value_type logfact( -log10( max BOOST_PREVENT_MACRO_SUBSTITUTION( eps_rel , static_cast< value_type >(1.0E-12) ) ) * 0.6 + 0.5 ); - m_current_k_opt = max BOOST_PREVENT_MACRO_SUBSTITUTION( static_cast( 1 ) , min BOOST_PREVENT_MACRO_SUBSTITUTION( static_cast( m_k_max-1 ) , logfact )); - */ - } - - - /* Resizer methods */ - - template< class StateIn > - void adjust_size( const StateIn &x ) - { - resize_m_dxdt( x ); - resize_m_xnew( x ); - resize_impl( x ); - m_midpoint.adjust_size( x ); - } - - -private: - - template< class StateIn > - bool resize_m_dxdt( const StateIn &x ) - { - return adjust_size_by_resizeability( m_dxdt , x , typename is_resizeable::type() ); - } - - template< class StateIn > - bool resize_m_xnew( const StateIn &x ) - { - return adjust_size_by_resizeability( m_xnew , x , typename is_resizeable::type() ); - } - - template< class StateIn > - bool resize_impl( const StateIn &x ) - { - bool resized( false ); - for( size_t i = 0 ; i < m_k_max ; ++i ) - resized |= adjust_size_by_resizeability( m_table[i] , x , typename is_resizeable::type() ); - resized |= adjust_size_by_resizeability( m_err , x , typename is_resizeable::type() ); - return resized; - } - - - template< class System , class StateInOut > - controlled_step_result try_step_v1( System system , StateInOut &x , time_type &t , time_type &dt ) - { - typename odeint::unwrap_reference< System >::type &sys = system; - m_dxdt_resizer.adjust_size( x , detail::bind( &controlled_error_bs_type::template resize_m_dxdt< StateInOut > , detail::ref( *this ) , detail::_1 ) ); - sys( x , m_dxdt.m_v ,t ); - return try_step( system , x , m_dxdt.m_v , t , dt ); - } - - - template< class StateInOut > - void extrapolate( size_t k , state_table_type &table , const value_matrix &coeff , StateInOut &xest ) - /* polynomial extrapolation, see http://www.nr.com/webnotes/nr3web21.pdf - uses the obtained intermediate results to extrapolate to dt->0 - */ - { - static const value_type val1 = static_cast< value_type >( 1.0 ); - for( int j=k-1 ; j>0 ; --j ) - { - m_algebra.for_each3( table[j-1].m_v , table[j].m_v , table[j-1].m_v , - typename operations_type::template scale_sum2< value_type , value_type >( val1 + coeff[k][j] , -coeff[k][j] ) ); - } - m_algebra.for_each3( xest , table[0].m_v , xest , - typename operations_type::template scale_sum2< value_type , value_type >( val1 + coeff[k][0] , -coeff[k][0]) ); - } - - time_type calc_h_opt( time_type h , value_type error , size_t k ) const - /* calculates the optimal step size for a given error and stage number */ - { - BOOST_USING_STD_MIN(); - BOOST_USING_STD_MAX(); - using std::pow; - value_type expo( 1.0/(2*k+1) ); - value_type facmin = m_facmin_table[k]; - value_type fac; - if (error == 0.0) - fac=1.0/facmin; - else - { - fac = STEPFAC2 / pow BOOST_PREVENT_MACRO_SUBSTITUTION( error / STEPFAC1 , expo ); - fac = max BOOST_PREVENT_MACRO_SUBSTITUTION( static_cast(facmin/STEPFAC4) , min BOOST_PREVENT_MACRO_SUBSTITUTION( static_cast(1.0/facmin) , fac ) ); - } - return h*fac; - } - - controlled_step_result set_k_opt( size_t k , const inv_time_vector &work , const time_vector &h_opt , time_type &dt ) - /* calculates the optimal stage number */ - { - if( k == 1 ) - { - m_current_k_opt = 2; - return success; - } - if( (work[k-1] < KFAC1*work[k]) || (k == m_k_max) ) - { // order decrease - m_current_k_opt = k-1; - dt = h_opt[ m_current_k_opt ]; - return success; - } - else if( (work[k] < KFAC2*work[k-1]) || m_last_step_rejected || (k == m_k_max-1) ) - { // same order - also do this if last step got rejected - m_current_k_opt = k; - dt = h_opt[ m_current_k_opt ]; - return success; - } - else - { // order increase - only if last step was not rejected - m_current_k_opt = k+1; - dt = h_opt[ m_current_k_opt-1 ] * m_cost[ m_current_k_opt ] / m_cost[ m_current_k_opt-1 ] ; - return success; - } - } - - bool in_convergence_window( size_t k ) const - { - if( (k == m_current_k_opt-1) && !m_last_step_rejected ) - return true; // decrease stepsize only if last step was not rejected - return ( (k == m_current_k_opt) || (k == m_current_k_opt+1) ); - } - - bool should_reject( value_type error , size_t k ) const - { - if( k == m_current_k_opt-1 ) - { - const value_type d = m_interval_sequence[m_current_k_opt] * m_interval_sequence[m_current_k_opt+1] / - (m_interval_sequence[0]*m_interval_sequence[0]); - //step will fail, criterion 17.3.17 in NR - return ( error > d*d ); - } - else if( k == m_current_k_opt ) - { - const value_type d = m_interval_sequence[m_current_k_opt] / m_interval_sequence[0]; - return ( error > d*d ); - } else - return error > 1.0; - } - - default_error_checker< value_type, algebra_type , operations_type > m_error_checker; - modified_midpoint< state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type > m_midpoint; - - bool m_last_step_rejected; - bool m_first; - - time_type m_dt_last; - time_type m_t_last; - time_type m_max_dt; - - size_t m_current_k_opt; - - algebra_type m_algebra; - - resizer_type m_dxdt_resizer; - resizer_type m_xnew_resizer; - resizer_type m_resizer; - - wrapped_state_type m_xnew; - wrapped_state_type m_err; - wrapped_deriv_type m_dxdt; - - int_vector m_interval_sequence; // stores the successive interval counts - value_matrix m_coeff; - int_vector m_cost; // costs for interval count - value_vector m_facmin_table; // for precomputed facmin to save pow calls - - state_table_type m_table; // sequence of states for extrapolation - - value_type STEPFAC1 , STEPFAC2 , STEPFAC3 , STEPFAC4 , KFAC1 , KFAC2; -}; - - -/******** DOXYGEN ********/ -/** - * \class bulirsch_stoer - * \brief The Bulirsch-Stoer algorithm. - * - * The Bulirsch-Stoer is a controlled stepper that adjusts both step size - * and order of the method. The algorithm uses the modified midpoint and - * a polynomial extrapolation compute the solution. - * - * \tparam State The state type. - * \tparam Value The value type. - * \tparam Deriv The type representing the time derivative of the state. - * \tparam Time The time representing the independent variable - the time. - * \tparam Algebra The algebra type. - * \tparam Operations The operations type. - * \tparam Resizer The resizer policy type. - */ - - /** - * \fn bulirsch_stoer::bulirsch_stoer( value_type eps_abs , value_type eps_rel , value_type factor_x , value_type factor_dxdt ) - * \brief Constructs the bulirsch_stoer class, including initialization of - * the error bounds. - * - * \param eps_abs Absolute tolerance level. - * \param eps_rel Relative tolerance level. - * \param factor_x Factor for the weight of the state. - * \param factor_dxdt Factor for the weight of the derivative. - */ - - /** - * \fn bulirsch_stoer::try_step( System system , StateInOut &x , time_type &t , time_type &dt ) - * \brief Tries to perform one step. - * - * This method tries to do one step with step size dt. If the error estimate - * is to large, the step is rejected and the method returns fail and the - * step size dt is reduced. If the error estimate is acceptably small, the - * step is performed, success is returned and dt might be increased to make - * the steps as large as possible. This method also updates t if a step is - * performed. Also, the internal order of the stepper is adjusted if required. - * - * \param system The system function to solve, hence the r.h.s. of the ODE. - * It must fulfill the Simple System concept. - * \param x The state of the ODE which should be solved. Overwritten if - * the step is successful. - * \param t The value of the time. Updated if the step is successful. - * \param dt The step size. Updated. - * \return success if the step was accepted, fail otherwise. - */ - - /** - * \fn bulirsch_stoer::try_step( System system , StateInOut &x , const DerivIn &dxdt , time_type &t , time_type &dt ) - * \brief Tries to perform one step. - * - * This method tries to do one step with step size dt. If the error estimate - * is to large, the step is rejected and the method returns fail and the - * step size dt is reduced. If the error estimate is acceptably small, the - * step is performed, success is returned and dt might be increased to make - * the steps as large as possible. This method also updates t if a step is - * performed. Also, the internal order of the stepper is adjusted if required. - * - * \param system The system function to solve, hence the r.h.s. of the ODE. - * It must fulfill the Simple System concept. - * \param x The state of the ODE which should be solved. Overwritten if - * the step is successful. - * \param dxdt The derivative of state. - * \param t The value of the time. Updated if the step is successful. - * \param dt The step size. Updated. - * \return success if the step was accepted, fail otherwise. - */ - - /** - * \fn bulirsch_stoer::try_step( System system , const StateIn &in , time_type &t , StateOut &out , time_type &dt ) - * \brief Tries to perform one step. - * - * \note This method is disabled if state_type=time_type to avoid ambiguity. - * - * This method tries to do one step with step size dt. If the error estimate - * is to large, the step is rejected and the method returns fail and the - * step size dt is reduced. If the error estimate is acceptably small, the - * step is performed, success is returned and dt might be increased to make - * the steps as large as possible. This method also updates t if a step is - * performed. Also, the internal order of the stepper is adjusted if required. - * - * \param system The system function to solve, hence the r.h.s. of the ODE. - * It must fulfill the Simple System concept. - * \param in The state of the ODE which should be solved. - * \param t The value of the time. Updated if the step is successful. - * \param out Used to store the result of the step. - * \param dt The step size. Updated. - * \return success if the step was accepted, fail otherwise. - */ - - - /** - * \fn bulirsch_stoer::try_step( System system , const StateIn &in , const DerivIn &dxdt , time_type &t , StateOut &out , time_type &dt ) - * \brief Tries to perform one step. - * - * This method tries to do one step with step size dt. If the error estimate - * is to large, the step is rejected and the method returns fail and the - * step size dt is reduced. If the error estimate is acceptably small, the - * step is performed, success is returned and dt might be increased to make - * the steps as large as possible. This method also updates t if a step is - * performed. Also, the internal order of the stepper is adjusted if required. - * - * \param system The system function to solve, hence the r.h.s. of the ODE. - * It must fulfill the Simple System concept. - * \param in The state of the ODE which should be solved. - * \param dxdt The derivative of state. - * \param t The value of the time. Updated if the step is successful. - * \param out Used to store the result of the step. - * \param dt The step size. Updated. - * \return success if the step was accepted, fail otherwise. - */ - - - /** - * \fn bulirsch_stoer::adjust_size( const StateIn &x ) - * \brief Adjust the size of all temporaries in the stepper manually. - * \param x A state from which the size of the temporaries to be resized is deduced. - */ - -} -} -} - -#endif // BOOST_NUMERIC_ODEINT_STEPPER_BULIRSCH_STOER_HPP_INCLUDED - -#endif // USE_BULRISCH_STOER_PATCH diff --git a/src/ublas_types.h b/src/ublas_types.h deleted file mode 100644 index 750b7056..00000000 --- a/src/ublas_types.h +++ /dev/null @@ -1,119 +0,0 @@ -// [[Rcpp::plugins(cpp14)]] - -#pragma once -#ifndef UBLAS_TYPES_H_INCLUDED -#define UBLAS_TYPES_H_INCLUDED - -#include "config.h" -#include -#include -#include - - -namespace ublas = boost::numeric::ublas; - - -template using vector_t = ublas::vector; -template using matrix_t = ublas::matrix; - - -// forward declarations Rcpp <-> boost::numeric::ublas -namespace Rcpp { - - namespace traits { - - template SEXP wrap(const vector_t&); - template SEXP wrap(const matrix_t&); - - template vector_t as(SEXP); - template matrix_t as(SEXP); - - template class Exporter>; - template class Exporter>; - - } - -} - - -#include - - -namespace Rcpp { - - namespace traits { - - template inline SEXP wrap(const vector_t& obj) { - const int RTYPE = Rcpp::traits::r_sexptype_traits::rtype; - return Rcpp::Vector(obj.begin(), obj.end()); - } - - - template inline SEXP wrap(const matrix_t& obj) { - const size_t nr = static_cast(obj.size1()); - const size_t nc = static_cast(obj.size2()); - const int RTYPE = Rcpp::traits::r_sexptype_traits::rtype; - Rcpp::Matrix rmat(nr, nc); - for (size_t i = 0; i < nr; ++i) { - for (size_t j = 0; j < nc; ++j) { - rmat(i, j) = obj(i, j); - } - } - return rmat; - } - - - template - class Exporter> - { - private: - static constexpr int RTYPE = Rcpp::traits::r_sexptype_traits::rtype; - Rcpp::Vector rvec; - - public: - Exporter(SEXP x) : rvec(x) { - if (TYPEOF(x) != RTYPE) { - throw std::invalid_argument("Wrong R type for mapped 1D array"); - } - } - - vector_t get() { - vector_t x(rvec.size()); - std::copy(rvec.begin(), rvec.end(), x.begin()); - return x; - } - }; - - - template - class Exporter> - { - private: - static constexpr int RTYPE = Rcpp::traits::r_sexptype_traits::rtype; - Rcpp::Matrix rmat; - - public: - Exporter(SEXP x) : rmat(x) { - if (TYPEOF(x) != RTYPE) { - throw std::invalid_argument("Wrong R type for mapped 2D array"); - } - } - - matrix_t get() { - const size_t nr = static_cast(rmat.rows()); - const size_t nc = static_cast(rmat.cols()); - matrix_t x(nr, nc); - for (size_t i = 0; i < nr; ++i) { - for (size_t j = 0; j < nc; ++j) { - x(i, j) = rmat(i, j); - } - } - return x; - } - }; - - } - -} - -#endif diff --git a/tests/testthat/test-DAISIE_ML1.R b/tests/testthat/test-DAISIE_ML1.R index 4aa7def5..58c56872 100644 --- a/tests/testthat/test-DAISIE_ML1.R +++ b/tests/testthat/test-DAISIE_ML1.R @@ -10,7 +10,6 @@ test_that("use", { idparsopt <- 1:5 parsfix <- NULL idparsfix <- NULL - invisible(capture.output( tested_MLE <- DAISIE_ML1( datalist = datalist, initparsopt = initparsopt, @@ -23,7 +22,6 @@ test_that("use", { res = 15, tolint = c(0.1, 0.01) ) - )) expected_MLE <- data.frame( lambda_c = 3.689104200780465, mu = 4.31030299415995, @@ -48,7 +46,7 @@ test_that("abuse", { parsfix <- NULL idparsfix <- NULL expect_error( - DAISIE:::DAISIE_ML1( + DAISIE_ML1( datalist = "nonsense", initparsopt = initparsopt, idparsopt = idparsopt, diff --git a/tests/testthat/test-DAISIE_ML2.R b/tests/testthat/test-DAISIE_ML2.R index 0d64954e..58af6660 100644 --- a/tests/testthat/test-DAISIE_ML2.R +++ b/tests/testthat/test-DAISIE_ML2.R @@ -2,7 +2,6 @@ test_that("use", { skip_if(Sys.getenv("CI") == "", message = "Run only on CI") skip_on_cran() utils::data(Macaronesia_datalist, package = "DAISIE") - invisible(capture.output( tested_MLE <- DAISIE_ML2( datalist = Macaronesia_datalist, initparsopt = c( @@ -22,9 +21,9 @@ test_that("use", { idparsfix = c(1, 3), tol = c(0.01, 0.1, 0.001), res = 15, - tolint = c(0.1, 0.01) + tolint = c(0.1, 0.01), + verbose = 0 ) - )) expected_MLE <- data.frame( lambda_c = c(0.0, 0.315015693879739, @@ -60,7 +59,7 @@ test_that("use", { test_that("abuse", { skip_if(Sys.getenv("CI") == "", message = "Run only on CI") skip_on_cran() - expect_error(tested_MLE <- DAISIE:::DAISIE_ML2( + expect_error(tested_MLE <- DAISIE_ML2( datalist = "nonsense", initparsopt = c( 1.053151832, diff --git a/tests/testthat/test-DAISIE_ML4.R b/tests/testthat/test-DAISIE_ML4.R index 435ec184..f5aec0ab 100644 --- a/tests/testthat/test-DAISIE_ML4.R +++ b/tests/testthat/test-DAISIE_ML4.R @@ -7,6 +7,7 @@ test_that("DAISIE_ML4 is silent and produces correct output", { idparsopt = 1:6, parsfix = NULL, idparsfix = NULL, + verbose = 0, methode = 'lsodes', optimmethod = 'simplex', CS_version = create_CS_version(model = 2, diff --git a/tests/testthat/test-DAISIE_MW_ML.R b/tests/testthat/test-DAISIE_MW_ML.R index 23b55798..fd52d34c 100644 --- a/tests/testthat/test-DAISIE_MW_ML.R +++ b/tests/testthat/test-DAISIE_MW_ML.R @@ -7,7 +7,7 @@ test_that("DAISIE_MW_ML produces correct output", { utils::data(archipelagos41) invisible(capture.output( - M19_tested <- DAISIE::DAISIE_MW_ML( + M19_tested <- DAISIE_MW_ML( datalist = archipelagos41, initparsopt = c( 0.040073803, @@ -81,7 +81,7 @@ test_that("DAISIE_MW_ML produces correct output when in parallel", { ) invisible(capture.output( - M19_computation <- DAISIE::DAISIE_MW_ML( + M19_computation <- DAISIE_MW_ML( datalist = archipelagos41, initparsopt = c( 0.040073803, diff --git a/tests/testthat/test-DAISIE_ONEcolonist.R b/tests/testthat/test-DAISIE_ONEcolonist.R index c0437b11..86319784 100644 --- a/tests/testthat/test-DAISIE_ONEcolonist.R +++ b/tests/testthat/test-DAISIE_ONEcolonist.R @@ -7,7 +7,7 @@ test_that("DAISIE_ONEcolonist works on an oceanic DAISIE_sim_core", { imm_rate <- 1.0 ana_rate <- 1.0 set.seed(1) - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -17,7 +17,7 @@ test_that("DAISIE_ONEcolonist works on an oceanic DAISIE_sim_core", { island_gradient_angle = 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) nonoceanic_pars <- c(0, 0) - sim <- DAISIE:::DAISIE_sim_core_cr( + sim <- DAISIE_sim_core_cr( time = sim_time, mainland_n = n_mainland_species, pars = c(clado_rate, ext_rate, carr_cap, imm_rate, ana_rate), @@ -51,7 +51,7 @@ test_that("DAISIE_ONEcolonist works on an oceanic DAISIE_sim_core", { init_nonend_spec <- sim$init_nonend_spec init_end_spec <- sim$init_end_spec carrying_capacity <- sim$carrying_capacity - result <- DAISIE:::DAISIE_ONEcolonist( + result <- DAISIE_ONEcolonist( time = sim_time, island_spec = island_spec, stt_table = stt_table @@ -77,7 +77,7 @@ test_that("DAISIE_ONEcolonist works with >=2 cladogenetic with same ancestor", { carr_cap <- 4 imm_rate <- 1 ana_rate <- 0.000001 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -87,7 +87,7 @@ test_that("DAISIE_ONEcolonist works with >=2 cladogenetic with same ancestor", { island_gradient_angle = 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) nonoceanic_pars <- c(0, 0) - expect_silent(out <- DAISIE:::DAISIE_sim_core_cr( + expect_silent(out <- DAISIE_sim_core_cr( time = sim_time, mainland_n = n_mainland_species, pars = c(clado_rate, ext_rate, carr_cap, imm_rate, ana_rate), @@ -108,7 +108,7 @@ test_that("DAISIE_ONEcolonist works with >=2 anagenetic with same ancestor", { carr_cap <- 4 imm_rate <- 1 ana_rate <- 2 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -118,7 +118,7 @@ test_that("DAISIE_ONEcolonist works with >=2 anagenetic with same ancestor", { island_gradient_angle = 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) nonoceanic_pars <- c(0, 0) - expect_silent(out <- DAISIE:::DAISIE_sim_core_cr( + expect_silent(out <- DAISIE_sim_core_cr( time = sim_time, mainland_n = n_mainland_species, pars = c(clado_rate, ext_rate, carr_cap, imm_rate, ana_rate), @@ -137,7 +137,7 @@ test_that("DAISIE_ONEcolonist works with >=2 nonendemic with same ancestor", { carr_cap <- 4 imm_rate <- 3 ana_rate <- 1 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -147,7 +147,7 @@ test_that("DAISIE_ONEcolonist works with >=2 nonendemic with same ancestor", { island_gradient_angle = 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) nonoceanic_pars <- c(0, 0) - expect_silent(out <- DAISIE:::DAISIE_sim_core_cr( + expect_silent(out <- DAISIE_sim_core_cr( time = sim_time, mainland_n = n_mainland_species, pars = c(clado_rate, ext_rate, carr_cap, imm_rate, ana_rate), @@ -185,7 +185,7 @@ test_that("DAISIE_ONEcolonist stac and brts works for single colonist", { "Anagenetic_origin" ) stt_table <- NULL - result <- DAISIE:::DAISIE_ONEcolonist( + result <- DAISIE_ONEcolonist( time = sim_time, island_spec = island_spec, stt_table = stt_table @@ -221,7 +221,7 @@ test_that("DAISIE_ONEcolonist stac and brts works for 1 nonendemic colonist", { "Anagenetic_origin" ) stt_table <- NULL - result <- DAISIE:::DAISIE_ONEcolonist( + result <- DAISIE_ONEcolonist( time = sim_time, island_spec = island_spec, stt_table = stt_table @@ -266,7 +266,7 @@ test_that("DAISIE_ONEcolonist stac and brts works for 2 endemic colonists, "Anagenetic_origin" ) stt_table <- NULL - result <- DAISIE:::DAISIE_ONEcolonist( + result <- DAISIE_ONEcolonist( time = sim_time, island_spec = island_spec, stt_table = stt_table @@ -312,7 +312,7 @@ test_that("DAISIE_ONEcolonist stac and brts works for 3 endemic colonists", { "Anagenetic_origin" ) stt_table <- NULL - result <- DAISIE:::DAISIE_ONEcolonist( + result <- DAISIE_ONEcolonist( time = sim_time, island_spec = island_spec, stt_table = stt_table @@ -380,7 +380,7 @@ test_that("DAISIE_ONEcolonist stac and brts works for 2 endemic clades", { "Anagenetic_origin" ) stt_table <- NULL - result <- DAISIE:::DAISIE_ONEcolonist( + result <- DAISIE_ONEcolonist( time = sim_time, island_spec = island_spec, stt_table = stt_table @@ -461,7 +461,7 @@ test_that("DAISIE_ONEcolonist stac and brts works for 2 endemic clades, "Anagenetic_origin" ) stt_table <- NULL - result <- DAISIE:::DAISIE_ONEcolonist( + result <- DAISIE_ONEcolonist( time = sim_time, island_spec = island_spec, stt_table = stt_table @@ -548,7 +548,7 @@ test_that("DAISIE_ONEcolonist stac and brts works for 2 endemic clades, "Anagenetic_origin" ) stt_table <- NULL - result <- DAISIE:::DAISIE_ONEcolonist( + result <- DAISIE_ONEcolonist( time = sim_time, island_spec = island_spec, stt_table = stt_table @@ -597,7 +597,7 @@ test_that("DAISIE_ONEcolonist stac and brts works for 1 anagenetic clade from imm_rate <- 1.0 ana_rate <- 0 set.seed(3) - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -607,7 +607,7 @@ test_that("DAISIE_ONEcolonist stac and brts works for 1 anagenetic clade from island_gradient_angle = 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) nonoceanic_pars <- c(0, 0) - result <- DAISIE:::DAISIE_sim_core_cr( + result <- DAISIE_sim_core_cr( time = sim_time, mainland_n = n_mainland_species, pars = c(clado_rate, ext_rate, carr_cap, imm_rate, ana_rate), diff --git a/tests/testthat/test-DAISIE_convert_to_classic_plot.R b/tests/testthat/test-DAISIE_convert_to_classic_plot.R index 2cae9ca3..1ca8c389 100644 --- a/tests/testthat/test-DAISIE_convert_to_classic_plot.R +++ b/tests/testthat/test-DAISIE_convert_to_classic_plot.R @@ -8,7 +8,7 @@ test_that("abuse", { # test_that("use", { # utils::data("islands_1type_1000reps", package = "DAISIE") -# simulation_outputs <- DAISIE::DAISIE_convert_to_classic_plot( +# simulation_outputs <- DAISIE_convert_to_classic_plot( # islands_1type_1000reps # ) # expect_true(is_simulation_outputs(simulation_outuputs)) diff --git a/tests/testthat/test-DAISIE_format_CS.R b/tests/testthat/test-DAISIE_format_CS.R index f8f54722..ba91e0a0 100644 --- a/tests/testthat/test-DAISIE_format_CS.R +++ b/tests/testthat/test-DAISIE_format_CS.R @@ -7,7 +7,7 @@ test_that("silent with empty island with correct output", { set.seed(1) island_replicates <- list() out <- list() - out[[1]] <- DAISIE:::DAISIE_sim_core_cr( + out[[1]] <- DAISIE_sim_core_cr( time = time, pars = pars, mainland_n = mainland_n, @@ -25,7 +25,7 @@ test_that("silent with empty island with correct output", { ) island_replicates[[1]] <- out expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS( + formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = time, M = mainland_n, @@ -54,13 +54,13 @@ test_that("silent with non-empty island with correct output", { set.seed(1) island_replicates <- list() out <- list() - out[[1]] <- DAISIE:::DAISIE_sim_core_cr( + out[[1]] <- DAISIE_sim_core_cr( time = time, pars = pars, mainland_n = mainland_n, nonoceanic_pars = c(0, 0), hyper_pars = create_hyper_pars(d = 0, x = 0), - area_pars = DAISIE::create_area_pars( + area_pars = create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -71,7 +71,7 @@ test_that("silent with non-empty island with correct output", { ) island_replicates[[1]] <- out expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS( # nolint + formatted_CS_sim <- DAISIE_format_CS( # nolint island_replicates = island_replicates, time = time, M = mainland_n, @@ -106,13 +106,13 @@ test_that("output with empty island and verbose = TRUE", { set.seed(1) island_replicates <- list() out <- list() - out[[1]] <- DAISIE:::DAISIE_sim_core_cr( + out[[1]] <- DAISIE_sim_core_cr( time = time, pars = pars, mainland_n = mainland_n, nonoceanic_pars = c(0, 0), hyper_pars = create_hyper_pars(d = 0, x = 0), - area_pars = DAISIE::create_area_pars( + area_pars = create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -123,7 +123,7 @@ test_that("output with empty island and verbose = TRUE", { ) island_replicates[[1]] <- out expect_message( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS( + formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = time, M = mainland_n, @@ -145,14 +145,14 @@ test_that("silent with non-empty 2 type island", { set.seed(1) island_replicates <- list() prop_type2_pool <- 0.4 - island_replicates <- DAISIE:::DAISIE_sim_min_type2( + island_replicates <- DAISIE_sim_min_type2( time = total_time, M = M, pars = pars, replicates = replicates, prop_type2_pool = prop_type2_pool, hyper_pars = create_hyper_pars(d = 0, x = 0), - area_pars = DAISIE::create_area_pars( + area_pars = create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -162,7 +162,7 @@ test_that("silent with non-empty 2 type island", { island_gradient_angle = 0), verbose = FALSE) expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS( + formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = total_time, M = mainland_n, @@ -183,7 +183,7 @@ test_that("silent with non-empty 2 type island full stt", { set.seed(1) island_replicates <- list() prop_type2_pool <- 0.4 - island_replicates <- DAISIE:::DAISIE_sim_min_type2( + island_replicates <- DAISIE_sim_min_type2( time = total_time, M = M, pars = pars, @@ -191,7 +191,7 @@ test_that("silent with non-empty 2 type island full stt", { prop_type2_pool = prop_type2_pool, verbose = FALSE, hyper_pars = create_hyper_pars(d = 0, x = 0), - area_pars = DAISIE::create_area_pars( + area_pars = create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -201,7 +201,7 @@ test_that("silent with non-empty 2 type island full stt", { island_gradient_angle = 0) ) expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS( + formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = total_time, M = mainland_n, @@ -212,7 +212,7 @@ test_that("silent with non-empty 2 type island full stt", { test_that("abuse", { expect_error( - DAISIE:::DAISIE_format_CS( + DAISIE_format_CS( island_replicates = "nonsense", time = "nonsense", M = "nonsense", @@ -232,13 +232,13 @@ test_that("use full stt", { set.seed(1) island_replicates <- list() out <- list() - out[[1]] <- DAISIE:::DAISIE_sim_core_cr( + out[[1]] <- DAISIE_sim_core_cr( time = time, pars = pars, mainland_n = mainland_n, nonoceanic_pars = c(0, 0), hyper_pars = create_hyper_pars(d = 0, x = 0), - area_pars = DAISIE::create_area_pars( + area_pars = create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -249,7 +249,7 @@ test_that("use full stt", { ) island_replicates[[1]] <- out expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS( + formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = time, M = mainland_n, @@ -333,21 +333,21 @@ test_that("use complete stt with ontogeny", { ) hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) nonoceanic_pars <- c(0, 0) - island_ontogeny = DAISIE:::translate_island_ontogeny("beta") - sea_level = DAISIE:::translate_sea_level("const") - peak <- DAISIE:::calc_peak(total_time = total_time, + island_ontogeny = translate_island_ontogeny("beta") + sea_level = translate_sea_level("const") + peak <- calc_peak(total_time = total_time, area_pars = area_pars) - Amax <- DAISIE:::get_global_max_area(total_time = total_time, + Amax <- get_global_max_area(total_time = total_time, area_pars = area_pars, peak = peak, island_ontogeny = island_ontogeny, sea_level = sea_level) - Amin <- DAISIE:::get_global_min_area(total_time = total_time, + Amin <- get_global_min_area(total_time = total_time, area_pars = area_pars, peak = peak, island_ontogeny = island_ontogeny, sea_level = sea_level) - out[[1]] <- DAISIE:::DAISIE_sim_core_time_dep( + out[[1]] <- DAISIE_sim_core_time_dep( time = total_time, pars = pars, mainland_n = mainland_n, @@ -363,7 +363,7 @@ test_that("use complete stt with ontogeny", { ) island_replicates[[1]] <- out expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS( + formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = total_time, M = mainland_n, @@ -417,7 +417,7 @@ test_that("full stt works with multiple replicates", { verbose <- FALSE sample_freq <- Inf set.seed(1) - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -430,7 +430,7 @@ test_that("full stt works with multiple replicates", { island_replicates <- list() island_replicates[[1]] <- island_replicates out <- list() - out[[1]] <- DAISIE:::DAISIE_sim_core_cr( + out[[1]] <- DAISIE_sim_core_cr( time = time, pars = pars, mainland_n = mainland_n, @@ -438,7 +438,7 @@ test_that("full stt works with multiple replicates", { hyper_pars = hyper_pars, nonoceanic_pars = nonoceanic_pars ) - out[[2]] <- DAISIE:::DAISIE_sim_core_cr( + out[[2]] <- DAISIE_sim_core_cr( time = time, pars = pars, mainland_n = mainland_n, @@ -448,7 +448,7 @@ test_that("full stt works with multiple replicates", { ) island_replicates[[1]] <- out expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS( + formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = time, M = mainland_n, @@ -464,7 +464,7 @@ test_that("full stt works with empty island", { mainland_n <- 1 verbose <- FALSE sample_freq <- Inf - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -483,7 +483,7 @@ test_that("full stt works with empty island", { out <- list() for (m_spec in 1:mainland_n) { out$branching_times <- c(10) - out <- DAISIE:::DAISIE_sim_core_cr( + out <- DAISIE_sim_core_cr( time = total_time, mainland_n = 1, pars = pars, @@ -496,7 +496,7 @@ test_that("full stt works with empty island", { island_replicates[[rep]] <- full_list } expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS( + formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = total_time, M = mainland_n, @@ -523,12 +523,12 @@ test_that("full stt with two trait states", { set.seed(1) island_replicates <- list() out <- list() - out[[1]] <- DAISIE:::DAISIE_sim_core_trait_dep( + out[[1]] <- DAISIE_sim_core_trait_dep( time = time, pars = pars, mainland_n = mainland_n, hyper_pars = create_hyper_pars(d = 0, x = 0), - area_pars = DAISIE::create_area_pars( + area_pars = create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -540,7 +540,7 @@ test_that("full stt with two trait states", { ) island_replicates[[1]] <- out expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS( + formatted_CS_sim <- DAISIE_format_CS( island_replicates = island_replicates, time = time, M = mainland_n, diff --git a/tests/testthat/test-DAISIE_format_CS_full_stt.R b/tests/testthat/test-DAISIE_format_CS_full_stt.R index 2b2bd8b5..e87ec03b 100644 --- a/tests/testthat/test-DAISIE_format_CS_full_stt.R +++ b/tests/testthat/test-DAISIE_format_CS_full_stt.R @@ -3,7 +3,7 @@ test_that("complete stt, 1 type, no geodynamics, oceanic island, one trait state pars <- c(0.4, 0.2, 10, 2, 0.5) total_time <- 1 mainland_n <- 2 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -24,7 +24,7 @@ test_that("complete stt, 1 type, no geodynamics, oceanic island, one trait state for (m_spec in 1:mainland_n) { out$branching_times <- c(10) while (length(out$branching_times) == 1) { - out <- DAISIE:::DAISIE_sim_core_cr( + out <- DAISIE_sim_core_cr( time = total_time, mainland_n = 1, pars = pars, @@ -40,7 +40,7 @@ test_that("complete stt, 1 type, no geodynamics, oceanic island, one trait state expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS_full_stt( + formatted_CS_sim <- DAISIE_format_CS_full_stt( island_replicates = island_replicates, time = total_time, M = mainland_n, @@ -119,14 +119,14 @@ test_that("complete stt, 1 type, geodynamics, oceanic island, one trait state ) hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) nonoceanic_pars <- c(0, 0) - peak <- DAISIE:::calc_peak(total_time = total_time, + peak <- calc_peak(total_time = total_time, area_pars = area_pars) - Amax <- DAISIE:::get_global_max_area(total_time = total_time, + Amax <- get_global_max_area(total_time = total_time, area_pars = area_pars, peak = peak, island_ontogeny = island_ontogeny, sea_level = sea_level) - Amin <- DAISIE:::get_global_min_area(total_time = total_time, + Amin <- get_global_min_area(total_time = total_time, area_pars = area_pars, peak = peak, island_ontogeny = island_ontogeny, @@ -138,7 +138,7 @@ test_that("complete stt, 1 type, geodynamics, oceanic island, one trait state for (m_spec in 1:mainland_n) { out$branching_times <- c(10) while (length(out$branching_times) == 1) { - out <- DAISIE:::DAISIE_sim_core_time_dep( + out <- DAISIE_sim_core_time_dep( island_ontogeny = 1, time = total_time, mainland_n = 1, @@ -159,7 +159,7 @@ test_that("complete stt, 1 type, geodynamics, oceanic island, one trait state } expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS_full_stt( + formatted_CS_sim <- DAISIE_format_CS_full_stt( island_replicates = island_replicates, time = total_time, M = mainland_n, @@ -217,7 +217,7 @@ test_that("complete stt, 2 type, no geodynamics, oceanic island, one trait state mainland_n <- M verbose <- FALSE replicates <- 2 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -230,7 +230,7 @@ test_that("complete stt, 2 type, no geodynamics, oceanic island, one trait state island_replicates <- list() prop_type2_pool <- 0.4 - island_replicates <- DAISIE:::DAISIE_sim_min_type2( + island_replicates <- DAISIE_sim_min_type2( time = total_time, M = M, pars = pars, @@ -241,7 +241,7 @@ test_that("complete stt, 2 type, no geodynamics, oceanic island, one trait state verbose = FALSE ) expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS_full_stt( + formatted_CS_sim <- DAISIE_format_CS_full_stt( island_replicates = island_replicates, time = total_time, M = mainland_n, @@ -366,7 +366,7 @@ test_that("complete stt, 1 type, no geodynamics, nonoceanic, one trait state ana_rate <- 1.010073119 # anagenesis rate pars <- c(clado_rate, ext_rate, clade_carr_cap, imm_rate, ana_rate) replicates <- 3 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -386,7 +386,7 @@ test_that("complete stt, 1 type, no geodynamics, nonoceanic, one trait state for (m_spec in 1:mainland_n) { out$branching_times <- c(10) while (length(out$branching_times) == 1) { - out <- DAISIE:::DAISIE_sim_core_cr( + out <- DAISIE_sim_core_cr( time = total_time, mainland_n = 1, pars = pars, @@ -400,7 +400,7 @@ test_that("complete stt, 1 type, no geodynamics, nonoceanic, one trait state island_replicates[[rep]] <- full_list } expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS_full_stt( + formatted_CS_sim <- DAISIE_format_CS_full_stt( island_replicates = island_replicates, time = total_time, M = mainland_n, @@ -415,7 +415,7 @@ test_that("complete stt, 1 type, no geodynamics, oceanic island, one trait state total_time <- 1 mainland_n <- 2 verbose <- TRUE - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -437,7 +437,7 @@ test_that("complete stt, 1 type, no geodynamics, oceanic island, one trait state for (m_spec in 1:mainland_n) { out$branching_times <- c(10) while (length(out$branching_times) == 1) { - out <- DAISIE:::DAISIE_sim_core_cr( + out <- DAISIE_sim_core_cr( time = total_time, mainland_n = 1, pars = pars, @@ -451,7 +451,7 @@ test_that("complete stt, 1 type, no geodynamics, oceanic island, one trait state island_replicates[[rep]] <- full_list } expect_message( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS_full_stt( + formatted_CS_sim <- DAISIE_format_CS_full_stt( island_replicates = island_replicates, time = total_time, M = mainland_n, @@ -502,7 +502,7 @@ test_that("complete stt, 1 type, no geodynamics, oceanic,two trait states sea_level = sea_level, extcutoff = extcutoff, hyper_pars = create_hyper_pars(d = 0, x = 0), - area_pars = DAISIE::create_area_pars( + area_pars = create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -530,7 +530,7 @@ test_that("complete stt, 1 type, no geodynamics, oceanic,two trait states sea_level = sea_level, extcutoff = extcutoff, hyper_pars = create_hyper_pars(d = 0, x = 0), - area_pars = DAISIE::create_area_pars( + area_pars = create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -545,7 +545,7 @@ test_that("complete stt, 1 type, no geodynamics, oceanic,two trait states island_replicates[[rep]] <- full_list } expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS_full_stt( + formatted_CS_sim <- DAISIE_format_CS_full_stt( island_replicates = island_replicates, time = total_time, M = mainland_n, @@ -560,7 +560,7 @@ test_that("when no colonization happens returns 0", { pars <- c(0.4, 0.2, 10, 0.000001, 0.5) total_time <- 1 mainland_n <- 1 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -578,7 +578,7 @@ test_that("when no colonization happens returns 0", { full_list <- list() out <- list() for (m_spec in 1:mainland_n) { - out <- DAISIE:::DAISIE_sim_core_cr( + out <- DAISIE_sim_core_cr( time = total_time, mainland_n = 1, pars = pars, @@ -594,7 +594,7 @@ test_that("when no colonization happens returns 0", { expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS_full_stt( + formatted_CS_sim <- DAISIE_format_CS_full_stt( island_replicates = island_replicates, time = total_time, M = mainland_n, diff --git a/tests/testthat/test-DAISIE_format_CS_sampled_stt.R b/tests/testthat/test-DAISIE_format_CS_sampled_stt.R index 7544f826..3b8637b4 100644 --- a/tests/testthat/test-DAISIE_format_CS_sampled_stt.R +++ b/tests/testthat/test-DAISIE_format_CS_sampled_stt.R @@ -5,7 +5,7 @@ test_that("sampled stt, 1 type, no geodynamics, oceanic island (same arguments mainland_n <- 1 verbose <- FALSE sample_freq <- 1 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -78,20 +78,20 @@ test_that("sampled stt, 1 type, geodynamics, oceanic island (same arguments as island_gradient_angle = 0 ) hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) - peak <- DAISIE:::calc_peak(total_time = total_time, + peak <- calc_peak(total_time = total_time, area_pars = area_pars) - Amax <- DAISIE:::get_global_max_area(total_time = total_time, + Amax <- get_global_max_area(total_time = total_time, area_pars = area_pars, peak = peak, island_ontogeny = island_ontogeny, sea_level = sea_level) - Amin <- DAISIE:::get_global_min_area(total_time = total_time, + Amin <- get_global_min_area(total_time = total_time, area_pars = area_pars, peak = peak, island_ontogeny = island_ontogeny, sea_level = sea_level) nonoceanic_pars <- c(0, 0) - out[[1]] <- DAISIE:::DAISIE_sim_core_time_dep( + out[[1]] <- DAISIE_sim_core_time_dep( time = total_time, pars = pars, mainland_n = mainland_n, @@ -106,7 +106,7 @@ test_that("sampled stt, 1 type, geodynamics, oceanic island (same arguments as ) island_replicates[[1]] <- out expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS_sampled_stt( + formatted_CS_sim <- DAISIE_format_CS_sampled_stt( island_replicates = island_replicates, time = total_time, M = mainland_n, @@ -161,7 +161,7 @@ test_that("sampled stt, 2 type, no geodynamics, oceanic island (same arguments verbose <- FALSE replicates <- 1 sample_freq <- 25 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -173,7 +173,7 @@ test_that("sampled stt, 2 type, no geodynamics, oceanic island (same arguments set.seed(1) island_replicates <- list() prop_type2_pool <- 0.4 - island_replicates <- DAISIE:::DAISIE_sim_min_type2( + island_replicates <- DAISIE_sim_min_type2( time = total_time, M = M, pars = pars, @@ -184,7 +184,7 @@ test_that("sampled stt, 2 type, no geodynamics, oceanic island (same arguments verbose = FALSE ) expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS_sampled_stt( + formatted_CS_sim <- DAISIE_format_CS_sampled_stt( island_replicates = island_replicates, time = total_time, M = mainland_n, @@ -242,7 +242,7 @@ test_that("sampled stt, 1 type, no geodynamics, nonoceanic (same arguments as imm_rate <- 0.00933207 # immigration rate ana_rate <- 1.010073119 # anagenesis rate pars <- c(clado_rate, ext_rate, clade_carr_cap, imm_rate, ana_rate) - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -258,7 +258,7 @@ test_that("sampled stt, 1 type, no geodynamics, nonoceanic (same arguments as set.seed(1) island_replicates <- list() out <- list() - out[[1]] <- DAISIE:::DAISIE_sim_core_cr( + out[[1]] <- DAISIE_sim_core_cr( time = total_time, pars = pars, mainland_n = mainland_n, @@ -268,7 +268,7 @@ test_that("sampled stt, 1 type, no geodynamics, nonoceanic (same arguments as ) island_replicates[[1]] <- out expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS_sampled_stt( + formatted_CS_sim <- DAISIE_format_CS_sampled_stt( island_replicates = island_replicates, time = total_time, M = mainland_n, @@ -285,7 +285,7 @@ test_that("sampled stt, 1 type, no geodynamics, oceanic (same arguments as mainland_n <- 2 verbose <- FALSE sample_freq <- 25 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -305,7 +305,7 @@ test_that("sampled stt, 1 type, no geodynamics, oceanic (same arguments as for (m_spec in 1:mainland_n) { out$branching_times <- c(10) while (length(out$branching_times) == 1) { - out <- DAISIE:::DAISIE_sim_core_cr( + out <- DAISIE_sim_core_cr( time = total_time, mainland_n = 1, pars = pars, @@ -320,7 +320,7 @@ test_that("sampled stt, 1 type, no geodynamics, oceanic (same arguments as } expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS_sampled_stt( + formatted_CS_sim <- DAISIE_format_CS_sampled_stt( island_replicates = island_replicates, time = total_time, M = mainland_n, diff --git a/tests/testthat/test-DAISIE_format_CS_trait.R b/tests/testthat/test-DAISIE_format_CS_trait.R index 7db2a982..497c2c03 100644 --- a/tests/testthat/test-DAISIE_format_CS_trait.R +++ b/tests/testthat/test-DAISIE_format_CS_trait.R @@ -40,7 +40,7 @@ test_that("sampled stt, 1 type, no geodynamics, oceanic, two trait states sea_level = sea_level, extcutoff = extcutoff, hyper_pars = create_hyper_pars(d = 0, x = 0), - area_pars = DAISIE::create_area_pars( + area_pars = create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -70,7 +70,7 @@ test_that("sampled stt, 1 type, no geodynamics, oceanic, two trait states sea_level = sea_level, extcutoff = extcutoff, hyper_pars = create_hyper_pars(d = 0, x = 0), - area_pars = DAISIE::create_area_pars( + area_pars = create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -85,7 +85,7 @@ test_that("sampled stt, 1 type, no geodynamics, oceanic, two trait states island_replicates[[rep]] <- full_list } expect_silent( - formatted_CS_sim <- DAISIE:::DAISIE_format_CS_sampled_stt( + formatted_CS_sim <- DAISIE_format_CS_sampled_stt( island_replicates = island_replicates, time = total_time, M = mainland_n, diff --git a/tests/testthat/test-DAISIE_format_GW.R b/tests/testthat/test-DAISIE_format_GW.R index 59e80f36..769e1bc1 100644 --- a/tests/testthat/test-DAISIE_format_GW.R +++ b/tests/testthat/test-DAISIE_format_GW.R @@ -5,7 +5,7 @@ test_that("silent with empty island with correct output", { num_guilds <- 1 verbose <- FALSE sample_freq <- 1 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -18,7 +18,7 @@ test_that("silent with empty island with correct output", { set.seed(1) island_replicates <- list() out <- list() - out[[1]] <- DAISIE:::DAISIE_sim_core_cr( + out[[1]] <- DAISIE_sim_core_cr( time = time, pars = pars, mainland_n = mainland_n, @@ -28,7 +28,7 @@ test_that("silent with empty island with correct output", { ) island_replicates[[1]] <- out expect_silent( - formatted_GW_sim <- DAISIE:::DAISIE_format_GW( + formatted_GW_sim <- DAISIE_format_GW( island_replicates = island_replicates, time = time, M = mainland_n, @@ -56,7 +56,7 @@ test_that("silent with non-empty island with correct output", { num_guilds <- 1 verbose <- FALSE sample_freq <- 1 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -69,7 +69,7 @@ test_that("silent with non-empty island with correct output", { set.seed(1) island_replicates <- list() out <- list() - out[[1]] <- DAISIE:::DAISIE_sim_core_cr( + out[[1]] <- DAISIE_sim_core_cr( time = time, pars = pars, mainland_n = mainland_n, @@ -79,7 +79,7 @@ test_that("silent with non-empty island with correct output", { ) island_replicates[[1]] <- out expect_silent( - formatted_GW_sim <- DAISIE:::DAISIE_format_GW( + formatted_GW_sim <- DAISIE_format_GW( island_replicates = island_replicates, time = time, M = mainland_n, @@ -98,7 +98,7 @@ test_that("output with empty island and verbose = TRUE", { verbose <- TRUE sample_freq <- 1 set.seed(1) - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -110,7 +110,7 @@ test_that("output with empty island and verbose = TRUE", { nonoceanic_pars <- c(0, 0) island_replicates <- list() out <- list() - out[[1]] <- DAISIE:::DAISIE_sim_core_cr( + out[[1]] <- DAISIE_sim_core_cr( time = time, pars = pars, mainland_n = mainland_n, @@ -119,8 +119,8 @@ test_that("output with empty island and verbose = TRUE", { nonoceanic_pars = nonoceanic_pars ) island_replicates[[1]] <- out - expect_output( - formatted_GW_sim <- DAISIE:::DAISIE_format_GW( + expect_message( + formatted_GW_sim <- DAISIE_format_GW( island_replicates = island_replicates, time = time, M = mainland_n, @@ -133,5 +133,5 @@ test_that("output with empty island and verbose = TRUE", { }) test_that("abuse", { - expect_error(DAISIE:::DAISIE_format_GW("nonsense")) + expect_error(DAISIE_format_GW("nonsense")) }) diff --git a/tests/testthat/test-DAISIE_format_IW.R b/tests/testthat/test-DAISIE_format_IW.R index 246d0622..17d43c1d 100644 --- a/tests/testthat/test-DAISIE_format_IW.R +++ b/tests/testthat/test-DAISIE_format_IW.R @@ -4,7 +4,7 @@ test_that("silent with empty island with correct output", { mainland_n <- 10 verbose <- FALSE sample_freq <- 1 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -17,7 +17,7 @@ test_that("silent with empty island with correct output", { set.seed(1) island_replicates <- list() - island_replicates[[1]] <- DAISIE:::DAISIE_sim_core_cr( + island_replicates[[1]] <- DAISIE_sim_core_cr( time = time, pars = pars, mainland_n = mainland_n, @@ -26,7 +26,7 @@ test_that("silent with empty island with correct output", { nonoceanic_pars = nonoceanic_pars ) expect_silent( - formatted_IW_sim <- DAISIE:::DAISIE_format_IW( + formatted_IW_sim <- DAISIE_format_IW( island_replicates = island_replicates, time = time, M = mainland_n, @@ -56,7 +56,7 @@ test_that("silent with non-empty island with correct output", { mainland_n <- 10 verbose <- FALSE sample_freq <- 1 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -68,7 +68,7 @@ test_that("silent with non-empty island with correct output", { nonoceanic_pars <- c(0, 0) set.seed(1) island_replicates <- list() - island_replicates[[1]] <- DAISIE:::DAISIE_sim_core_cr( + island_replicates[[1]] <- DAISIE_sim_core_cr( time = time, pars = pars, mainland_n = mainland_n, @@ -77,7 +77,7 @@ test_that("silent with non-empty island with correct output", { nonoceanic_pars = nonoceanic_pars ) expect_silent( - formatted_IW_sim <- DAISIE:::DAISIE_format_IW( + formatted_IW_sim <- DAISIE_format_IW( island_replicates = island_replicates, time = time, M = mainland_n, @@ -126,7 +126,7 @@ test_that("DAISIE_format_IW prints when verbose = TRUE", { mainland_n <- 1000 verbose <- TRUE sample_freq <- 1 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -138,7 +138,7 @@ test_that("DAISIE_format_IW prints when verbose = TRUE", { nonoceanic_pars <- c(0, 0) set.seed(1) island_replicates <- list() - island_replicates[[1]] <- DAISIE:::DAISIE_sim_core_cr( + island_replicates[[1]] <- DAISIE_sim_core_cr( time = time, pars = pars, mainland_n = mainland_n, @@ -147,7 +147,7 @@ test_that("DAISIE_format_IW prints when verbose = TRUE", { nonoceanic_pars = nonoceanic_pars ) expect_message( - formatted_IW_sim <- DAISIE:::DAISIE_format_IW( + formatted_IW_sim <- DAISIE_format_IW( island_replicates = island_replicates, time = time, M = mainland_n, @@ -165,7 +165,7 @@ test_that("silent with empty nonoceanic island with correct output", { nonoceanic_pars <- c(0.2, 0.5) verbose <- FALSE sample_freq <- 1 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -176,7 +176,7 @@ test_that("silent with empty nonoceanic island with correct output", { hyper_pars <- create_hyper_pars(d = 0, x = 0) set.seed(1) island_replicates <- list() - island_replicates[[1]] <- DAISIE:::DAISIE_sim_core_cr( + island_replicates[[1]] <- DAISIE_sim_core_cr( time = time, mainland_n = mainland_n, pars = pars, @@ -185,7 +185,7 @@ test_that("silent with empty nonoceanic island with correct output", { nonoceanic_pars = nonoceanic_pars ) expect_silent( - formatted_IW_sim <- DAISIE:::DAISIE_format_IW( + formatted_IW_sim <- DAISIE_format_IW( island_replicates = island_replicates, time = time, M = mainland_n, @@ -217,7 +217,7 @@ test_that("silent with non-empty nonoceanic island with nonoceanic_pars <- c(0.2, 0.5) verbose <- FALSE sample_freq <- 1 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -229,7 +229,7 @@ test_that("silent with non-empty nonoceanic island with set.seed(1) island_replicates <- list() - island_replicates[[1]] <- DAISIE:::DAISIE_sim_core_cr( + island_replicates[[1]] <- DAISIE_sim_core_cr( time = time, mainland_n = mainland_n, pars = pars, @@ -238,7 +238,7 @@ test_that("silent with non-empty nonoceanic island with hyper_pars = hyper_pars ) expect_silent( - formatted_IW_sim <- DAISIE:::DAISIE_format_IW( + formatted_IW_sim <- DAISIE_format_IW( island_replicates = island_replicates, time = time, M = mainland_n, @@ -278,7 +278,7 @@ test_that("silent with non-empty nonoceanic island with nonoceanic_pars <- c(0.2, 0.5) verbose <- FALSE sample_freq <- 1 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -290,7 +290,7 @@ test_that("silent with non-empty nonoceanic island with set.seed(1) island_replicates <- list() - island_replicates[[1]] <- DAISIE:::DAISIE_sim_core_cr( + island_replicates[[1]] <- DAISIE_sim_core_cr( time = time, mainland_n = mainland_n, pars = pars, @@ -299,7 +299,7 @@ test_that("silent with non-empty nonoceanic island with hyper_pars = hyper_pars ) expect_silent( - formatted_IW_sim <- DAISIE:::DAISIE_format_IW( + formatted_IW_sim <- DAISIE_format_IW( island_replicates = island_replicates, time = time, M = mainland_n, @@ -342,7 +342,7 @@ test_that("add_brt_table output is correct when length(island) == 1", { stt_all = stt_all, init_nonend_spec = 0, init_end_spec = 0) - formatted_brt <- DAISIE:::add_brt_table(island) + formatted_brt <- add_brt_table(island) brt_table <- matrix(ncol = 5, nrow = 1) colnames(brt_table) <- c("brt", "clade", "event", "endemic", "col") brt_table[1, ] <- c(1, 0, 0, NA, NA) @@ -381,7 +381,7 @@ test_that("add_brt_table output is correct when length(island) != 1", { 0.5288428), stac = 4, missing_species = 0) - formatted_brt <- DAISIE:::add_brt_table(island) + formatted_brt <- add_brt_table(island) brt_table <- matrix(ncol = 5, nrow = 5) colnames(brt_table) <- c("brt", "clade", "event", "endemic", "col") brt_table[1, ] <- c(1, 0, 0, NA, NA) @@ -413,11 +413,11 @@ test_that("add_brt_table output is correct when length(island) != 1", { #test_that("add_brt_table output is correct when length(island_no_stac1or5) != 0") test_that("abuse", { - expect_error(DAISIE:::DAISIE_format_IW("nonsense")) + expect_error(DAISIE_format_IW("nonsense")) }) test_that("abuse", { - expect_error(DAISIE:::add_brt_table("nonsense")) + expect_error(add_brt_table("nonsense")) }) @@ -440,11 +440,11 @@ test_that("silent with empty island with correct output", { start_midway <- FALSE set.seed(1) island_replicates <- list() - island_replicates[[1]] <- DAISIE:::DAISIE_sim_core_trait_dep( + island_replicates[[1]] <- DAISIE_sim_core_trait_dep( time = time, pars = pars, hyper_pars = create_hyper_pars(d = 0, x = 0), - area_pars = DAISIE::create_area_pars( + area_pars = create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -456,7 +456,7 @@ test_that("silent with empty island with correct output", { mainland_n = mainland_n ) expect_silent( - formatted_IW_sim <- DAISIE:::DAISIE_format_IW( + formatted_IW_sim <- DAISIE_format_IW( island_replicates = island_replicates, time = time, M = mainland_n, @@ -503,7 +503,7 @@ test_that("silent when species with two trait states with island_replicates <- list() verbose <- FALSE set.seed(1) - island_replicates[[1]] <- DAISIE:::DAISIE_sim_core_trait_dep( + island_replicates[[1]] <- DAISIE_sim_core_trait_dep( time = time, mainland_n = mainland_n, pars = pars, @@ -511,7 +511,7 @@ test_that("silent when species with two trait states with island_ontogeny = island_ontogeny, sea_level = sea_level, hyper_pars = create_hyper_pars(d = 0, x = 0), - area_pars = DAISIE::create_area_pars( + area_pars = create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -522,7 +522,7 @@ test_that("silent when species with two trait states with extcutoff = extcutoff ) expect_silent( - formatted_IW_sim <- DAISIE:::DAISIE_format_IW( + formatted_IW_sim <- DAISIE_format_IW( island_replicates = island_replicates, time = time, M = mainland_n, diff --git a/tests/testthat/test-DAISIE_loglik_CS.R b/tests/testthat/test-DAISIE_loglik_CS.R index bb55aba9..034fe078 100644 --- a/tests/testthat/test-DAISIE_loglik_CS.R +++ b/tests/testthat/test-DAISIE_loglik_CS.R @@ -82,7 +82,7 @@ test_that("DAISIE_loglik_all produces correct output for relaxed-rate model", { skip_on_cran() utils::data(Galapagos_datalist) invisible(capture.output(suppressWarnings( - loglik <- DAISIE::DAISIE_loglik_all( + loglik <- DAISIE_loglik_all( pars1 = c(2.55068735, 2.68345455, 10.00000000, 0.00933207, 1.01007312), pars2 = c(100, 0, 0, 0, NA), datalist = Galapagos_datalist, @@ -126,8 +126,8 @@ test_that("DAISIE_loglik_all produces same output for CS_version 0 and 1 with Galapagos_datalist2[[i]]$branching_times <- c(4, 4 - 2*i*0.1,4 -2*i*0.1-0.1) Galapagos_datalist2[[i]]$stac <- 2 } - Galapagos_datalist2 <- DAISIE:::add_brt_table(Galapagos_datalist2) - loglik_CS00 <- DAISIE::DAISIE_loglik_all( + Galapagos_datalist2 <- add_brt_table(Galapagos_datalist2) + loglik_CS00 <- DAISIE_loglik_all( pars1 = c(2.55068735, 2.68345455, 10.00000000, 0.00933207, 1.01007312), pars2 = c(100, 11, 0, 0, NA), datalist = Galapagos_datalist2, @@ -135,7 +135,7 @@ test_that("DAISIE_loglik_all produces same output for CS_version 0 and 1 with CS_version = 0, abstolint = 1e-16, reltolint = 1e-10) - loglik_CS10 <- DAISIE::DAISIE_loglik_all( + loglik_CS10 <- DAISIE_loglik_all( pars1 = c(2.55068735, 2.68345455, 10.00000000, 0.00933207, 1.01007312), pars2 = c(100, 11, 0, 0, NA), datalist = Galapagos_datalist2, @@ -144,7 +144,7 @@ test_that("DAISIE_loglik_all produces same output for CS_version 0 and 1 with abstolint = 1e-16, reltolint = 1e-10) testthat::expect_equal(loglik_CS00, loglik_CS10, tol = 5E-6) - loglik_CS01 <- DAISIE::DAISIE_loglik_all( + loglik_CS01 <- DAISIE_loglik_all( pars1 = c(2.55068735, 2.68345455, 10.00000000, 0.00933207, 1.01007312), pars2 = c(100, 11, 1, 0, NA), datalist = Galapagos_datalist2, @@ -152,7 +152,7 @@ test_that("DAISIE_loglik_all produces same output for CS_version 0 and 1 with CS_version = 0, abstolint = 1e-16, reltolint = 1e-10) - loglik_CS11 <- DAISIE::DAISIE_loglik_all( + loglik_CS11 <- DAISIE_loglik_all( pars1 = c(2.55068735, 2.68345455, 10.00000000, 0.00933207, 1.01007312), pars2 = c(100, 11, 1, 0, NA), datalist = Galapagos_datalist2, @@ -174,14 +174,14 @@ test_that("DAISIE_loglik_CS_choice produces equivalent output for ODEINT RKCK54 0.0527, 0.0327, 0.0221, 0.1180, 0.0756, 0.0525, 0.0322, 0.0118) stac <- 2 missnumspec <- 0 - loglik1 <- DAISIE:::DAISIE_loglik_CS_choice( + loglik1 <- DAISIE_loglik_CS_choice( pars1 = pars1, pars2 = pars2, brts = brts, stac = stac, missnumspec = missnumspec ) - loglik2 <- DAISIE:::DAISIE_loglik_CS_choice( + loglik2 <- DAISIE_loglik_CS_choice( pars1 = pars1, pars2 = pars2, brts = brts, diff --git a/tests/testthat/test-DAISIE_loglik_IW_solver.R b/tests/testthat/test-DAISIE_loglik_IW_solver.R index c7013f37..4add87b2 100644 --- a/tests/testthat/test-DAISIE_loglik_IW_solver.R +++ b/tests/testthat/test-DAISIE_loglik_IW_solver.R @@ -24,7 +24,7 @@ test_that("IW and CS loglik is same when K = Inf", { #Galapagos_datalist_IW[[8]]$branching_times <- c(4, 2, 1.41) #Galapagos_datalist_IW[[8]]$stac <- 2 - Galapagos_datalist_IW <- DAISIE:::add_brt_table(Galapagos_datalist_IW) + Galapagos_datalist_IW <- add_brt_table(Galapagos_datalist_IW) invisible(capture.output( loglik_IW <- DAISIE_loglik_IW( pars1 = pars1, @@ -56,7 +56,7 @@ test_that("loglik IW various solver options give similar results", { pars1 <- c(0.2, 0.1, 1000.1, 0.001, 0.3) pars2 <- c(40, 11, 0, 0) - IW0 <- DAISIE::DAISIE_loglik_IW( + IW0 <- DAISIE_loglik_IW( pars1 = pars1, pars2 = pars2, datalist = frogs_datalist, @@ -64,7 +64,7 @@ test_that("loglik IW various solver options give similar results", { abstolint = 1E-12, reltolint = 1E-10, ) - IW1 <- DAISIE::DAISIE_loglik_IW( + IW1 <- DAISIE_loglik_IW( pars1 = pars1, pars2 = pars2, datalist = frogs_datalist, @@ -72,7 +72,7 @@ test_that("loglik IW various solver options give similar results", { abstolint = 1E-12, reltolint = 1E-10, ) - IW2 <- DAISIE::DAISIE_loglik_IW( + IW2 <- DAISIE_loglik_IW( pars1 = pars1, pars2 = pars2, datalist = frogs_datalist, @@ -80,7 +80,7 @@ test_that("loglik IW various solver options give similar results", { abstolint = 1E-12, reltolint = 1E-10, ) - IW3 <- DAISIE::DAISIE_loglik_IW( + IW3 <- DAISIE_loglik_IW( pars1 = pars1, pars2 = pars2, datalist = frogs_datalist, @@ -88,7 +88,7 @@ test_that("loglik IW various solver options give similar results", { abstolint = 1E-12, reltolint = 1E-10, ) - IW4 <- DAISIE::DAISIE_loglik_IW( + IW4 <- DAISIE_loglik_IW( pars1 = pars1, pars2 = pars2, datalist = frogs_datalist, diff --git a/tests/testthat/test-DAISIE_max_rates.R b/tests/testthat/test-DAISIE_max_rates.R index 22413493..1971c399 100644 --- a/tests/testthat/test-DAISIE_max_rates.R +++ b/tests/testthat/test-DAISIE_max_rates.R @@ -1,7 +1,7 @@ test_that("use ontogeny", { total_time <- 1 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 5000, current_area = 2500, proportional_peak_t = 0.5, @@ -12,9 +12,9 @@ test_that("use ontogeny", { ) island_ontogeny <- 1 sea_level <- 0 - peak <- DAISIE:::calc_peak(total_time = total_time, area_pars = area_pars) + peak <- calc_peak(total_time = total_time, area_pars = area_pars) testthat::expect_silent( - global_max_area <- DAISIE:::get_global_max_area( + global_max_area <- get_global_max_area( total_time = total_time, area_pars = area_pars, peak = peak, @@ -25,7 +25,7 @@ test_that("use ontogeny", { total_time <- 15 # Gets actual peak for entire curve testthat::expect_equal( - global_max_area <- DAISIE:::get_global_max_area( + global_max_area <- get_global_max_area( total_time = total_time, area_pars = area_pars, peak = peak, @@ -39,7 +39,7 @@ test_that("use ontogeny", { test_that("use sea level", { total_time <- 1 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1000, current_area = 1, proportional_peak_t = 0, @@ -52,7 +52,7 @@ test_that("use sea level", { island_ontogeny <- 0 sea_level <- 1 testthat::expect_silent( - global_max_area <- DAISIE:::get_global_max_area( + global_max_area <- get_global_max_area( total_time = total_time, area_pars = area_pars, peak = peak, diff --git a/tests/testthat/test-DAISIE_min_rates.R b/tests/testthat/test-DAISIE_min_rates.R index 1122c1cf..9128a43b 100644 --- a/tests/testthat/test-DAISIE_min_rates.R +++ b/tests/testthat/test-DAISIE_min_rates.R @@ -1,7 +1,7 @@ test_that("use ontogeny", { total_time <- 1 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 5000, current_area = 2500, proportional_peak_t = 0.5, @@ -12,9 +12,9 @@ test_that("use ontogeny", { ) island_ontogeny <- 1 sea_level <- 0 - peak <- DAISIE:::calc_peak(total_time = total_time, area_pars = area_pars) + peak <- calc_peak(total_time = total_time, area_pars = area_pars) testthat::expect_silent( - global_min_area <- DAISIE:::get_global_min_area( + global_min_area <- get_global_min_area( total_time = total_time, area_pars = area_pars, peak = peak, @@ -26,7 +26,7 @@ test_that("use ontogeny", { test_that("use sea level", { total_time <- 1 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1000, current_area = 1000, proportional_peak_t = 0, @@ -38,7 +38,7 @@ test_that("use sea level", { island_ontogeny <- 0 sea_level <- 1 testthat::expect_silent( - global_min_area <- DAISIE:::get_global_min_area( + global_min_area <- get_global_min_area( total_time = total_time, area_pars = area_pars, island_ontogeny = island_ontogeny, diff --git a/tests/testthat/test-DAISIE_plot_stt.R b/tests/testthat/test-DAISIE_plot_stt.R index 45a9faea..303f663d 100644 --- a/tests/testthat/test-DAISIE_plot_stt.R +++ b/tests/testthat/test-DAISIE_plot_stt.R @@ -1,12 +1,12 @@ test_that("use", { skip("Plots: Run and manually inspect output") utils::data(islands_1type_1000reps, package = "DAISIE") - plot_lists <- DAISIE:::DAISIE_convert_to_classic_plot( + plot_lists <- DAISIE_convert_to_classic_plot( simulation_outputs = islands_1type_1000reps ) type <- names(plot_lists)[1] expect_silent( - DAISIE:::DAISIE_plot_stt( + DAISIE_plot_stt( plot_plus_one = FALSE, time = 4, plot_lists = plot_lists, diff --git a/tests/testthat/test-DAISIE_sim_core.R b/tests/testthat/test-DAISIE_sim_core.R index 886c05db..5c977aa0 100644 --- a/tests/testthat/test-DAISIE_sim_core.R +++ b/tests/testthat/test-DAISIE_sim_core.R @@ -10,7 +10,7 @@ test_that("Clean run should be silent", { ana_rate <- 1.0 testthat::expect_silent( - DAISIE:::DAISIE_sim_core_cr( + DAISIE_sim_core_cr( time = sim_time, mainland_n = n_mainland_species, pars = c(clado_rate, ext_rate, carr_cap, imm_rate, ana_rate), @@ -32,7 +32,7 @@ test_that("Clean run should be silent", { test_that("Ontogeny simulation should run silent", { set.seed(234567890) - testthat::expect_silent(DAISIE:::DAISIE_sim_core_time_dep( + testthat::expect_silent(DAISIE_sim_core_time_dep( time = 10, mainland_n = 1000, pars = c(0.0001, 2.2, 0.005, 0.001, 1), diff --git a/tests/testthat/test-DAISIE_sim_core_cr.R b/tests/testthat/test-DAISIE_sim_core_cr.R index 1a50caec..51527dcc 100644 --- a/tests/testthat/test-DAISIE_sim_core_cr.R +++ b/tests/testthat/test-DAISIE_sim_core_cr.R @@ -7,7 +7,7 @@ test_that("Clean run should be silent", { carr_cap <- 4 imm_rate <- 1.0 ana_rate <- 1.0 - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -18,7 +18,7 @@ test_that("Clean run should be silent", { hyper_pars <- create_hyper_pars(d = 0, x = 0) nonoceanic_pars <- c(0, 0) expect_silent( - DAISIE:::DAISIE_sim_core_cr( + DAISIE_sim_core_cr( time = sim_time, mainland_n = n_mainland_species, pars = c(clado_rate, ext_rate, carr_cap, imm_rate, ana_rate), @@ -31,7 +31,7 @@ test_that("Clean run should be silent", { test_that("A non-oceanic run with non-zero sampling should have native species on the island", { - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -40,7 +40,7 @@ test_that("A non-oceanic run with non-zero sampling should have native sea_level_frequency = 0, island_gradient_angle = 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) - nonoceanic_sim <- DAISIE:::DAISIE_sim_core_cr( + nonoceanic_sim <- DAISIE_sim_core_cr( time = 0.4, mainland_n = 1000, pars = c( @@ -62,7 +62,7 @@ test_that("DAISIE_sim_core output is correct", { time <- 1 mainland_n <- 100 set.seed(5) - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -72,7 +72,7 @@ test_that("DAISIE_sim_core output is correct", { island_gradient_angle = 0) nonoceanic_pars <- c(0, 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) - sim_core <- DAISIE:::DAISIE_sim_core_cr( + sim_core <- DAISIE_sim_core_cr( time = time, mainland_n = mainland_n, pars = c(2, 2, 20, 0.1, 1), @@ -94,7 +94,7 @@ test_that("DAISIE_sim_core output is correct", { test_that("DAISIE_sim_core with land-bridge starting at time = 0 for CS uses the second parameter set at time = 0", { - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -104,7 +104,7 @@ test_that("DAISIE_sim_core with land-bridge starting at time = 0 for CS uses island_gradient_angle = 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) expect_silent( - DAISIE:::DAISIE_sim_core_cr_shift( + DAISIE_sim_core_cr_shift( time = 10, mainland_n = 1, pars = c(1, 1, 10, 0.1, 1, 2, 2, 20, 0.2, 1), @@ -117,7 +117,7 @@ test_that("DAISIE_sim_core with land-bridge starting at time = 0 for CS uses test_that("DAISIE_sim_core fails when pars[4] == 0 && nonoceanic_pars[1] == 0", { - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -128,7 +128,7 @@ test_that("DAISIE_sim_core fails when pars[4] == 0 && nonoceanic_pars <- c(0, 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) expect_error( - DAISIE:::DAISIE_sim_core_cr( + DAISIE_sim_core_cr( time = 1, mainland_n = 100, pars = c(2, 2, 20, 0, 1), diff --git a/tests/testthat/test-DAISIE_sim_core_cr_shift.R b/tests/testthat/test-DAISIE_sim_core_cr_shift.R index ec7a6aea..200f496b 100644 --- a/tests/testthat/test-DAISIE_sim_core_cr_shift.R +++ b/tests/testthat/test-DAISIE_sim_core_cr_shift.R @@ -1,7 +1,7 @@ test_that("split-rate model runs silent and gives correct output", { set.seed(1) - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -12,7 +12,7 @@ test_that("split-rate model runs silent and nonoceanic_pars <- c(0, 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) expect_silent( - DAISIE:::DAISIE_sim_core_cr_shift( + DAISIE_sim_core_cr_shift( time = 10, mainland_n = 1, pars = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), @@ -25,7 +25,7 @@ test_that("split-rate model runs silent and }) test_that("abuse split-rate model with time smaller than shift_times", { - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -35,7 +35,7 @@ test_that("abuse split-rate model with time smaller than shift_times", { island_gradient_angle = 0) nonoceanic_pars <- c(0, 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) - expect_error(DAISIE:::DAISIE_sim_core_cr_shift( + expect_error(DAISIE_sim_core_cr_shift( time = 1, mainland_n = 1, pars = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), @@ -45,7 +45,7 @@ test_that("abuse split-rate model with time smaller than shift_times", { }) test_that("abuse split-rate model with gamma = 0", { - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -55,7 +55,7 @@ test_that("abuse split-rate model with gamma = 0", { island_gradient_angle = 0) nonoceanic_pars <- c(0, 0) hyper_pars <- create_hyper_pars(d = 0, x = 0) - expect_error(DAISIE:::DAISIE_sim_core_cr_shift( + expect_error(DAISIE_sim_core_cr_shift( time = 1, mainland_n = 1, pars = c(1, 1, 1, 0, 1, 1, 1, 1, 1, 1), diff --git a/tests/testthat/test-DAISIE_sim_core_time_dep.R b/tests/testthat/test-DAISIE_sim_core_time_dep.R index 17bc5b89..c2002d18 100644 --- a/tests/testthat/test-DAISIE_sim_core_time_dep.R +++ b/tests/testthat/test-DAISIE_sim_core_time_dep.R @@ -12,23 +12,23 @@ test_that("Ontogeny oceanic should run silent IW", { island_gradient_angle = 0) nonoceanic_pars <- c(0, 0) hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) - island_ontogeny <- DAISIE:::translate_island_ontogeny("beta") - sea_level <- DAISIE:::translate_sea_level("const") - peak <- DAISIE:::calc_peak(total_time = total_time, + island_ontogeny <- translate_island_ontogeny("beta") + sea_level <- translate_sea_level("const") + peak <- calc_peak(total_time = total_time, area_pars = area_pars) - Amax <- DAISIE:::get_global_max_area(total_time = total_time, + Amax <- get_global_max_area(total_time = total_time, area_pars = area_pars, peak = peak, island_ontogeny = island_ontogeny, sea_level = sea_level) - Amin <- DAISIE:::get_global_min_area(total_time = total_time, + Amin <- get_global_min_area(total_time = total_time, area_pars = area_pars, peak = peak, island_ontogeny = island_ontogeny, sea_level = sea_level) set.seed(234567890) expect_silent( - DAISIE:::DAISIE_sim_core_time_dep( + DAISIE_sim_core_time_dep( time = total_time, mainland_n = mainland_n, pars = pars, @@ -49,8 +49,8 @@ test_that("Ontogeny oceanic should run silent CS", { total_time <- 10 mainland_n <- 1 pars <- c(0.0001, 2.2, 0.005, 0.001, 1) - island_ontogeny <- DAISIE:::translate_island_ontogeny("beta") - sea_level <- DAISIE:::translate_sea_level("const") + island_ontogeny <- translate_island_ontogeny("beta") + sea_level <- translate_sea_level("const") area_pars <- create_area_pars( max_area = 5000, current_area = 2500, @@ -61,21 +61,21 @@ test_that("Ontogeny oceanic should run silent CS", { island_gradient_angle = 0) nonoceanic_pars <- c(0, 0) hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) - peak <- DAISIE:::calc_peak(total_time = total_time, + peak <- calc_peak(total_time = total_time, area_pars = area_pars) - Amax <- DAISIE:::get_global_max_area(total_time = total_time, + Amax <- get_global_max_area(total_time = total_time, area_pars = area_pars, peak = peak, island_ontogeny = island_ontogeny, sea_level = sea_level) - Amin <- DAISIE:::get_global_min_area(total_time = total_time, + Amin <- get_global_min_area(total_time = total_time, area_pars = area_pars, peak = peak, island_ontogeny = island_ontogeny, sea_level = sea_level) set.seed(420) expect_silent( - DAISIE:::DAISIE_sim_core_time_dep( + DAISIE_sim_core_time_dep( time = total_time, mainland_n = mainland_n, pars = pars, @@ -105,23 +105,23 @@ test_that("Ontogeny oceanic with sea level should run silent CS", { island_gradient_angle = 30) nonoceanic_pars <- c(0, 0) hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) - island_ontogeny <- DAISIE:::translate_island_ontogeny("beta") + island_ontogeny <- translate_island_ontogeny("beta") sea_level <- translate_sea_level("const") - peak <- DAISIE:::calc_peak(total_time = total_time, + peak <- calc_peak(total_time = total_time, area_pars = area_pars) - Amax <- DAISIE:::get_global_max_area(total_time = total_time, + Amax <- get_global_max_area(total_time = total_time, area_pars = area_pars, peak = peak, island_ontogeny = island_ontogeny, sea_level = sea_level) - Amin <- DAISIE:::get_global_min_area(total_time = total_time, + Amin <- get_global_min_area(total_time = total_time, area_pars = area_pars, peak = peak, island_ontogeny = island_ontogeny, sea_level = sea_level) set.seed(439) expect_silent( - out <- DAISIE:::DAISIE_sim_core_time_dep( + out <- DAISIE_sim_core_time_dep( time = total_time, mainland_n = mainland_n, pars = pars, @@ -152,22 +152,22 @@ test_that("all species extinct if island dead", { sea_level_frequency = 0, island_gradient_angle = 0) nonoceanic_pars <- c(0, 0) - island_ontogeny <- DAISIE:::translate_island_ontogeny("beta") - sea_level <- DAISIE:::translate_sea_level("const") - peak <- DAISIE:::calc_peak(total_time = total_time, + island_ontogeny <- translate_island_ontogeny("beta") + sea_level <- translate_sea_level("const") + peak <- calc_peak(total_time = total_time, area_pars = area_pars) - Amax <- DAISIE:::get_global_max_area(total_time = total_time, + Amax <- get_global_max_area(total_time = total_time, area_pars = area_pars, peak = peak, island_ontogeny = island_ontogeny, sea_level = sea_level) - Amin <- DAISIE:::get_global_min_area(total_time = total_time, + Amin <- get_global_min_area(total_time = total_time, area_pars = area_pars, peak = peak, island_ontogeny = island_ontogeny, sea_level = sea_level) set.seed(1) - ontogeny_sim <- DAISIE:::DAISIE_sim_core_time_dep( + ontogeny_sim <- DAISIE_sim_core_time_dep( time = total_time, mainland_n = mainland_n, pars = pars, @@ -209,7 +209,7 @@ test_that("!is.null(area_pars) && island_ontogeny == 'const'", { Amax <- 1 Amin <- 1 expect_error( - DAISIE:::DAISIE_sim_core_time_dep( + DAISIE_sim_core_time_dep( time = total_time, mainland_n = mainland_n, pars = pars, @@ -237,7 +237,7 @@ test_that("(is.null(ext_pars) || is.null(area_pars)) && sea_level <- 1 expect_error( - DAISIE:::DAISIE_sim_core_time_dep( + DAISIE_sim_core_time_dep( time = time, mainland_n = mainland_n, pars = pars, @@ -254,7 +254,7 @@ test_that("(is.null(ext_pars) || is.null(area_pars)) && test_that("abuse time dependent model with gamma = 0", { - expect_error(DAISIE:::DAISIE_sim_core_time_dep( + expect_error(DAISIE_sim_core_time_dep( time = 1, mainland_n = 1, pars = c(1, 1, 1, 0, 1), diff --git a/tests/testthat/test-DAISIE_sim_core_trait_dep.R b/tests/testthat/test-DAISIE_sim_core_trait_dep.R index a7ec0b84..1687ef8f 100644 --- a/tests/testthat/test-DAISIE_sim_core_trait_dep.R +++ b/tests/testthat/test-DAISIE_sim_core_trait_dep.R @@ -1,11 +1,11 @@ test_that("nonontogeny oceanic trait_dependnet island should run silent IW", { set.seed(234567890) expect_silent( - DAISIE:::DAISIE_sim_core_trait_dep( + DAISIE_sim_core_trait_dep( time = 10, mainland_n = 100, hyper_pars = create_hyper_pars(d = 0, x = 0), - area_pars = DAISIE::create_area_pars( + area_pars = create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -29,11 +29,11 @@ test_that("nonontogeny oceanic trait_dependnet island should run silent IW", { test_that("nonontogeny oceanic trait_dependnet island should run silent CS", { set.seed(420) expect_silent( - DAISIE:::DAISIE_sim_core_trait_dep( + DAISIE_sim_core_trait_dep( time = 10, mainland_n = 0, hyper_pars = create_hyper_pars(d = 0, x = 0), - area_pars = DAISIE::create_area_pars( + area_pars = create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -57,11 +57,11 @@ test_that("nonontogeny oceanic trait_dependnet island should run silent CS", { test_that("abuse NULL trait pars", { set.seed(234567890) expect_error( - DAISIE:::DAISIE_sim_core_trait_dep( + DAISIE_sim_core_trait_dep( time = 10, mainland_n = 100, hyper_pars = create_hyper_pars(d = 0, x = 0), - area_pars = DAISIE::create_area_pars( + area_pars = create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -79,11 +79,11 @@ test_that("abuse NULL trait pars", { test_that("abuse NULL trait pars", { set.seed(234567890) expect_error( - DAISIE:::DAISIE_sim_core_trait_dep( + DAISIE_sim_core_trait_dep( time = 10, mainland_n = 100, hyper_pars = create_hyper_pars(d = 0, x = 0), - area_pars = DAISIE::create_area_pars( + area_pars = create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, diff --git a/tests/testthat/test-DAISIE_sim_cr.R b/tests/testthat/test-DAISIE_sim_cr.R index c5053986..19c1eb7c 100644 --- a/tests/testthat/test-DAISIE_sim_cr.R +++ b/tests/testthat/test-DAISIE_sim_cr.R @@ -567,8 +567,8 @@ test_that("constant rate oceanic CS prints correct output when replicates <- 1 verbose <- TRUE set.seed(1) - expect_output( - sim <- DAISIE::DAISIE_sim_cr(time = total_time, + expect_message( + sim <- DAISIE_sim_cr(time = total_time, M = mainland_n, pars = pars, replicates = replicates, @@ -586,8 +586,8 @@ test_that("constant rate oceanic IW prints correct output when replicates <- 1 verbose <- TRUE set.seed(1) - expect_output( - sim <- DAISIE::DAISIE_sim_cr(time = total_time, + expect_message( + sim <- DAISIE_sim_cr(time = total_time, M = mainland_n, pars = pars, replicates = replicates, @@ -615,7 +615,7 @@ test_that("2 type simulation with divdepmodel = 'CS' verbose run should ana_rate_type_2 <- 1.0 prop_type2_pool <- 0.1 replicates_apply_type2 <- FALSE - expect_output( + expect_message( sim <- DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -648,7 +648,7 @@ test_that("A divdepmodel = 'GW' run with verbose should print", { imm_rate <- 0.01 ana_rate <- 1.0 num_guilds <- 5 - expect_output( + expect_message( DAISIE_sim_cr( time = island_age, M = n_mainland_species, @@ -672,7 +672,7 @@ test_that("2 type, no geodynamics, nonoceanic should give error", { set.seed(1) prop_type2_pool <- 0.4 nonoceanic_pars <- c(0.5, 0.5) - expect_error(DAISIE::DAISIE_sim_cr( + expect_error(DAISIE_sim_cr( time = total_time, M = M, pars = pars, diff --git a/tests/testthat/test-DAISIE_sim_cr_shift.R b/tests/testthat/test-DAISIE_sim_cr_shift.R index 9abbc4c1..a33f7ee2 100644 --- a/tests/testthat/test-DAISIE_sim_cr_shift.R +++ b/tests/testthat/test-DAISIE_sim_cr_shift.R @@ -129,7 +129,7 @@ test_that("abuse split-rates model", { }) test_that("split-rates model prints when verbose = TRUE", { - expect_output( + expect_message( DAISIE_sim_cr_shift( time = 10, M = 10, diff --git a/tests/testthat/test-DAISIE_sim_time_dep.R b/tests/testthat/test-DAISIE_sim_time_dep.R index 4382d0be..d1dd8dee 100644 --- a/tests/testthat/test-DAISIE_sim_time_dep.R +++ b/tests/testthat/test-DAISIE_sim_time_dep.R @@ -341,7 +341,7 @@ test_that("A clean CS ontogeny run with verbose should print to console", { sea_level <- "const" extcutoff <- 1000 hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) - expect_output( + expect_message( DAISIE_sim_time_dep( time = island_age, M = n_mainland_species, @@ -387,7 +387,7 @@ test_that("A clean IW ontogeny run should produce no output", { extcutoff <- 1000 hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) nonoceanic_pars <- c(0, 0) - expect_output( + expect_message( DAISIE_sim_time_dep( time = island_age, M = n_mainland_species, @@ -436,7 +436,7 @@ test_that("A clean GW ontogeny run should produce no output", { extcutoff <- 1000 hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) nonoceanic_pars <- c(0, 0) - expect_output( + expect_message( DAISIE_sim_time_dep( time = island_age, M = n_mainland_species, diff --git a/tests/testthat/test-are_max_rates_gt_rates.R b/tests/testthat/test-are_max_rates_gt_rates.R index 72586a40..130217f3 100644 --- a/tests/testthat/test-are_max_rates_gt_rates.R +++ b/tests/testthat/test-are_max_rates_gt_rates.R @@ -1,6 +1,6 @@ test_that("basic use", { expect_true( - DAISIE:::are_max_rates_gt_rates( + are_max_rates_gt_rates( rates = list( immig_rate = 0.1, ext_rate = 0.2, @@ -16,7 +16,7 @@ test_that("basic use", { ) ) expect_true( - DAISIE:::are_max_rates_gt_rates( + are_max_rates_gt_rates( rates = list( immig_rate = 0.1, ext_rate = 0.2, @@ -36,7 +36,7 @@ test_that("basic use", { test_that("check returns FALSE when wrong", { expect_false( - DAISIE:::are_max_rates_gt_rates( + are_max_rates_gt_rates( rates = list( immig_rate = 0.1, ext_rate = 0.2, @@ -53,7 +53,7 @@ test_that("check returns FALSE when wrong", { ) expect_false( - DAISIE:::are_max_rates_gt_rates( + are_max_rates_gt_rates( rates = list( immig_rate = 0.1, ext_rate = 0.2, @@ -69,7 +69,7 @@ test_that("check returns FALSE when wrong", { ) ) expect_false( - DAISIE:::are_max_rates_gt_rates( + are_max_rates_gt_rates( rates = list( immig_rate = 0.1, ext_rate = 0.2, @@ -86,7 +86,7 @@ test_that("check returns FALSE when wrong", { ) expect_false( - DAISIE:::are_max_rates_gt_rates( + are_max_rates_gt_rates( rates = list( immig_rate = 0.1, ext_rate = 0.2, @@ -102,7 +102,7 @@ test_that("check returns FALSE when wrong", { ) ) expect_false( - DAISIE:::are_max_rates_gt_rates( + are_max_rates_gt_rates( rates = list( immig_rate = "nonsense", ext_rate = 0.2, @@ -118,7 +118,7 @@ test_that("check returns FALSE when wrong", { ) ) expect_false( - DAISIE:::are_max_rates_gt_rates( + are_max_rates_gt_rates( rates = list( immig_rate = 0.1, ext_rate = 0.2, diff --git a/tests/testthat/test-get_ana_rate.R b/tests/testthat/test-get_ana_rate.R index 8055238c..23dd32d8 100644 --- a/tests/testthat/test-get_ana_rate.R +++ b/tests/testthat/test-get_ana_rate.R @@ -1,10 +1,10 @@ test_that("use", { ps_ana_rate <- 1 n_immigrants <- 5 - ana_rate <- DAISIE:::get_ana_rate( + ana_rate <- get_ana_rate( laa = ps_ana_rate, num_immigrants = n_immigrants) - created <- DAISIE:::get_ana_rate( + created <- get_ana_rate( laa = 1, num_immigrants = 5) expected <- ps_ana_rate * n_immigrants diff --git a/tests/testthat/test-get_clado_rate.R b/tests/testthat/test-get_clado_rate.R index c2d8399b..c356f1e0 100644 --- a/tests/testthat/test-get_clado_rate.R +++ b/tests/testthat/test-get_clado_rate.R @@ -2,9 +2,9 @@ test_that("use area constant diversity-independent", { ps_clado_rate <- 0.2 carr_cap <- Inf n_species <- 4 - hyper_pars <- DAISIE:::create_hyper_pars(d = 0, x = 0) + hyper_pars <- create_hyper_pars(d = 0, x = 0) area <- 1 - created <- DAISIE:::get_clado_rate( + created <- get_clado_rate( lac = ps_clado_rate, hyper_pars = hyper_pars, num_spec = n_species, @@ -19,9 +19,9 @@ test_that("use area constant diversity-dependent", { ps_clado_rate <- 0.2 carr_cap <- 9 n_species <- 4 - hyper_pars <- DAISIE:::create_hyper_pars(d = 0, x = 0) + hyper_pars <- create_hyper_pars(d = 0, x = 0) area <- 1 - created <- DAISIE:::get_clado_rate( + created <- get_clado_rate( lac = ps_clado_rate, hyper_pars = hyper_pars, num_spec = n_species, @@ -36,9 +36,9 @@ test_that("use area variable diversity-independent", { ps_clado_rate <- 0.2 carr_cap <- Inf n_species <- 4 - hyper_pars <- DAISIE:::create_hyper_pars(d = 0.2, x = 0.1) + hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) area <- 10 - created <- DAISIE:::get_clado_rate( + created <- get_clado_rate( lac = ps_clado_rate, hyper_pars = hyper_pars, num_spec = n_species, @@ -53,9 +53,9 @@ test_that("use area variable diversity-dependent", { ps_clado_rate <- 0.2 carr_cap <- 9 n_species <- 4 - hyper_pars <- DAISIE:::create_hyper_pars(d = 0.2, x = 0.1) + hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) area <- 10 - created <- DAISIE:::get_clado_rate( + created <- get_clado_rate( lac = ps_clado_rate, hyper_pars = hyper_pars, num_spec = n_species, diff --git a/tests/testthat/test-get_ext_rate.R b/tests/testthat/test-get_ext_rate.R index 78acb145..66ed0042 100644 --- a/tests/testthat/test-get_ext_rate.R +++ b/tests/testthat/test-get_ext_rate.R @@ -1,9 +1,9 @@ test_that("use area constant", { ps_ext_rate <- 2 n_species <- 4 - hyper_pars = DAISIE:::create_hyper_pars(d = 0, x = 0) + hyper_pars = create_hyper_pars(d = 0, x = 0) area <- 1 - created <- DAISIE:::get_ext_rate( + created <- get_ext_rate( mu = ps_ext_rate, hyper_pars = hyper_pars, extcutoff = 1000, @@ -17,9 +17,9 @@ test_that("use area constant", { test_that("use area variable", { ps_ext_rate <- 2 n_species <- 4 - hyper_pars = DAISIE:::create_hyper_pars(d = 0.2, x = 0.1) + hyper_pars = create_hyper_pars(d = 0.2, x = 0.1) area <- 10 - created <- DAISIE:::get_ext_rate( + created <- get_ext_rate( mu = ps_ext_rate, hyper_pars = hyper_pars, extcutoff = 1000, diff --git a/tests/testthat/test-get_immig_rate.R b/tests/testthat/test-get_immig_rate.R index e3fac823..51fbeda3 100644 --- a/tests/testthat/test-get_immig_rate.R +++ b/tests/testthat/test-get_immig_rate.R @@ -3,9 +3,9 @@ test_that("use area constant diversity-independent", { ps_imm_rate <- 0.1 n_island_species <- 5 n_mainland_species <- 1 - hyper_pars <- DAISIE:::create_hyper_pars(0, 0) + hyper_pars <- create_hyper_pars(0, 0) area <- 1 - created <- DAISIE:::get_immig_rate( + created <- get_immig_rate( gam = ps_imm_rate, A = area, num_spec = n_island_species, @@ -22,9 +22,9 @@ test_that("use area constant diversity-dependent", { ps_imm_rate <- 0.1 n_island_species <- 5 n_mainland_species <- 1 - hyper_pars <- DAISIE:::create_hyper_pars(0, 0) + hyper_pars <- create_hyper_pars(0, 0) area <- 1 - created <- DAISIE:::get_immig_rate( + created <- get_immig_rate( gam = ps_imm_rate, A = area, num_spec = n_island_species, @@ -41,9 +41,9 @@ test_that("use area variable (ontogeny) diversity-dependent", { ps_imm_rate <- 0.1 n_island_species <- 5 n_mainland_species <- 1 - hyper_pars <- DAISIE:::create_hyper_pars(0, 0) + hyper_pars <- create_hyper_pars(0, 0) area <- 10 - created <- DAISIE:::get_immig_rate( + created <- get_immig_rate( gam = ps_imm_rate, A = area, num_spec = n_island_species, diff --git a/tests/testthat/test-integration_DAISIE.R b/tests/testthat/test-integration_DAISIE.R index c6923be8..70eac94b 100644 --- a/tests/testthat/test-integration_DAISIE.R +++ b/tests/testthat/test-integration_DAISIE.R @@ -73,7 +73,7 @@ test_that("IW and CS loglik is same when K = Inf", { Galapagos_datalist_IW[[i]]$stac <- 2 } - Galapagos_datalist_IW <- DAISIE:::add_brt_table(Galapagos_datalist_IW) + Galapagos_datalist_IW <- add_brt_table(Galapagos_datalist_IW) loglik_IW <- DAISIE_loglik_IW( pars1 = pars1, pars2 = pars2, diff --git a/tests/testthat/test-is_simulation_outputs.R b/tests/testthat/test-is_simulation_outputs.R index 35d780af..79177c02 100644 --- a/tests/testthat/test-is_simulation_outputs.R +++ b/tests/testthat/test-is_simulation_outputs.R @@ -8,7 +8,7 @@ test_that("use", { plot_sims = FALSE, verbose = FALSE))) - expect_true(is_simulation_outputs(DAISIE::DAISIE_sim_time_dep( + expect_true(is_simulation_outputs(DAISIE_sim_time_dep( time = 2, M = 500, pars = c(0.00001, 1, 0.05, 0.001, 1), diff --git a/tests/testthat/test-island_area.R b/tests/testthat/test-island_area.R index c5d287c6..9d02ee77 100644 --- a/tests/testthat/test-island_area.R +++ b/tests/testthat/test-island_area.R @@ -25,7 +25,7 @@ test_that("is valid island area with ontogeny", { sea_level_frequency = 0, island_gradient_angle = 0 ) - peak <- DAISIE:::calc_peak(total_time = 4, area_pars = area_pars) + peak <- calc_peak(total_time = 4, area_pars = area_pars) area <- island_area(timeval = 2, total_time = 4, @@ -64,7 +64,7 @@ test_that("is valid island area with ontogeny and sea level", { sea_level_frequency = 10, island_gradient_angle = 85 ) - peak <- DAISIE:::calc_peak(total_time = 4, area_pars = area_pars) + peak <- calc_peak(total_time = 4, area_pars = area_pars) area <- island_area(timeval = 2, total_time = 4, area_pars = area_pars, diff --git a/tests/testthat/test-printing.R b/tests/testthat/test-printing.R new file mode 100644 index 00000000..30fac8de --- /dev/null +++ b/tests/testthat/test-printing.R @@ -0,0 +1,89 @@ +test_that("print_parameters_and_loglik works", { + expect_message( + print_parameters_and_loglik( + pars = c(1, 2:6), + loglik = -3, + verbose = 3, + type = 'clade_loglik' + ), + regexp = "Status of colonist: 1, Parameters: 2.000000, 3.000000, 4.000000, 5.000000, 6.000000, Loglikelihood: -3.000000") + expect_message(print_parameters_and_loglik(pars = c(2:6), loglik = -3, verbose = 3, type = 'island_loglik')) + + expect_message(print_parameters_and_loglik(pars = c(2:6), loglik = -3, verbose = 3, type = 'island_ML')) + expect_message(print_parameters_and_loglik(pars = c(1:11), loglik = -3, verbose = 3, type = 'global_ML', distance_dep = 'power')) + expect_message(print_parameters_and_loglik(pars = c(1:11), loglik = -3, verbose = 3, type = 'global_ML', distance_dep = 'sigmoidal_col')) + expect_message(print_parameters_and_loglik(pars = data.frame(rbind(c(2:6),c(12:16))), loglik = -3, verbose = 3, type = 'multiple_island_ML')) + + expect_silent(print_parameters_and_loglik(pars = data.frame(rbind(c(2:6),c(12:16))), loglik = -3, verbose = 1, type = 'multiple_island_ML')) + expect_silent(print_parameters_and_loglik(pars = data.frame(rbind(c(2:6),c(12:16))), loglik = -3, verbose = 0, type = 'multiple_island_ML')) +}) + +test_that("print_ml_par_settings works", { + + expect_message( + print_ml_par_settings( + namepars = letters[1:5], + idparsopt = 1:5, + idparsfix = NULL, + idparsnoshift = 1:5, + all_no_shift = 1:5, + verbose = 1 + ), + regexp = "You are optimizing: a b c d e +You are fixing: nothing") + + expect_message( + print_ml_par_settings( + namepars = letters[1:5], + idparsopt = 1:4, + idparsfix = 5, + idparsnoshift = 1:5, + all_no_shift = 1:5, + verbose = 1 + ), + regexp = "You are optimizing: a b c d +You are fixing: e") + + expect_message( + print_ml_par_settings( + namepars = letters[1:5], + idparsopt = 1:5, + idparsfix = NULL, + idparsnoshift = 1:4, + all_no_shift = 1:4, + verbose = 1 + ), + regexp = "You are optimizing: a b c d e +You are fixing: nothing +You are not shifting: a b c d") + + expect_silent( + print_ml_par_settings( + namepars = letters[1:5], + idparsopt = 1:5, + idparsfix = NULL, + idparsnoshift = 1:4, + all_no_shift = 1:4, + verbose = 0 + ) + ) + +}) + +test_that("print_init_ll works", { + expect_message( + print_init_ll( + initloglik = 10, + verbose = 1 + ), + regexp = "Calculating the likelihood for the initial parameters. +The loglikelihood for the initial parameter values is 10 +Optimizing the likelihood - this may take a while.") + + expect_silent( + print_init_ll( + initloglik = 10, + verbose = 0 + ) + ) +}) diff --git a/tests/testthat/test-time_dep_vs_cr.R b/tests/testthat/test-time_dep_vs_cr.R index adc6f213..8751739f 100644 --- a/tests/testthat/test-time_dep_vs_cr.R +++ b/tests/testthat/test-time_dep_vs_cr.R @@ -16,7 +16,7 @@ test_that("constant rate output matches time dependent code", { imm_rate <- 1.0 ana_rate <- 1.0 pars <- c(clado_rate, ext_rate, carr_cap, imm_rate, ana_rate) - area_pars <- DAISIE::create_area_pars( + area_pars <- create_area_pars( max_area = 1, current_area = 1, proportional_peak_t = 0, @@ -25,11 +25,11 @@ test_that("constant rate output matches time dependent code", { sea_level_frequency = 0, island_gradient_angle = 0 ) - hyper_pars <- DAISIE::create_hyper_pars(d = 0, x = 0) + hyper_pars <- create_hyper_pars(d = 0, x = 0) nonoceanic_pars <- c(0, 0) rng_seed <- 42 set.seed(rng_seed) - cr_out <- DAISIE:::DAISIE_sim_cr( + cr_out <- DAISIE_sim_cr( time = sim_time, M = n_mainland_species, pars = pars, @@ -43,9 +43,9 @@ test_that("constant rate output matches time dependent code", { # Ontogeny code running constant case ----------------------------------- # We must use the core function to avoid calling calc_peak with a constant # area. - hyper_pars <- DAISIE::create_hyper_pars(d = 0, x = 0) + hyper_pars <- create_hyper_pars(d = 0, x = 0) set.seed(rng_seed) - time_dep_out <- DAISIE:::DAISIE_sim_core_time_dep( + time_dep_out <- DAISIE_sim_core_time_dep( time = sim_time, mainland_n = n_mainland_species, pars = c(clado_rate, ext_rate, carr_cap, imm_rate, ana_rate), diff --git a/tests/testthat/test-update_max_rates.R b/tests/testthat/test-update_max_rates.R index d319131c..6f33bb53 100644 --- a/tests/testthat/test-update_max_rates.R +++ b/tests/testthat/test-update_max_rates.R @@ -23,12 +23,12 @@ test_that("update_max_rates constant rates is silent and gives correct output", num_immigrants <- 0 mainland_n <- 1 peak <- 1 - Amin <- DAISIE:::get_global_min_area(total_time = total_time, + Amin <- get_global_min_area(total_time = total_time, area_pars = area_pars, peak = peak, island_ontogeny = island_ontogeny, sea_level = sea_level) - Amax <- DAISIE:::get_global_max_area(total_time = total_time, + Amax <- get_global_max_area(total_time = total_time, area_pars = area_pars, peak = peak, island_ontogeny = island_ontogeny, @@ -70,7 +70,7 @@ test_that("update area-dependent max rates is silent and gives correct output", island_gradient_angle = 0 ) hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) - peak <- DAISIE:::calc_peak(total_time = 0.7, area_pars = area_pars) + peak <- calc_peak(total_time = 0.7, area_pars = area_pars) Amin <- get_global_min_area(total_time = 0.7, area_pars = area_pars, peak = peak, @@ -82,7 +82,7 @@ test_that("update area-dependent max rates is silent and gives correct output", island_ontogeny = 1, sea_level = 0) - expect_silent(rates <- DAISIE:::update_max_rates( + expect_silent(rates <- update_max_rates( gam = 0.009, laa = 1.0, lac = 2.5, diff --git a/tests/testthat/test-update_rates.R b/tests/testthat/test-update_rates.R index 502c243a..4a0479b4 100644 --- a/tests/testthat/test-update_rates.R +++ b/tests/testthat/test-update_rates.R @@ -63,7 +63,7 @@ test_that("update area-dependent rates is silent and gives correct output", { island_gradient_angle = 0) hyper_pars <- create_hyper_pars(d = 0.2, x = 0.1) peak <- calc_peak(total_time = 1, area_pars = area_pars) - expect_silent(rates <- DAISIE:::update_rates( + expect_silent(rates <- update_rates( timeval = 0, total_time = 1, gam = gam, diff --git a/tests/testthat/test_printing.R b/tests/testthat/test_printing.R deleted file mode 100644 index 4d331126..00000000 --- a/tests/testthat/test_printing.R +++ /dev/null @@ -1,8 +0,0 @@ -test_that("printing is done", { - print_parameters_and_loglik(pars = c(1,2:6), loglik = -3, verbose = T, type = 'clade_loglik') - print_parameters_and_loglik(pars = c(2:6), loglik = -3, verbose = T, type = 'island_loglik') - print_parameters_and_loglik(pars = c(2:6), loglik = -3, verbose = T, type = 'island_ML') - print_parameters_and_loglik(pars = c(1:11), loglik = -3, verbose = T, type = 'global_ML', distance_dep = 'power') - print_parameters_and_loglik(pars = c(1:11), loglik = -3, verbose = T, type = 'global_ML', distance_dep = 'sigmoidal_col') - print_parameters_and_loglik(pars = data.frame(rbind(c(2:6),c(12:16))), loglik = -3, verbose = T, type = 'multiple_island_ML') -})