diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2022-10-20 11:55:52 +0200 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2022-10-21 11:35:37 +0200 |
commit | a4a6585639c09d0174df4e14f7dc912f2ba339f9 (patch) | |
tree | 7ccd225b43e929d2c50567e602ab02214b01d329 | |
parent | cdf3848b252e8aae311bbfbf1d2921a38d904ad1 (diff) |
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.
-rw-r--r-- | R/multistart.R | 16 |
1 files changed, 10 insertions, 6 deletions
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 |