aboutsummaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2020-05-14 18:39:29 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2020-05-14 18:39:29 +0200
commit808a679efb69ec6603db6642687d9e8ceb3b3453 (patch)
tree17763b0c5a490078ff77bafb2d680e42c1d5709b /R
parentb6e278759127dab5bb78bc3016926a66e8a9758f (diff)
Add a parms method for mmkin objects
Diffstat (limited to 'R')
-rw-r--r--R/parms.mkinfit.R34
1 files changed, 32 insertions, 2 deletions
diff --git a/R/parms.mkinfit.R b/R/parms.mkinfit.R
index 281d06de..f173ef51 100644
--- a/R/parms.mkinfit.R
+++ b/R/parms.mkinfit.R
@@ -4,9 +4,13 @@
#' model parameters, in order to avoid working with a fitted model without
#' considering the error structure that was assumed for the fit.
#'
-#' @param object A fitted model object
+#' @param object A fitted model object. Methods are implemented for
+#' [mkinfit()] objects and for [mmkin()] objects.
#' @param \dots Not used
-#' @return A numeric vector of fitted model parameters
+#' @return For mkinfit objects, a numeric vector of fitted model parameters.
+#' For mmkin row objects, a matrix with the parameters with a
+#' row for each dataset. If the mmkin object has more than one row, a list of
+#' such matrices is returned.
#' @export
parms <- function(object, ...)
{
@@ -26,3 +30,29 @@ parms.mkinfit <- function(object, transformed = FALSE, ...)
if (transformed) object$par
else c(object$bparms.optim, object$errparms)
}
+
+#' @rdname parms
+#' @examples
+#' ds <- lapply(experimental_data_for_UBA_2019[6:10],
+#' function(x) subset(x$data[c("name", "time", "value")]))
+#' names(ds) <- paste("Dataset", 6:10)
+#' fits <- mmkin(c("SFO", "FOMC", "DFOP"), ds, quiet = TRUE)
+#' parms(fits["SFO", ])
+#' parms(fits[, 2])
+#' parms(fits)
+#' parms(fits, transformed = TRUE)
+#' @export
+parms.mmkin <- function(object, transformed = FALSE, ...)
+{
+ if (nrow(object) == 1) {
+ res <- sapply(object, parms, transformed = transformed, ...)
+ colnames(res) <- colnames(object)
+ } else {
+ res <- list()
+ for (i in 1:nrow(object)) {
+ res[[i]] <- parms(object[i, ], transformed = transformed, ...)
+ }
+ names(res) <- rownames(object)
+ }
+ return(res)
+}

Contact - Imprint