aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2020-04-14 11:45:49 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2020-04-14 11:58:35 +0200
commitd4a49b4837de347d34b2c198de7342c34b0fab63 (patch)
treedf63250c72d94221a0560a8480cda45e309aa88e
parent28914451ac0ccc5bade64d9a79b7897cc701360a (diff)
Keep order of datasets in nlme_data, add a plot
-rw-r--r--DESCRIPTION2
-rw-r--r--R/nlme.R11
-rw-r--r--docs/reference/nlme-1.pngbin0 -> 70555 bytes
-rw-r--r--docs/reference/nlme.html36
-rw-r--r--man/nlme.Rd8
5 files changed, 51 insertions, 6 deletions
diff --git a/DESCRIPTION b/DESCRIPTION
index 2a4047aa..722e6ff1 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -2,7 +2,7 @@ Package: mkin
Type: Package
Title: Kinetic Evaluation of Chemical Degradation Data
Version: 0.9.49.10
-Date: 2020-04-10
+Date: 2020-04-14
Authors@R: c(person("Johannes", "Ranke", role = c("aut", "cre", "cph"),
email = "jranke@uni-bremen.de",
comment = c(ORCID = "0000-0003-4371-6538")),
diff --git a/R/nlme.R b/R/nlme.R
index 79e4e9c1..12a3104c 100644
--- a/R/nlme.R
+++ b/R/nlme.R
@@ -33,6 +33,11 @@
#' mean_dp <- mean_degparms(f)
#' grouped_data <- nlme_data(f)
#' nlme_f <- nlme_function(f)
+#' # These assignments are necessary for these objects to be
+#' # visible to nlme and augPred when evaluation is done by
+#' # pkgdown to generated the html docs.
+#' assign("nlme_f", nlme_f, globalenv())
+#' assign("grouped_data", grouped_data, globalenv())
#'
#' library(nlme)
#' m_nlme <- nlme(value ~ nlme_f(name, time, parent_0, log_k_parent_sink),
@@ -41,6 +46,7 @@
#' random = pdDiag(parent_0 + log_k_parent_sink ~ 1),
#' start = mean_dp)
#' summary(m_nlme)
+#' plot(augPred(m_nlme, level = 0:1), layout = c(3, 1))
#'
#' \dontrun{
#' # Test on some real data
@@ -111,7 +117,7 @@
#'
#' anova(f_nlme_fomc_sfo, f_nlme_sfo_sfo)
#' }
-#' @return A function that can be used with \code{link{nlme}}
+#' @return A function that can be used with nlme
#' @export
nlme_function <- function(object) {
if (nrow(object) > 1) stop("Only row objects allowed")
@@ -204,9 +210,10 @@ nlme_data <- function(object) {
names(ds_list) <- ds_names
ds_nlme <- purrr::map_dfr(ds_list, function(x) x, .id = "ds")
ds_nlme$variable <- as.character(ds_nlme$variable)
+ ds_nlme$ds <- ordered(ds_nlme$ds, levels = unique(ds_nlme$ds))
ds_nlme_renamed <- data.frame(ds = ds_nlme$ds, name = ds_nlme$variable,
time = ds_nlme$time, value = ds_nlme$observed,
stringsAsFactors = FALSE)
- ds_nlme_grouped <- groupedData(value ~ time | ds, ds_nlme_renamed)
+ ds_nlme_grouped <- groupedData(value ~ time | ds, ds_nlme_renamed, order.groups = FALSE)
return(ds_nlme_grouped)
}
diff --git a/docs/reference/nlme-1.png b/docs/reference/nlme-1.png
new file mode 100644
index 00000000..68ccb43f
--- /dev/null
+++ b/docs/reference/nlme-1.png
Binary files differ
diff --git a/docs/reference/nlme.html b/docs/reference/nlme.html
index 696916a0..1b05f882 100644
--- a/docs/reference/nlme.html
+++ b/docs/reference/nlme.html
@@ -159,7 +159,7 @@ datasets.</p>
<h2 class="hasAnchor" id="value"><a class="anchor" href="#value"></a>Value</h2>
- <p>A function that can be used with <code>link{nlme}</code></p>
+ <p>A function that can be used with nlme</p>
<p>A named vector containing mean values of the fitted degradation model parameters</p>
<p>A <code><a href='https://rdrr.io/pkg/nlme/man/groupedData.html'>groupedData</a></code> object</p>
@@ -188,13 +188,45 @@ datasets.</p>
<span class='no'>mean_dp</span> <span class='kw'>&lt;-</span> <span class='fu'>mean_degparms</span>(<span class='no'>f</span>)
<span class='no'>grouped_data</span> <span class='kw'>&lt;-</span> <span class='fu'>nlme_data</span>(<span class='no'>f</span>)
<span class='no'>nlme_f</span> <span class='kw'>&lt;-</span> <span class='fu'>nlme_function</span>(<span class='no'>f</span>)
+<span class='co'># These assignments are necessary for these objects to be</span>
+<span class='co'># visible to nlme and augPred when evaluation is done by</span>
+<span class='co'># pkgdown to generated the html docs.</span>
+<span class='fu'><a href='https://rdrr.io/r/base/assign.html'>assign</a></span>(<span class='st'>"nlme_f"</span>, <span class='no'>nlme_f</span>, <span class='fu'><a href='https://rdrr.io/r/base/environment.html'>globalenv</a></span>())
+<span class='fu'><a href='https://rdrr.io/r/base/assign.html'>assign</a></span>(<span class='st'>"grouped_data"</span>, <span class='no'>grouped_data</span>, <span class='fu'><a href='https://rdrr.io/r/base/environment.html'>globalenv</a></span>())
<span class='fu'><a href='https://rdrr.io/r/base/library.html'>library</a></span>(<span class='no'>nlme</span>)
<span class='no'>m_nlme</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlme/man/nlme.html'>nlme</a></span>(<span class='no'>value</span> ~ <span class='fu'>nlme_f</span>(<span class='no'>name</span>, <span class='no'>time</span>, <span class='no'>parent_0</span>, <span class='no'>log_k_parent_sink</span>),
<span class='kw'>data</span> <span class='kw'>=</span> <span class='no'>grouped_data</span>,
<span class='kw'>fixed</span> <span class='kw'>=</span> <span class='no'>parent_0</span> + <span class='no'>log_k_parent_sink</span> ~ <span class='fl'>1</span>,
<span class='kw'>random</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/pkg/nlme/man/pdDiag.html'>pdDiag</a></span>(<span class='no'>parent_0</span> + <span class='no'>log_k_parent_sink</span> ~ <span class='fl'>1</span>),
- <span class='kw'>start</span> <span class='kw'>=</span> <span class='no'>mean_dp</span>)</div><div class='output co'>#&gt; <span class='error'>Error in nlme_f(name, time, parent_0, log_k_parent_sink): konnte Funktion "nlme_f" nicht finden</span></div><div class='input'><span class='fu'><a href='https://rdrr.io/r/base/summary.html'>summary</a></span>(<span class='no'>m_nlme</span>)</div><div class='output co'>#&gt; <span class='error'>Error in summary(m_nlme): Objekt 'm_nlme' nicht gefunden</span></div><div class='input'>
+ <span class='kw'>start</span> <span class='kw'>=</span> <span class='no'>mean_dp</span>)
+<span class='fu'><a href='https://rdrr.io/r/base/summary.html'>summary</a></span>(<span class='no'>m_nlme</span>)</div><div class='output co'>#&gt; Nonlinear mixed-effects model fit by maximum likelihood
+#&gt; Model: value ~ nlme_f(name, time, parent_0, log_k_parent_sink)
+#&gt; Data: grouped_data
+#&gt; AIC BIC logLik
+#&gt; 298.2781 307.7372 -144.1391
+#&gt;
+#&gt; Random effects:
+#&gt; Formula: list(parent_0 ~ 1, log_k_parent_sink ~ 1)
+#&gt; Level: ds
+#&gt; Structure: Diagonal
+#&gt; parent_0 log_k_parent_sink Residual
+#&gt; StdDev: 0.9374733 0.7098105 3.83543
+#&gt;
+#&gt; Fixed effects: parent_0 + log_k_parent_sink ~ 1
+#&gt; Value Std.Error DF t-value p-value
+#&gt; parent_0 101.76838 1.1445444 45 88.91606 0
+#&gt; log_k_parent_sink -3.05444 0.4195622 45 -7.28008 0
+#&gt; Correlation:
+#&gt; prnt_0
+#&gt; log_k_parent_sink 0.034
+#&gt;
+#&gt; Standardized Within-Group Residuals:
+#&gt; Min Q1 Med Q3 Max
+#&gt; -2.6169360 -0.2185329 0.0574070 0.5720937 3.0459868
+#&gt;
+#&gt; Number of Observations: 49
+#&gt; Number of Groups: 3 </div><div class='input'><span class='fu'><a href='https://rdrr.io/r/graphics/plot.html'>plot</a></span>(<span class='fu'><a href='https://rdrr.io/pkg/nlme/man/augPred.html'>augPred</a></span>(<span class='no'>m_nlme</span>, <span class='kw'>level</span> <span class='kw'>=</span> <span class='fl'>0</span>:<span class='fl'>1</span>), <span class='kw'>layout</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='fl'>3</span>, <span class='fl'>1</span>))</div><div class='img'><img src='nlme-1.png' alt='' width='700' height='433' /></div><div class='input'>
<span class='co'># \dontrun{</span>
<span class='co'># Test on some real data</span>
<span class='no'>ds_2</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>],
diff --git a/man/nlme.Rd b/man/nlme.Rd
index 7527f09d..8e5c2aa0 100644
--- a/man/nlme.Rd
+++ b/man/nlme.Rd
@@ -16,7 +16,7 @@ nlme_data(object)
\item{object}{An mmkin row object containing several fits of the same model to different datasets}
}
\value{
-A function that can be used with \code{link{nlme}}
+A function that can be used with nlme
A named vector containing mean values of the fitted degradation model parameters
@@ -53,6 +53,11 @@ f <- mmkin("SFO", ds, cores = 1, quiet = TRUE)
mean_dp <- mean_degparms(f)
grouped_data <- nlme_data(f)
nlme_f <- nlme_function(f)
+# These assignments are necessary for these objects to be
+# visible to nlme and augPred when evaluation is done by
+# pkgdown to generated the html docs.
+assign("nlme_f", nlme_f, globalenv())
+assign("grouped_data", grouped_data, globalenv())
library(nlme)
m_nlme <- nlme(value ~ nlme_f(name, time, parent_0, log_k_parent_sink),
@@ -61,6 +66,7 @@ m_nlme <- nlme(value ~ nlme_f(name, time, parent_0, log_k_parent_sink),
random = pdDiag(parent_0 + log_k_parent_sink ~ 1),
start = mean_dp)
summary(m_nlme)
+plot(augPred(m_nlme, level = 0:1), layout = c(3, 1))
\dontrun{
# Test on some real data

Contact - Imprint