aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NAMESPACE1
-rw-r--r--NEWS.md4
-rw-r--r--R/parms.mkinfit.R34
-rw-r--r--docs/news/index.html8
-rw-r--r--docs/pkgdown.yml2
-rw-r--r--docs/reference/parms.html83
-rw-r--r--man/parms.Rd19
7 files changed, 143 insertions, 8 deletions
diff --git a/NAMESPACE b/NAMESPACE
index ef1ddca5..72a60dea 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -16,6 +16,7 @@ S3method(mkinpredict,mkinmod)
S3method(nlme,mmkin)
S3method(nobs,mkinfit)
S3method(parms,mkinfit)
+S3method(parms,mmkin)
S3method(plot,mkinfit)
S3method(plot,mmkin)
S3method(plot,nafta)
diff --git a/NEWS.md b/NEWS.md
index 3867320e..37cb5072 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,7 @@
+# mkin 0.9.50.3 (unreleased)
+
+- 'parms': Add a method for mmkin objects
+
# mkin 0.9.50.2 (2020-05-12)
- Increase tolerance for a platform specific test results on the Solaris test machine on CRAN
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)
+}
diff --git a/docs/news/index.html b/docs/news/index.html
index 20f532ab..c3713a94 100644
--- a/docs/news/index.html
+++ b/docs/news/index.html
@@ -141,6 +141,14 @@
<small>Source: <a href='http://github.com/jranke/mkin/blob/master/NEWS.md'><code>NEWS.md</code></a></small>
</div>
+ <div id="mkin-0-9-50-3-unreleased" class="section level1">
+<h1 class="page-header" data-toc-text="0.9.50.3">
+<a href="#mkin-0-9-50-3-unreleased" class="anchor"></a>mkin 0.9.50.3 (unreleased)<small> Unreleased </small>
+</h1>
+<ul>
+<li>‘parms’: Add a method for mmkin objects</li>
+</ul>
+</div>
<div id="mkin-0-9-50-2-2020-05-12" class="section level1">
<h1 class="page-header" data-toc-text="0.9.50.2">
<a href="#mkin-0-9-50-2-2020-05-12" class="anchor"></a>mkin 0.9.50.2 (2020-05-12)<small> 2020-05-12 </small>
diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml
index eb3f0f6e..77d13196 100644
--- a/docs/pkgdown.yml
+++ b/docs/pkgdown.yml
@@ -10,7 +10,7 @@ articles:
NAFTA_examples: web_only/NAFTA_examples.html
benchmarks: web_only/benchmarks.html
compiled_models: web_only/compiled_models.html
-last_built: 2020-05-14T15:07Z
+last_built: 2020-05-14T16:37Z
urls:
reference: https://pkgdown.jrwb.de/mkin/reference
article: https://pkgdown.jrwb.de/mkin/articles
diff --git a/docs/reference/parms.html b/docs/reference/parms.html
index f62b3898..cb705d2c 100644
--- a/docs/reference/parms.html
+++ b/docs/reference/parms.html
@@ -111,6 +111,9 @@ considering the error structure that was assumed for the fit." />
<li>
<a href="../articles/web_only/NAFTA_examples.html">Example evaluation of NAFTA SOP Attachment examples</a>
</li>
+ <li>
+ <a href="../articles/web_only/benchmarks.html">Some benchmark timings</a>
+ </li>
</ul>
</li>
<li>
@@ -151,6 +154,9 @@ considering the error structure that was assumed for the fit.</p>
<pre class="usage"><span class='fu'>parms</span>(<span class='no'>object</span>, <span class='no'>...</span>)
<span class='co'># S3 method for mkinfit</span>
+<span class='fu'>parms</span>(<span class='no'>object</span>, <span class='kw'>transformed</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>, <span class='no'>...</span>)
+
+<span class='co'># S3 method for mmkin</span>
<span class='fu'>parms</span>(<span class='no'>object</span>, <span class='kw'>transformed</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>, <span class='no'>...</span>)</pre>
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
@@ -158,7 +164,8 @@ considering the error structure that was assumed for the fit.</p>
<colgroup><col class="name" /><col class="desc" /></colgroup>
<tr>
<th>object</th>
- <td><p>A fitted model object</p></td>
+ <td><p>A fitted model object. Methods are implemented for
+<code><a href='mkinfit.html'>mkinfit()</a></code> objects and for <code><a href='mmkin.html'>mmkin()</a></code> objects.</p></td>
</tr>
<tr>
<th>...</th>
@@ -173,7 +180,10 @@ as used internally during the optimisation?</p></td>
<h2 class="hasAnchor" id="value"><a class="anchor" href="#value"></a>Value</h2>
- <p>A numeric vector of fitted model parameters</p>
+ <p>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.</p>
<h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
<pre class="examples"><div class='input'><span class='no'>fit</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='mkinfit.html'>mkinfit</a></span>(<span class='st'>"SFO"</span>, <span class='no'>FOCUS_2006_C</span>)</div><div class='output co'>#&gt; <span class='message'>Ordinary least squares optimisation</span></div><div class='output co'>#&gt; Sum of squared residuals at call 1: 2388.077
@@ -190,7 +200,74 @@ as used internally during the optimisation?</p></td>
#&gt; Sum of squared residuals at call 25: 196.5334
#&gt; Negative log-likelihood at call 31: 26.64668</div><div class='output co'>#&gt; <span class='message'>Optimisation successfully terminated.</span></div><div class='input'><span class='fu'>parms</span>(<span class='no'>fit</span>)</div><div class='output co'>#&gt; parent_0 k_parent_sink sigma
#&gt; 82.4921598 0.3060633 4.6730124 </div><div class='input'><span class='fu'>parms</span>(<span class='no'>fit</span>, <span class='kw'>transformed</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>)</div><div class='output co'>#&gt; parent_0 log_k_parent_sink sigma
-#&gt; 82.492160 -1.183963 4.673012 </div></pre>
+#&gt; 82.492160 -1.183963 4.673012 </div><div class='input'><span class='no'>ds</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/lapply.html'>lapply</a></span>(<span class='no'>experimental_data_for_UBA_2019</span>[<span class='fl'>6</span>:<span class='fl'>10</span>],
+ <span class='kw'>function</span>(<span class='no'>x</span>) <span class='fu'><a href='https://rdrr.io/r/base/subset.html'>subset</a></span>(<span class='no'>x</span>$<span class='no'>data</span>[<span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='st'>"name"</span>, <span class='st'>"time"</span>, <span class='st'>"value"</span>)]))
+<span class='fu'><a href='https://rdrr.io/r/base/names.html'>names</a></span>(<span class='no'>ds</span>) <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/paste.html'>paste</a></span>(<span class='st'>"Dataset"</span>, <span class='fl'>6</span>:<span class='fl'>10</span>)
+<span class='no'>fits</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='mmkin.html'>mmkin</a></span>(<span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='st'>"SFO"</span>, <span class='st'>"FOMC"</span>, <span class='st'>"DFOP"</span>), <span class='no'>ds</span>, <span class='kw'>quiet</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>)
+<span class='fu'>parms</span>(<span class='no'>fits</span>[<span class='st'>"SFO"</span>, ])</div><div class='output co'>#&gt; Dataset 6 Dataset 7 Dataset 8 Dataset 9 Dataset 10
+#&gt; parent_0 88.52275400 82.666781678 86.8547308 91.7779306 82.14809450
+#&gt; k_parent_sink 0.05794659 0.009647805 0.2102974 0.1232258 0.00720421
+#&gt; sigma 5.15274487 7.040168584 3.6769645 6.4669234 6.50457673</div><div class='input'><span class='fu'>parms</span>(<span class='no'>fits</span>[, <span class='fl'>2</span>])</div><div class='output co'>#&gt; $SFO
+#&gt; Dataset 7
+#&gt; parent_0 82.666781678
+#&gt; k_parent_sink 0.009647805
+#&gt; sigma 7.040168584
+#&gt;
+#&gt; $FOMC
+#&gt; Dataset 7
+#&gt; parent_0 92.6837649
+#&gt; alpha 0.4967832
+#&gt; beta 14.1451255
+#&gt; sigma 1.9167519
+#&gt;
+#&gt; $DFOP
+#&gt; Dataset 7
+#&gt; parent_0 91.058971503
+#&gt; k1 0.044946770
+#&gt; k2 0.002868336
+#&gt; g 0.526942415
+#&gt; sigma 2.221302196
+#&gt; </div><div class='input'><span class='fu'>parms</span>(<span class='no'>fits</span>)</div><div class='output co'>#&gt; $SFO
+#&gt; Dataset 6 Dataset 7 Dataset 8 Dataset 9 Dataset 10
+#&gt; parent_0 88.52275400 82.666781678 86.8547308 91.7779306 82.14809450
+#&gt; k_parent_sink 0.05794659 0.009647805 0.2102974 0.1232258 0.00720421
+#&gt; sigma 5.15274487 7.040168584 3.6769645 6.4669234 6.50457673
+#&gt;
+#&gt; $FOMC
+#&gt; Dataset 6 Dataset 7 Dataset 8 Dataset 9 Dataset 10
+#&gt; parent_0 95.558575 92.6837649 90.719787 98.383939 94.8481458
+#&gt; alpha 1.338667 0.4967832 1.639099 1.074460 0.2805272
+#&gt; beta 13.033315 14.1451255 5.007077 4.397126 6.9052224
+#&gt; sigma 1.847671 1.9167519 1.066063 3.146056 1.6222778
+#&gt;
+#&gt; $DFOP
+#&gt; Dataset 6 Dataset 7 Dataset 8 Dataset 9 Dataset 10
+#&gt; parent_0 96.55213663 91.058971503 90.34509469 98.14858850 94.311323409
+#&gt; k1 0.21954589 0.044946770 0.41232289 0.31697588 0.080663853
+#&gt; k2 0.02957934 0.002868336 0.07581767 0.03260384 0.003425417
+#&gt; g 0.44845068 0.526942415 0.66091965 0.65322767 0.342652880
+#&gt; sigma 1.35690468 2.221302196 1.34169076 2.87159846 1.942067831
+#&gt; </div><div class='input'><span class='fu'>parms</span>(<span class='no'>fits</span>, <span class='kw'>transformed</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>)</div><div class='output co'>#&gt; $SFO
+#&gt; Dataset 6 Dataset 7 Dataset 8 Dataset 9 Dataset 10
+#&gt; parent_0 88.522754 82.666782 86.854731 91.777931 82.148094
+#&gt; log_k_parent_sink -2.848234 -4.641025 -1.559232 -2.093737 -4.933090
+#&gt; sigma 5.152745 7.040169 3.676964 6.466923 6.504577
+#&gt;
+#&gt; $FOMC
+#&gt; Dataset 6 Dataset 7 Dataset 8 Dataset 9 Dataset 10
+#&gt; parent_0 95.5585751 92.6837649 90.7197870 98.38393897 94.848146
+#&gt; log_alpha 0.2916741 -0.6996015 0.4941466 0.07181816 -1.271085
+#&gt; log_beta 2.5675088 2.6493701 1.6108523 1.48095106 1.932278
+#&gt; sigma 1.8476712 1.9167519 1.0660627 3.14605557 1.622278
+#&gt;
+#&gt; $DFOP
+#&gt; Dataset 6 Dataset 7 Dataset 8 Dataset 9 Dataset 10
+#&gt; parent_0 96.5521366 91.05897150 90.3450947 98.1485885 94.311323
+#&gt; log_k1 -1.5161940 -3.10227638 -0.8859485 -1.1489296 -2.517465
+#&gt; log_k2 -3.5206791 -5.85402317 -2.5794240 -3.4233253 -5.676532
+#&gt; g_ilr -0.1463234 0.07627854 0.4719196 0.4477805 -0.460676
+#&gt; sigma 1.3569047 2.22130220 1.3416908 2.8715985 1.942068
+#&gt; </div></pre>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
<nav id="toc" data-toggle="toc" class="sticky-top">
diff --git a/man/parms.Rd b/man/parms.Rd
index 5752de0b..87e23781 100644
--- a/man/parms.Rd
+++ b/man/parms.Rd
@@ -3,14 +3,18 @@
\name{parms}
\alias{parms}
\alias{parms.mkinfit}
+\alias{parms.mmkin}
\title{Extract model parameters from mkinfit models}
\usage{
parms(object, ...)
\method{parms}{mkinfit}(object, transformed = FALSE, ...)
+
+\method{parms}{mmkin}(object, transformed = FALSE, ...)
}
\arguments{
-\item{object}{A fitted model object}
+\item{object}{A fitted model object. Methods are implemented for
+\code{\link[=mkinfit]{mkinfit()}} objects and for \code{\link[=mmkin]{mmkin()}} objects.}
\item{\dots}{Not used}
@@ -18,7 +22,10 @@ parms(object, ...)
as used internally during the optimisation?}
}
\value{
-A numeric vector of fitted model parameters
+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.
}
\description{
This function always returns degradation model parameters as well as error
@@ -29,4 +36,12 @@ considering the error structure that was assumed for the fit.
fit <- mkinfit("SFO", FOCUS_2006_C)
parms(fit)
parms(fit, transformed = TRUE)
+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)
}

Contact - Imprint