From a4a6585639c09d0174df4e14f7dc912f2ba339f9 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 20 Oct 2022 11:55:52 +0200 Subject: Make update.saem.mmkin work with objects from multistart In particular, objects selected using best.multistart can now be updated, as the starting parameters are inserted into the call, without reference to 'start_parms' which will not be available outside the multistart method. --- R/multistart.R | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'R/multistart.R') diff --git a/R/multistart.R b/R/multistart.R index 11736670..4282de9c 100644 --- a/R/multistart.R +++ b/R/multistart.R @@ -80,14 +80,18 @@ multistart.saem.mmkin <- function(object, n = 50, cores = 1, mmkin_parms, 1, function(x) stats::runif(n, min(x), max(x))) + fit_function <- function(x) { + ret <- update(object, degparms_start = start_parms[x, ], ...) + ret$call[[4]] <- str2lang( + paste0(capture.output(dput(start_parms[x, ])), + collapse = "")) + return(ret) + } + if (is.null(cluster)) { - res <- parallel::mclapply(1:n, function (x) { - update(object, degparms_start = start_parms[x, ], ...) - }, mc.cores = cores) + res <- parallel::mclapply(1:n, fit_function, mc.cores = cores) } else { - res <- parallel::parLapply(cluster, 1:n, function(x) { - update(object, degparms_start = start_parms[x, ], ...) - }) + res <- parallel::parLapply(cluster, 1:n, fit_function) } attr(res, "orig") <- object attr(res, "start_parms") <- start_parms -- cgit v1.2.1