From d4a49b4837de347d34b2c198de7342c34b0fab63 Mon Sep 17 00:00:00 2001
From: Johannes Ranke
Date: Tue, 14 Apr 2020 11:45:49 +0200
Subject: Keep order of datasets in nlme_data, add a plot
---
DESCRIPTION | 2 +-
R/nlme.R | 11 +++++++++--
docs/reference/nlme-1.png | Bin 0 -> 70555 bytes
docs/reference/nlme.html | 36 ++++++++++++++++++++++++++++++++++--
man/nlme.Rd | 8 +++++++-
5 files changed, 51 insertions(+), 6 deletions(-)
create mode 100644 docs/reference/nlme-1.png
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
Binary files /dev/null and b/docs/reference/nlme-1.png 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.
Value
- A function that can be used with link{nlme}
+ A function that can be used with nlme
A named vector containing mean values of the fitted degradation model parameters
A groupedData
object
@@ -188,13 +188,45 @@ datasets.
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),
data = grouped_data,
fixed = parent_0 + log_k_parent_sink ~ 1,
random = pdDiag(parent_0 + log_k_parent_sink ~ 1),
- start = mean_dp)#> Error in nlme_f(name, time, parent_0, log_k_parent_sink): konnte Funktion "nlme_f" nicht finden
#> Error in summary(m_nlme): Objekt 'm_nlme' nicht gefunden
#> Nonlinear mixed-effects model fit by maximum likelihood
+#> Model: value ~ nlme_f(name, time, parent_0, log_k_parent_sink)
+#> Data: grouped_data
+#> AIC BIC logLik
+#> 298.2781 307.7372 -144.1391
+#>
+#> Random effects:
+#> Formula: list(parent_0 ~ 1, log_k_parent_sink ~ 1)
+#> Level: ds
+#> Structure: Diagonal
+#> parent_0 log_k_parent_sink Residual
+#> StdDev: 0.9374733 0.7098105 3.83543
+#>
+#> Fixed effects: parent_0 + log_k_parent_sink ~ 1
+#> Value Std.Error DF t-value p-value
+#> parent_0 101.76838 1.1445444 45 88.91606 0
+#> log_k_parent_sink -3.05444 0.4195622 45 -7.28008 0
+#> Correlation:
+#> prnt_0
+#> log_k_parent_sink 0.034
+#>
+#> Standardized Within-Group Residuals:
+#> Min Q1 Med Q3 Max
+#> -2.6169360 -0.2185329 0.0574070 0.5720937 3.0459868
+#>
+#> Number of Observations: 49
+#> Number of Groups: 3