From b5c2d9b4b6d02834eec0625bab2318102114cde0 Mon Sep 17 00:00:00 2001 From: rsetienne Date: Wed, 23 Oct 2024 17:39:55 +0200 Subject: [PATCH] Allowing for adding approximate loglikelihood function --- R/DAISIE_ML1.R | 8 +++++++- R/DAISIE_ML_CS.R | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/R/DAISIE_ML1.R b/R/DAISIE_ML1.R index 3bc01e1c..4f602942 100644 --- a/R/DAISIE_ML1.R +++ b/R/DAISIE_ML1.R @@ -108,7 +108,7 @@ DAISIE_ML1 <- function( island_ontogeny = NA, jitter = 0, num_cycles = 1, - function_to_optimize = DAISIE_loglik_all_choosepar) { + function_to_optimize = 'DAISIE_exact') { # datalist = list of all data: branching times, status of clade, and numnber of missing species # datalist[[,]][1] = list of branching times (positive, from present to past) # - max(brts) = age of the island @@ -157,6 +157,12 @@ DAISIE_ML1 <- function( # . eqmodel = 4 : equilibrium is assumed on immigrants using deterministic equation for endemics and immigrants # . eqmodel = 5 : equilibrium is assumed on endemics and immigrants using deterministic equation for endemics and immigrants + if(function_to_optimize == 'DAISIE_exact') { + function_to_optimize <- DAISIE_loglik_all_choosepar + } else + { + DAISIE_loglik_all_choosepar_approx + } out2err <- data.frame( lambda_c = NA, diff --git a/R/DAISIE_ML_CS.R b/R/DAISIE_ML_CS.R index 18b40c7c..58dfa9a8 100644 --- a/R/DAISIE_ML_CS.R +++ b/R/DAISIE_ML_CS.R @@ -183,7 +183,8 @@ DAISIE_ML_CS <- DAISIE_ML <- function( verbose = 0, tolint = c(1E-16, 1E-10), jitter = 0, - num_cycles = 1) { + num_cycles = 1, + function_to_optimize = 'DAISIE_exact') { if (datatype == "single") { if (is.na(island_ontogeny)) { @@ -229,7 +230,8 @@ DAISIE_ML_CS <- DAISIE_ML <- function( verbose = verbose, tolint = tolint, jitter = jitter, - num_cycles = num_cycles) + num_cycles = num_cycles, + function_to_optimize = function_to_optimize) } } else { stop(