From 20b9c584e7c43ecbb708459e531c24a1a4751e17 Mon Sep 17 00:00:00 2001
From: Johannes Ranke
Date: Sat, 9 Nov 2019 01:05:51 +0100
Subject: Add a lack-of-fit test
- Switch an example dataset in the test setup to a dataset with
replicates, adapt tests
- Skip the test for lrtest with an update specification as it does not
only fail when pkgdown generates static help pages, but also in testthat
---
NAMESPACE | 5 +
NEWS.md | 2 +
R/loftest.R | 112 +++++++++++++
R/logLik.mkinfit.R | 11 +-
_pkgdown.yml | 1 +
docs/news/index.html | 1 +
docs/reference/index.html | 6 +
docs/reference/loftest-1.png | Bin 0 -> 27354 bytes
docs/reference/loftest-2.png | Bin 0 -> 27721 bytes
docs/reference/loftest-3.png | Bin 0 -> 65409 bytes
docs/reference/loftest-4.png | Bin 0 -> 64457 bytes
docs/reference/loftest-5.png | Bin 0 -> 63057 bytes
docs/reference/loftest.html | 343 +++++++++++++++++++++++++++++++++++++++
docs/sitemap.xml | 3 +
man/loftest.Rd | 81 +++++++++
test.log | 26 +--
tests/testthat/FOCUS_2006_D.csf | 2 +-
tests/testthat/setup_script.R | 10 +-
tests/testthat/test_confidence.R | 7 +-
tests/testthat/test_tests.R | 22 ++-
20 files changed, 605 insertions(+), 27 deletions(-)
create mode 100644 R/loftest.R
create mode 100644 docs/reference/loftest-1.png
create mode 100644 docs/reference/loftest-2.png
create mode 100644 docs/reference/loftest-3.png
create mode 100644 docs/reference/loftest-4.png
create mode 100644 docs/reference/loftest-5.png
create mode 100644 docs/reference/loftest.html
create mode 100644 man/loftest.Rd
diff --git a/NAMESPACE b/NAMESPACE
index 8ea4c684..f428a612 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -4,6 +4,7 @@ S3method("[",mmkin)
S3method(AIC,mmkin)
S3method(BIC,mmkin)
S3method(confint,mkinfit)
+S3method(loftest,mkinfit)
S3method(logLik,mkinfit)
S3method(lrtest,mkinfit)
S3method(mkinpredict,mkinfit)
@@ -32,6 +33,7 @@ export(backtransform_odeparms)
export(endpoints)
export(ilr)
export(invilr)
+export(loftest)
export(logistic.solution)
export(lrtest)
export(max_twa_dfop)
@@ -73,8 +75,11 @@ importFrom(parallel,parLapply)
importFrom(stats,AIC)
importFrom(stats,BIC)
importFrom(stats,aggregate)
+importFrom(stats,coef)
importFrom(stats,cov2cor)
importFrom(stats,dist)
+importFrom(stats,dnorm)
+importFrom(stats,lm)
importFrom(stats,logLik)
importFrom(stats,nlminb)
importFrom(stats,nobs)
diff --git a/NEWS.md b/NEWS.md
index 395cd623..965105f4 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,7 @@
# mkin 0.9.49.8 (unreleased)
+- 'loftest': Add a lack-of-fit test
+
- 'plot_res', 'plot_sep' and 'mkinerrplot': Add the possibility to show standardized residuals and make it the default for fits with error models other than 'const'
- 'lrtest.mkinfit': Improve naming of the compared fits in the case of fixed parameters
diff --git a/R/loftest.R b/R/loftest.R
new file mode 100644
index 00000000..29721e23
--- /dev/null
+++ b/R/loftest.R
@@ -0,0 +1,112 @@
+#' Lack-of-fit test for models fitted to data with replicates
+#'
+#' This is a generic function with a method currently only defined for mkinfit
+#' objects. It fits an anova model to the data contained in the object and
+#' compares the likelihoods using the likelihood ratio test
+#' \code{\link[lmtest]{lrtest.default}} from the lmtest package.
+#'
+#' The anova model is interpreted as the simplest form of an mkinfit model,
+#' assuming only a constant variance about the means, but not enforcing any
+#' structure of the means, so we have one model parameter for every mean
+#' of replicate samples.
+#'
+#' @param object A model object with a defined loftest method
+#' @param \dots Not used
+#' @export
+loftest <- function(object, ...) {
+ UseMethod("loftest")
+}
+
+#' @rdname loftest
+#' @importFrom stats logLik lm dnorm coef
+#' @seealso lrtest
+#' @examples
+#' \dontrun{
+#' test_data <- subset(synthetic_data_for_UBA_2014[[12]]$data, name == "parent")
+#' sfo_fit <- mkinfit("SFO", test_data, quiet = TRUE)
+#' plot_res(sfo_fit) # We see a clear pattern in the residuals
+#' loftest(sfo_fit) # We have a clear lack of fit
+#' #
+#' # We try a different model (the one that was used to generate the data)
+#' dfop_fit <- mkinfit("DFOP", test_data, quiet = TRUE)
+#' plot_res(dfop_fit) # We don't see systematic deviations, but heteroscedastic residuals
+#' # therefore we should consider adapting the error model, although we have
+#' loftest(dfop_fit) # no lack of fit
+#' #
+#' # This is the anova model used internally for the comparison
+#' test_data_anova <- test_data
+#' test_data_anova$time <- as.factor(test_data_anova$time)
+#' anova_fit <- lm(value ~ time, data = test_data_anova)
+#' summary(anova_fit)
+#' logLik(anova_fit) # We get the same likelihood and degrees of freedom
+#' #
+#' test_data_2 <- synthetic_data_for_UBA_2014[[12]]$data
+#' m_synth_SFO_lin <- mkinmod(parent = list(type = "SFO", to = "M1"),
+#' M1 = list(type = "SFO", to = "M2"),
+#' M2 = list(type = "SFO"), use_of_ff = "max")
+#' sfo_lin_fit <- mkinfit(m_synth_SFO_lin, test_data_2, quiet = TRUE)
+#' plot_res(sfo_lin_fit) # not a good model, we try parallel formation
+#' loftest(sfo_lin_fit)
+#' #
+#' m_synth_SFO_par <- mkinmod(parent = list(type = "SFO", to = c("M1", "M2")),
+#' M1 = list(type = "SFO"),
+#' M2 = list(type = "SFO"), use_of_ff = "max")
+#' sfo_par_fit <- mkinfit(m_synth_SFO_par, test_data_2, quiet = TRUE)
+#' plot_res(sfo_par_fit) # much better for metabolites
+#' loftest(sfo_par_fit)
+#' #
+#' m_synth_DFOP_par <- mkinmod(parent = list(type = "DFOP", to = c("M1", "M2")),
+#' M1 = list(type = "SFO"),
+#' M2 = list(type = "SFO"), use_of_ff = "max")
+#' dfop_par_fit <- mkinfit(m_synth_DFOP_par, test_data_2, quiet = TRUE)
+#' plot_res(dfop_par_fit) # No visual lack of fit
+#' loftest(dfop_par_fit) # no lack of fit found by the test
+#' #
+#' # The anova model used for comparison in the case of transformation products
+#' test_data_anova_2 <- dfop_par_fit$data
+#' test_data_anova_2$variable <- as.factor(test_data_anova_2$variable)
+#' test_data_anova_2$time <- as.factor(test_data_anova_2$time)
+#' anova_fit_2 <- lm(observed ~ time:variable - 1, data = test_data_anova_2)
+#' summary(anova_fit_2)
+#' }
+#' @export
+loftest.mkinfit <- function(object, ...) {
+
+ name_function <- function(x) {
+ object_name <- paste(x$mkinmod$name, "with error model", x$err_mod)
+ if (length(x$bparms.fixed) > 0) {
+ object_name <- paste(object_name,
+ "and fixed parameter(s)",
+ paste(names(x$bparms.fixed), collapse = ", "))
+ }
+ return(object_name)
+ }
+
+ # Check if we have replicates in the data
+ if (max(aggregate(object$data$observed,
+ by = list(object$data$variable, object$data$time), length)$x) == 1) {
+ stop("Not defined for fits to data without replicates")
+ }
+
+ data_anova <- object$data
+ data_anova$time <- as.factor(data_anova$time)
+ data_anova$variable <- as.factor(data_anova$variable)
+ if (nlevels(data_anova$variable) == 1) {
+ object_2 <- lm(observed ~ time - 1, data = data_anova)
+ } else {
+ object_2 <- lm(observed ~ variable:time - 1,
+ data = data_anova)
+ }
+
+ object_2$mkinmod <- list(name = "ANOVA")
+ object_2$err_mod <- "const"
+ sigma_mle <- sqrt(sum(residuals(object_2)^2)/nobs(object_2))
+ object_2$logLik <- sum(dnorm(x = object_2$residuals,
+ mean = 0, sd = sigma_mle, log = TRUE))
+ object_2$data <- object$data # to make the nobs.mkinfit method work
+ object_2$bparms.optim <- coef(object_2)
+ object_2$errparms <- 1 # We have estimated one error model parameter
+ class(object_2) <- "mkinfit"
+
+ lmtest::lrtest.default(object_2, object, name = name_function)
+}
diff --git a/R/logLik.mkinfit.R b/R/logLik.mkinfit.R
index cadc0d0a..1c025893 100644
--- a/R/logLik.mkinfit.R
+++ b/R/logLik.mkinfit.R
@@ -1,15 +1,15 @@
#' Calculated the log-likelihood of a fitted mkinfit object
-#'
+#'
#' This function returns the product of the likelihood densities of each
#' observed value, as calculated as part of the fitting procedure using
#' \code{\link{dnorm}}, i.e. assuming normal distribution, and with the means
#' predicted by the degradation model, and the standard deviations predicted by
#' the error model.
-#'
+#'
#' The total number of estimated parameters returned with the value of the
#' likelihood is calculated as the sum of fitted degradation model parameters
#' and the fitted error model parameters.
-#'
+#'
#' @param object An object of class \code{\link{mkinfit}}.
#' @param \dots For compatibility with the generic method
#' @return An object of class \code{\link{logLik}} with the number of estimated
@@ -19,7 +19,7 @@
#' @seealso Compare the AIC of columns of \code{\link{mmkin}} objects using
#' \code{\link{AIC.mmkin}}.
#' @examples
-#'
+#'
#' \dontrun{
#' sfo_sfo <- mkinmod(
#' parent = mkinsub("SFO", to = "m1"),
@@ -31,11 +31,12 @@
#' f_tc <- mkinfit(sfo_sfo, d_t, error_model = "tc", quiet = TRUE)
#' AIC(f_nw, f_obs, f_tc)
#' }
-#'
+#'
#' @export
logLik.mkinfit <- function(object, ...) {
val <- object$logLik
# Number of estimated parameters
attr(val, "df") <- length(object$bparms.optim) + length(object$errparms)
+ class(val) <- "logLik"
return(val)
}
diff --git a/_pkgdown.yml b/_pkgdown.yml
index c222a817..c298256f 100644
--- a/_pkgdown.yml
+++ b/_pkgdown.yml
@@ -22,6 +22,7 @@ reference:
- confint.mkinfit
- update.mkinfit
- lrtest.mkinfit
+ - loftest
- mkinerrmin
- endpoints
- CAKE_export
diff --git a/docs/news/index.html b/docs/news/index.html
index 48ba25e5..9aa2e18b 100644
--- a/docs/news/index.html
+++ b/docs/news/index.html
@@ -134,6 +134,7 @@
mkin 0.9.49.8 (unreleased) Unreleased
+
‘loftest’: Add a lack-of-fit test
‘plot_res’, ‘plot_sep’ and ‘mkinerrplot’: Add the possibility to show standardized residuals and make it the default for fits with error models other than ‘const’
‘lrtest.mkinfit’: Improve naming of the compared fits in the case of fixed parameters
‘confint.mkinfit’: Make the quadratic approximation the default, as the likelihood profiling takes a lot of time, especially if the fit has more than three parameters
diff --git a/docs/reference/index.html b/docs/reference/index.html
index 1c9975e0..0947ff94 100644
--- a/docs/reference/index.html
+++ b/docs/reference/index.html
@@ -214,6 +214,12 @@ more datasets
Lack-of-fit test for models fitted to data with replicates
+
+
loftest.Rd
+
+
+
+
This is a generic function with a method currently only defined for mkinfit
+objects. It fits an anova model to the data contained in the object and
+compares the likelihoods using the likelihood ratio test
+lrtest.default from the lmtest package.
+
+
+
loftest(object, ...)
+
+# S3 method for mkinfit
+loftest(object, ...)
+
+
Arguments
+
+
+
+
object
+
A model object with a defined loftest method
+
+
+
...
+
Not used
+
+
+
+
Details
+
+
The anova model is interpreted as the simplest form of an mkinfit model,
+assuming only a constant variance about the means, but not enforcing any
+structure of the means, so we have one model parameter for every mean
+of replicate samples.
+
See also
+
+
lrtest
+
+
Examples
+
# \dontrun{
+test_data<-subset(synthetic_data_for_UBA_2014[[12]]$data, name=="parent")
+sfo_fit<-mkinfit("SFO", test_data, quiet=TRUE)
+plot_res(sfo_fit) # We see a clear pattern in the residuals
loftest(sfo_fit) # We have a clear lack of fit
#> Likelihood ratio test
+#>
+#> Model 1: ANOVA with error model const
+#> Model 2: SFO with error model const
+#> #Df LogLik Df Chisq Pr(>Chisq)
+#> 1 10 -40.710
+#> 2 3 -63.954 -7 46.487 7.027e-08 ***
+#> ---
+#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
+# We try a different model (the one that was used to generate the data)
+dfop_fit<-mkinfit("DFOP", test_data, quiet=TRUE)
+plot_res(dfop_fit) # We don't see systematic deviations, but heteroscedastic residuals
# therefore we should consider adapting the error model, although we have
+loftest(dfop_fit) # no lack of fit
#> Likelihood ratio test
+#>
+#> Model 1: ANOVA with error model const
+#> Model 2: DFOP with error model const
+#> #Df LogLik Df Chisq Pr(>Chisq)
+#> 1 10 -40.710
+#> 2 5 -42.453 -5 3.485 0.6257
#
+# This is the anova model used internally for the comparison
+test_data_anova<-test_data
+test_data_anova$time<-as.factor(test_data_anova$time)
+anova_fit<-lm(value ~ time, data=test_data_anova)
+summary(anova_fit)
#> Successfully compiled differential equation model from auto-generated C code.
dfop_par_fit<-mkinfit(m_synth_DFOP_par, test_data_2, quiet=TRUE)
+plot_res(dfop_par_fit) # No visual lack of fit
loftest(dfop_par_fit) # no lack of fit found by the test
#> Likelihood ratio test
+#>
+#> Model 1: ANOVA with error model const
+#> Model 2: m_synth_DFOP_par with error model const and fixed parameter(s) M1_0, M2_0
+#> #Df LogLik Df Chisq Pr(>Chisq)
+#> 1 28 -93.606
+#> 2 9 -102.763 -19 18.313 0.5016
#
+# The anova model used for comparison in the case of transformation products
+test_data_anova_2<-dfop_par_fit$data
+test_data_anova_2$variable<-as.factor(test_data_anova_2$variable)
+test_data_anova_2$time<-as.factor(test_data_anova_2$time)
+anova_fit_2<-lm(observed ~ time:variable - 1, data=test_data_anova_2)
+summary(anova_fit_2)
+
+
+
+
+
+
+
+
diff --git a/docs/sitemap.xml b/docs/sitemap.xml
index 3a56fe49..66b776b2 100644
--- a/docs/sitemap.xml
+++ b/docs/sitemap.xml
@@ -66,6 +66,9 @@
https://pkgdown.jrwb.de/mkin/reference/ilr.html
+
+ https://pkgdown.jrwb.de/mkin/reference/loftest.html
+ https://pkgdown.jrwb.de/mkin/reference/logLik.mkinfit.html
diff --git a/man/loftest.Rd b/man/loftest.Rd
new file mode 100644
index 00000000..397b5c08
--- /dev/null
+++ b/man/loftest.Rd
@@ -0,0 +1,81 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/loftest.R
+\name{loftest}
+\alias{loftest}
+\alias{loftest.mkinfit}
+\title{Lack-of-fit test for models fitted to data with replicates}
+\usage{
+loftest(object, ...)
+
+\method{loftest}{mkinfit}(object, ...)
+}
+\arguments{
+\item{object}{A model object with a defined loftest method}
+
+\item{\dots}{Not used}
+}
+\description{
+This is a generic function with a method currently only defined for mkinfit
+objects. It fits an anova model to the data contained in the object and
+compares the likelihoods using the likelihood ratio test
+\code{\link[lmtest]{lrtest.default}} from the lmtest package.
+}
+\details{
+The anova model is interpreted as the simplest form of an mkinfit model,
+assuming only a constant variance about the means, but not enforcing any
+structure of the means, so we have one model parameter for every mean
+of replicate samples.
+}
+\examples{
+\dontrun{
+test_data <- subset(synthetic_data_for_UBA_2014[[12]]$data, name == "parent")
+sfo_fit <- mkinfit("SFO", test_data, quiet = TRUE)
+plot_res(sfo_fit) # We see a clear pattern in the residuals
+loftest(sfo_fit) # We have a clear lack of fit
+#
+# We try a different model (the one that was used to generate the data)
+dfop_fit <- mkinfit("DFOP", test_data, quiet = TRUE)
+plot_res(dfop_fit) # We don't see systematic deviations, but heteroscedastic residuals
+# therefore we should consider adapting the error model, although we have
+loftest(dfop_fit) # no lack of fit
+#
+# This is the anova model used internally for the comparison
+test_data_anova <- test_data
+test_data_anova$time <- as.factor(test_data_anova$time)
+anova_fit <- lm(value ~ time, data = test_data_anova)
+summary(anova_fit)
+logLik(anova_fit) # We get the same likelihood and degrees of freedom
+#
+test_data_2 <- synthetic_data_for_UBA_2014[[12]]$data
+m_synth_SFO_lin <- mkinmod(parent = list(type = "SFO", to = "M1"),
+ M1 = list(type = "SFO", to = "M2"),
+ M2 = list(type = "SFO"), use_of_ff = "max")
+sfo_lin_fit <- mkinfit(m_synth_SFO_lin, test_data_2, quiet = TRUE)
+plot_res(sfo_lin_fit) # not a good model, we try parallel formation
+loftest(sfo_lin_fit)
+#
+m_synth_SFO_par <- mkinmod(parent = list(type = "SFO", to = c("M1", "M2")),
+ M1 = list(type = "SFO"),
+ M2 = list(type = "SFO"), use_of_ff = "max")
+sfo_par_fit <- mkinfit(m_synth_SFO_par, test_data_2, quiet = TRUE)
+plot_res(sfo_par_fit) # much better for metabolites
+loftest(sfo_par_fit)
+#
+m_synth_DFOP_par <- mkinmod(parent = list(type = "DFOP", to = c("M1", "M2")),
+ M1 = list(type = "SFO"),
+ M2 = list(type = "SFO"), use_of_ff = "max")
+dfop_par_fit <- mkinfit(m_synth_DFOP_par, test_data_2, quiet = TRUE)
+plot_res(dfop_par_fit) # No visual lack of fit
+loftest(dfop_par_fit) # no lack of fit found by the test
+#
+# The anova model used for comparison in the case of transformation products
+test_data_anova_2 <- dfop_par_fit$data
+test_data_anova_2$variable <- as.factor(test_data_anova_2$variable)
+test_data_anova_2$time <- as.factor(test_data_anova_2$time)
+anova_fit_2 <- lm(observed ~ time:variable - 1, data = test_data_anova_2)
+summary(anova_fit_2)
+}
+}
+\seealso{
+lrtest
+}
diff --git a/test.log b/test.log
index 806c72b3..bc6d26ae 100644
--- a/test.log
+++ b/test.log
@@ -2,32 +2,36 @@ Loading mkin
Testing mkin
✔ | OK F W S | Context
✔ | 2 | Export dataset for reading into CAKE
-✔ | 10 | Confidence intervals and p-values [9.7 s]
-✔ | 14 | Error model fitting [36.5 s]
+✔ | 10 | Confidence intervals and p-values [10.1 s]
+✔ | 14 | Error model fitting [40.5 s]
✔ | 4 | Calculation of FOCUS chi2 error levels [2.2 s]
-✔ | 13 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [3.3 s]
+✔ | 13 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [3.4 s]
✔ | 6 | Test fitting the decline of metabolites from their maximum [0.7 s]
✔ | 1 | Fitting the logistic model [0.9 s]
✔ | 1 | Test dataset class mkinds used in gmkin
✔ | 12 | Special cases of mkinfit calls [2.4 s]
✔ | 9 | mkinmod model generation and printing [0.2 s]
✔ | 3 | Model predictions with mkinpredict [0.3 s]
-✔ | 16 | Evaluations according to 2015 NAFTA guidance [4.0 s]
+✔ | 16 | Evaluations according to 2015 NAFTA guidance [4.1 s]
✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.3 s]
✔ | 3 | Summary
✔ | 11 | Plotting [0.6 s]
✔ | 4 | AIC calculation
✔ | 2 | Residuals extracted from mkinfit models
-✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [5.3 s]
-✔ | 4 | Fitting the SFORB model [1.7 s]
+✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [5.6 s]
+✔ | 4 | Fitting the SFORB model [1.8 s]
✔ | 1 | Summaries of old mkinfit objects
-✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [7.1 s]
-✔ | 6 | Hypothesis tests [31.2 s]
+✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [7.5 s]
+✔ | 7 1 | Hypothesis tests [34.1 s]
+────────────────────────────────────────────────────────────────────────────────
+test_tests.R:59: skip: We can do a likelihood ratio test using an update specification
+Reason: This errors out if called by testthat while it works in a normal R session
+────────────────────────────────────────────────────────────────────────────────
══ Results ═════════════════════════════════════════════════════════════════════
-Duration: 108.3 s
+Duration: 116.9 s
-OK: 132
+OK: 133
Failed: 0
Warnings: 0
-Skipped: 0
+Skipped: 1
diff --git a/tests/testthat/FOCUS_2006_D.csf b/tests/testthat/FOCUS_2006_D.csf
index 528e2b61..09940aa3 100644
--- a/tests/testthat/FOCUS_2006_D.csf
+++ b/tests/testthat/FOCUS_2006_D.csf
@@ -5,7 +5,7 @@ Description:
MeasurementUnits: % AR
TimeUnits: days
Comments: Created using mkin::CAKE_export
-Date: 2019-11-05
+Date: 2019-11-09
Optimiser: IRLS
[Data]
diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R
index 9becdd2a..e33f4af7 100644
--- a/tests/testthat/setup_script.R
+++ b/tests/testthat/setup_script.R
@@ -32,9 +32,6 @@ f_1_mkin_trans <- mkinfit("SFO", FOCUS_2006_A, quiet = TRUE)
f_1_mkin_notrans <- mkinfit("SFO", FOCUS_2006_A, quiet = TRUE,
transform_rates = FALSE)
-f_2_mkin <- mkinfit("DFOP", FOCUS_2006_C, quiet = TRUE)
-f_2_nls <- nls(value ~ SSbiexp(time, A1, lrc1, A2, lrc2), data = FOCUS_2006_C)
-
# mmkin object of parent fits for tests
models <- c("SFO", "FOMC", "DFOP", "HS")
fits <- mmkin(models,
@@ -62,11 +59,14 @@ f_sfo_sfo.ff <- mkinfit(SFO_SFO.ff,
subset(FOCUS_2006_D, value != 0),
quiet = TRUE)
-# Two metabolites
SFO_lin_a <- synthetic_data_for_UBA_2014[[1]]$data
-
DFOP_par_c <- synthetic_data_for_UBA_2014[[12]]$data
+f_2_mkin <- mkinfit("DFOP", DFOP_par_c, quiet = TRUE)
+f_2_nls <- nls(value ~ SSbiexp(time, A1, lrc1, A2, lrc2), data = subset(DFOP_par_c, name == "parent"))
+f_2_anova <- lm(value ~ as.factor(time), data = subset(DFOP_par_c, name == "parent"))
+
+# Two metabolites
m_synth_SFO_lin <- mkinmod(
parent = mkinsub("SFO", "M1"),
M1 = mkinsub("SFO", "M2"),
diff --git a/tests/testthat/test_confidence.R b/tests/testthat/test_confidence.R
index a2bf1401..e85fdb7a 100644
--- a/tests/testthat/test_confidence.R
+++ b/tests/testthat/test_confidence.R
@@ -54,11 +54,12 @@ test_that("Quadratic confidence intervals for rate constants are comparable to v
# Another case:
se_mkin_2 <- summary(f_2_mkin)$par[1:4, "Std. Error"]
se_nls_2 <- summary(f_2_nls)$coefficients[, "Std. Error"]
- # Here we the ratio of standard errors can be explained by the same
+ # Here the ratio of standard errors can be explained by the same
# principle up to about 3%
+ nobs_DFOP_par_c_parent <- nrow(subset(DFOP_par_c, name == "parent"))
expect_equivalent(
se_nls_2[c("lrc1", "lrc2")] / se_mkin_2[c("log_k1", "log_k2")],
- rep(sqrt(nrow(FOCUS_2006_C) / (nrow(FOCUS_2006_C) - 4)), 2),
+ rep(sqrt(nobs_DFOP_par_c_parent / (nobs_DFOP_par_c_parent - 4)), 2),
tolerance = 0.03)
})
@@ -73,7 +74,7 @@ test_that("Likelihood profile based confidence intervals work", {
}
f_mle <- stats4::mle(f_nll, start = as.list(parms(f)), nobs = nrow(FOCUS_2006_C))
- ci_mkin_1_p_0.95 <- confint(f, method = "profile", level = 0.95,
+ ci_mkin_1_p_0.95 <- confint(f, method = "profile", level = 0.95,
cores = n_cores, quiet = TRUE)
# Magically, we get very similar boundaries as stats4::mle
diff --git a/tests/testthat/test_tests.R b/tests/testthat/test_tests.R
index 5a522f8e..bdc72f08 100644
--- a/tests/testthat/test_tests.R
+++ b/tests/testthat/test_tests.R
@@ -1,5 +1,20 @@
context("Hypothesis tests")
+test_that("The lack-of-fit test works and can be reproduced using nls", {
+
+ expect_error(loftest(f_1_mkin_trans), "Not defined for fits to data without replicates")
+
+ loftest_mkin <- loftest(f_2_mkin)
+
+ # This code is inspired by Ritz and Streibig (2008) Nonlinear Regression using R, p. 64
+ Q <- as.numeric(- 2 * (logLik(f_2_nls) - logLik(f_2_anova)))
+ df.Q <- df.residual(f_2_nls) - df.residual(f_2_anova)
+ p_nls <- 1 - pchisq(Q, df.Q)
+
+ expect_equal(loftest_mkin[["2", "Pr(>Chisq)"]], p_nls, tolerance = 1e-5)
+
+})
+
test_that("The likelihood ratio test works", {
expect_error(lrtest(f_1_mkin_trans, f_2_mkin), "not been fitted to the same data")
@@ -25,7 +40,7 @@ test_that("Updating fitted models works", {
parent = mkinsub("DFOP", to = "A1"),
A1 = mkinsub("SFO", to = "A2"),
A2 = mkinsub("SFO"),
- use_of_ff = "max"
+ use_of_ff = "max", quiet = TRUE
)
f_soil_1_tc <- mkinfit(dfop_sfo_sfo,
@@ -41,6 +56,9 @@ test_that("Updating fitted models works", {
})
test_that("We can do a likelihood ratio test using an update specification", {
+ skip("This errors out if called by testthat while it works in a normal R session")
test_2_mkin_k2 <- lrtest(f_2_mkin, fixed_parms = c(k2 = 0))
- expect_equivalent(test_2_mkin_k2[["2", "Pr(>Chisq)"]], 1.139e-6, tolerance = 1e-8)
+ expect_equivalent(test_2_mkin_k2[["2", "Pr(>Chisq)"]], 4.851e-8, tolerance = 1e-8)
+ test_2_mkin_tc <- lrtest(f_2_mkin, error_model = "tc")
+ expect_equivalent(test_2_mkin_tc[["2", "Pr(>Chisq)"]], 7.302e-5, tolerance = 1e-7)
})
--
cgit v1.2.1
From 6064a205d42220062506b11d6334b4f8e3217041 Mon Sep 17 00:00:00 2001
From: Johannes Ranke
Date: Tue, 12 Nov 2019 15:16:28 +0100
Subject: lrtest method for mmkin columns with two fits
---
R/lrtest.mkinfit.R | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/R/lrtest.mkinfit.R b/R/lrtest.mkinfit.R
index a5689830..380cf3a5 100644
--- a/R/lrtest.mkinfit.R
+++ b/R/lrtest.mkinfit.R
@@ -18,6 +18,8 @@ lmtest::lrtest
#' parameters (alternative hypothesis) is listed first, then the model with the
#' lower number of fitted parameters (null hypothesis).
#'
+#' The method for mmkin objects only works for column objects with two members.
+#'
#' @importFrom stats logLik update
#' @param object An \code{\link{mkinfit}} object
#' @param object_2 Optionally, another mkinfit object fitted to the same data.
@@ -68,3 +70,10 @@ lrtest.mkinfit <- function(object, object_2 = NULL, ...) {
lmtest::lrtest.default(object_2, object, name = name_function)
}
}
+
+#' @rdname lrtest.mkinfit
+#' @export
+lrtest.mmkin <- function(object, ...) {
+ if (nrow(object) != 2 | ncol(object) > 1) stop("Only works for a column containing two mkinfit objects")
+ lrtest(object[[1, 1]], object[[2, 1]])
+}
--
cgit v1.2.1
From f3757dfbaabe4e60ecac063437a75ea32999640a Mon Sep 17 00:00:00 2001
From: Johannes Ranke
Date: Wed, 13 Nov 2019 11:04:27 +0100
Subject: Remove leftover line
---
tests/testthat/test_SFORB.R | 2 --
1 file changed, 2 deletions(-)
diff --git a/tests/testthat/test_SFORB.R b/tests/testthat/test_SFORB.R
index 49b3beed..bc9ab646 100644
--- a/tests/testthat/test_SFORB.R
+++ b/tests/testthat/test_SFORB.R
@@ -18,8 +18,6 @@
context("Fitting the SFORB model")
-logistic <- mkinmod(parent = mkinsub("logistic"))
-
test_that("Fitting the SFORB model is equivalent to fitting DFOP", {
f_sforb <- mkinfit("SFORB", FOCUS_2006_C, quiet = TRUE)
f_dfop <- mkinfit("DFOP", FOCUS_2006_C, quiet = TRUE)
--
cgit v1.2.1
From f6385b071cee2c261da28bf98fd1599da1a30ddb Mon Sep 17 00:00:00 2001
From: Johannes Ranke
Date: Wed, 13 Nov 2019 11:05:39 +0100
Subject: Likelihood ratio test for mmkin columns with two fits
---
NAMESPACE | 1 +
R/lrtest.mkinfit.R | 5 ++---
docs/reference/index.html | 2 +-
docs/reference/lrtest.mkinfit.html | 8 ++++++--
man/lrtest.mkinfit.Rd | 6 +++++-
5 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/NAMESPACE b/NAMESPACE
index f428a612..e561621b 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -7,6 +7,7 @@ S3method(confint,mkinfit)
S3method(loftest,mkinfit)
S3method(logLik,mkinfit)
S3method(lrtest,mkinfit)
+S3method(lrtest,mmkin)
S3method(mkinpredict,mkinfit)
S3method(mkinpredict,mkinmod)
S3method(nobs,mkinfit)
diff --git a/R/lrtest.mkinfit.R b/R/lrtest.mkinfit.R
index 380cf3a5..0054ea88 100644
--- a/R/lrtest.mkinfit.R
+++ b/R/lrtest.mkinfit.R
@@ -18,10 +18,9 @@ lmtest::lrtest
#' parameters (alternative hypothesis) is listed first, then the model with the
#' lower number of fitted parameters (null hypothesis).
#'
-#' The method for mmkin objects only works for column objects with two members.
-#'
#' @importFrom stats logLik update
-#' @param object An \code{\link{mkinfit}} object
+#' @param object An \code{\link{mkinfit}} object, or an \code{\link{mmkin}} column
+#' object containing two fits to the same data.
#' @param object_2 Optionally, another mkinfit object fitted to the same data.
#' @param \dots Argument to \code{\link{mkinfit}}, passed to
#' \code{\link{update.mkinfit}} for creating the alternative fitted object.
diff --git a/docs/reference/index.html b/docs/reference/index.html
index 0947ff94..4398469b 100644
--- a/docs/reference/index.html
+++ b/docs/reference/index.html
@@ -209,7 +209,7 @@ more datasets
diff --git a/docs/reference/lrtest.mkinfit.html b/docs/reference/lrtest.mkinfit.html
index 1d82eb74..70157db9 100644
--- a/docs/reference/lrtest.mkinfit.html
+++ b/docs/reference/lrtest.mkinfit.html
@@ -145,14 +145,18 @@ and can be expressed by fixing the parameters of the other.
# S3 method for mkinfit
-lrtest(object, object_2=NULL, ...)
An mkinfit object, or an mmkin column
+object containing two fits to the same data.
object_2
diff --git a/man/lrtest.mkinfit.Rd b/man/lrtest.mkinfit.Rd
index bc8ab4dc..84d7bc99 100644
--- a/man/lrtest.mkinfit.Rd
+++ b/man/lrtest.mkinfit.Rd
@@ -2,12 +2,16 @@
% Please edit documentation in R/lrtest.mkinfit.R
\name{lrtest.mkinfit}
\alias{lrtest.mkinfit}
+\alias{lrtest.mmkin}
\title{Likelihood ratio test for mkinfit models}
\usage{
\method{lrtest}{mkinfit}(object, object_2 = NULL, ...)
+
+\method{lrtest}{mmkin}(object, ...)
}
\arguments{
-\item{object}{An \code{\link{mkinfit}} object}
+\item{object}{An \code{\link{mkinfit}} object, or an \code{\link{mmkin}} column
+object containing two fits to the same data.}
\item{object_2}{Optionally, another mkinfit object fitted to the same data.}
--
cgit v1.2.1
From b0e529ff49dfa52568fe7c5e6e76439a83c62840 Mon Sep 17 00:00:00 2001
From: Johannes Ranke
Date: Wed, 13 Nov 2019 16:22:17 +0100
Subject: Improve citation
---
tests/testthat/test_tests.R | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tests/testthat/test_tests.R b/tests/testthat/test_tests.R
index bdc72f08..ddf8e1a0 100644
--- a/tests/testthat/test_tests.R
+++ b/tests/testthat/test_tests.R
@@ -6,7 +6,8 @@ test_that("The lack-of-fit test works and can be reproduced using nls", {
loftest_mkin <- loftest(f_2_mkin)
- # This code is inspired by Ritz and Streibig (2008) Nonlinear Regression using R, p. 64
+ # This code is a slightly modified version of that given in Ritz and Streibig
+ # (2008) Nonlinear Regression using R, p. 64
Q <- as.numeric(- 2 * (logLik(f_2_nls) - logLik(f_2_anova)))
df.Q <- df.residual(f_2_nls) - df.residual(f_2_anova)
p_nls <- 1 - pchisq(Q, df.Q)
--
cgit v1.2.1
From c3700bec3a704660d3ade7a54c56b7084beb02b4 Mon Sep 17 00:00:00 2001
From: Johannes Ranke
Date: Wed, 13 Nov 2019 21:15:35 +0100
Subject: Calculate Akaike weights
---
NAMESPACE | 3 +
NEWS.md | 2 +
R/aw.R | 60 +++++++++++
_pkgdown.yml | 1 +
docs/news/index.html | 1 +
docs/reference/aw.html | 214 ++++++++++++++++++++++++++++++++++++++++
docs/reference/index.html | 6 ++
docs/sitemap.xml | 3 +
man/aw.Rd | 47 +++++++++
test.log | 21 ++--
tests/testthat/FOCUS_2006_D.csf | 2 +-
tests/testthat/test_aw.R | 12 +++
12 files changed, 361 insertions(+), 11 deletions(-)
create mode 100644 R/aw.R
create mode 100644 docs/reference/aw.html
create mode 100644 man/aw.Rd
create mode 100644 tests/testthat/test_aw.R
diff --git a/NAMESPACE b/NAMESPACE
index e561621b..26995055 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -3,6 +3,8 @@
S3method("[",mmkin)
S3method(AIC,mmkin)
S3method(BIC,mmkin)
+S3method(aw,mkinfit)
+S3method(aw,mmkin)
S3method(confint,mkinfit)
S3method(loftest,mkinfit)
S3method(logLik,mkinfit)
@@ -30,6 +32,7 @@ export(IORE.solution)
export(SFO.solution)
export(SFORB.solution)
export(add_err)
+export(aw)
export(backtransform_odeparms)
export(endpoints)
export(ilr)
diff --git a/NEWS.md b/NEWS.md
index 965105f4..28cf76ad 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,7 @@
# mkin 0.9.49.8 (unreleased)
+- 'aw': Generic function for calculating Akaike weights, methods for mkinfit objects and mmkin columns
+
- 'loftest': Add a lack-of-fit test
- 'plot_res', 'plot_sep' and 'mkinerrplot': Add the possibility to show standardized residuals and make it the default for fits with error models other than 'const'
diff --git a/R/aw.R b/R/aw.R
new file mode 100644
index 00000000..24078f38
--- /dev/null
+++ b/R/aw.R
@@ -0,0 +1,60 @@
+#' Calculate Akaike weights for model averaging
+#'
+#' Akaike weights are calculated based on the relative
+#' expected Kullback-Leibler information as specified
+#' by Burnham and Anderson (2004).
+#'
+#' @param object An mmkin column object, containing two or more
+#' \code{\link{mkinfit}} models that have been fitted to the same data,
+#' or an mkinfit object. In the latter case, further mkinfit
+#' objects fitted to the same data should be specified
+#' as dots arguments.
+#' @param \dots Not used in the method for mmkin column objects,
+#' further mkinfit objects in the method for mkinfit objects.
+#' @references Burnham KP and Anderson DR (2004) Multimodel
+#' Inference: Understanding AIC and BIC in Model Selection
+#' Sociological Methods & Research 33(2) 261-304
+#' @examples
+#' \dontrun{
+#' f_sfo <- mkinfit("SFO", FOCUS_2006_D, quiet = TRUE)
+#' f_dfop <- mkinfit("DFOP", FOCUS_2006_D, quiet = TRUE)
+#' aw_sfo_dfop <- aw(f_sfo, f_dfop)
+#' sum(aw_sfo_dfop)
+#' aw_sfo_dfop # SFO gets more weight as it has less parameters and a similar fit
+#' f <- mmkin(c("SFO", "FOMC", "DFOP"), list("FOCUS D" = FOCUS_2006_D), cores = 1, quiet = TRUE)
+#' aw(f)
+#' sum(aw(f))
+#' aw(f[c("SFO", "DFOP")])
+#' }
+#' @export
+aw <- function(object, ...) UseMethod("aw")
+
+#' @export
+#' @rdname aw
+aw.mkinfit <- function(object, ...) {
+ oo <- list(...)
+ data_object <- object$data[c("time", "variable", "observed")]
+ for (i in seq_along(oo)) {
+ if (!inherits(oo[[i]], "mkinfit")) stop("Please supply only mkinfit objects")
+ data_other_object <- oo[[i]]$data[c("time", "variable", "observed")]
+ if (!identical(data_object, data_other_object)) {
+ stop("It seems that the mkinfit objects have not all been fitted to the same data")
+ }
+ }
+ all_objects <- list(object, ...)
+ AIC_all <- sapply(all_objects, AIC)
+ delta_i <- AIC_all - min(AIC_all)
+ denom <- sum(exp(-delta_i/2))
+ w_i <- exp(-delta_i/2) / denom
+ return(w_i)
+}
+
+#' @export
+#' @rdname aw
+aw.mmkin <- function(object, ...) {
+ if (ncol(object) > 1) stop("Please supply an mmkin column object")
+ do.call(aw, object)
+}
+
+
+
diff --git a/_pkgdown.yml b/_pkgdown.yml
index c298256f..6bb05b3e 100644
--- a/_pkgdown.yml
+++ b/_pkgdown.yml
@@ -25,6 +25,7 @@ reference:
- loftest
- mkinerrmin
- endpoints
+ - aw
- CAKE_export
- title: Work with mmkin objects
desc: Functions working with aggregated results
diff --git a/docs/news/index.html b/docs/news/index.html
index 9aa2e18b..6b0b89fa 100644
--- a/docs/news/index.html
+++ b/docs/news/index.html
@@ -134,6 +134,7 @@
mkin 0.9.49.8 (unreleased) Unreleased
+
‘aw’: Generic function for calculating Akaike weights, methods for mkinfit objects and mmkin columns
‘loftest’: Add a lack-of-fit test
‘plot_res’, ‘plot_sep’ and ‘mkinerrplot’: Add the possibility to show standardized residuals and make it the default for fits with error models other than ‘const’
‘lrtest.mkinfit’: Improve naming of the compared fits in the case of fixed parameters
Akaike weights are calculated based on the relative
+expected Kullback-Leibler information as specified
+by Burnham and Anderson (2004).
+
+
+
aw(object, ...)
+
+# S3 method for mkinfit
+aw(object, ...)
+
+# S3 method for mmkin
+aw(object, ...)
+
+
Arguments
+
+
+
+
object
+
An mmkin column object, containing two or more
+mkinfit models that have been fitted to the same data,
+or an mkinfit object. In the latter case, further mkinfit
+objects fitted to the same data should be specified
+as dots arguments.
+
+
+
...
+
Not used in the method for mmkin column objects,
+further mkinfit objects in the method for mkinfit objects.
+
+
+
+
References
+
+
Burnham KP and Anderson DR (2004) Multimodel
+ Inference: Understanding AIC and BIC in Model Selection
+ Sociological Methods & Research 33(2) 261-304
diff --git a/docs/sitemap.xml b/docs/sitemap.xml
index 66b776b2..a8d6dfa4 100644
--- a/docs/sitemap.xml
+++ b/docs/sitemap.xml
@@ -54,6 +54,9 @@
https://pkgdown.jrwb.de/mkin/reference/add_err.html
+
+ https://pkgdown.jrwb.de/mkin/reference/aw.html
+ https://pkgdown.jrwb.de/mkin/reference/confint.mkinfit.html
diff --git a/man/aw.Rd b/man/aw.Rd
new file mode 100644
index 00000000..f0994b94
--- /dev/null
+++ b/man/aw.Rd
@@ -0,0 +1,47 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/aw.R
+\name{aw}
+\alias{aw}
+\alias{aw.mkinfit}
+\alias{aw.mmkin}
+\title{Calculate Akaike weights for model averaging}
+\usage{
+aw(object, ...)
+
+\method{aw}{mkinfit}(object, ...)
+
+\method{aw}{mmkin}(object, ...)
+}
+\arguments{
+\item{object}{An mmkin column object, containing two or more
+\code{\link{mkinfit}} models that have been fitted to the same data,
+or an mkinfit object. In the latter case, further mkinfit
+objects fitted to the same data should be specified
+as dots arguments.}
+
+\item{\dots}{Not used in the method for mmkin column objects,
+further mkinfit objects in the method for mkinfit objects.}
+}
+\description{
+Akaike weights are calculated based on the relative
+expected Kullback-Leibler information as specified
+by Burnham and Anderson (2004).
+}
+\examples{
+\dontrun{
+f_sfo <- mkinfit("SFO", FOCUS_2006_D, quiet = TRUE)
+f_dfop <- mkinfit("DFOP", FOCUS_2006_D, quiet = TRUE)
+aw_sfo_dfop <- aw(f_sfo, f_dfop)
+sum(aw_sfo_dfop)
+aw_sfo_dfop # SFO gets more weight as it has less parameters and a similar fit
+f <- mmkin(c("SFO", "FOMC", "DFOP"), list("FOCUS D" = FOCUS_2006_D), cores = 1, quiet = TRUE)
+aw(f)
+sum(aw(f))
+aw(f[c("SFO", "DFOP")])
+}
+}
+\references{
+Burnham KP and Anderson DR (2004) Multimodel
+ Inference: Understanding AIC and BIC in Model Selection
+ Sociological Methods & Research 33(2) 261-304
+}
diff --git a/test.log b/test.log
index bc6d26ae..c51d06b8 100644
--- a/test.log
+++ b/test.log
@@ -1,11 +1,12 @@
Loading mkin
Testing mkin
✔ | OK F W S | Context
+✔ | 5 | Calculation of Akaike weights
✔ | 2 | Export dataset for reading into CAKE
-✔ | 10 | Confidence intervals and p-values [10.1 s]
-✔ | 14 | Error model fitting [40.5 s]
+✔ | 10 | Confidence intervals and p-values [9.7 s]
+✔ | 14 | Error model fitting [36.9 s]
✔ | 4 | Calculation of FOCUS chi2 error levels [2.2 s]
-✔ | 13 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [3.4 s]
+✔ | 13 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [3.3 s]
✔ | 6 | Test fitting the decline of metabolites from their maximum [0.7 s]
✔ | 1 | Fitting the logistic model [0.9 s]
✔ | 1 | Test dataset class mkinds used in gmkin
@@ -18,20 +19,20 @@ Testing mkin
✔ | 11 | Plotting [0.6 s]
✔ | 4 | AIC calculation
✔ | 2 | Residuals extracted from mkinfit models
-✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [5.6 s]
-✔ | 4 | Fitting the SFORB model [1.8 s]
+✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [5.3 s]
+✔ | 4 | Fitting the SFORB model [1.7 s]
✔ | 1 | Summaries of old mkinfit objects
-✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [7.5 s]
-✔ | 7 1 | Hypothesis tests [34.1 s]
+✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [7.2 s]
+✔ | 7 1 | Hypothesis tests [32.3 s]
────────────────────────────────────────────────────────────────────────────────
-test_tests.R:59: skip: We can do a likelihood ratio test using an update specification
+test_tests.R:60: skip: We can do a likelihood ratio test using an update specification
Reason: This errors out if called by testthat while it works in a normal R session
────────────────────────────────────────────────────────────────────────────────
══ Results ═════════════════════════════════════════════════════════════════════
-Duration: 116.9 s
+Duration: 110.2 s
-OK: 133
+OK: 138
Failed: 0
Warnings: 0
Skipped: 1
diff --git a/tests/testthat/FOCUS_2006_D.csf b/tests/testthat/FOCUS_2006_D.csf
index 09940aa3..358b50e3 100644
--- a/tests/testthat/FOCUS_2006_D.csf
+++ b/tests/testthat/FOCUS_2006_D.csf
@@ -5,7 +5,7 @@ Description:
MeasurementUnits: % AR
TimeUnits: days
Comments: Created using mkin::CAKE_export
-Date: 2019-11-09
+Date: 2019-11-13
Optimiser: IRLS
[Data]
diff --git a/tests/testthat/test_aw.R b/tests/testthat/test_aw.R
new file mode 100644
index 00000000..0a493893
--- /dev/null
+++ b/tests/testthat/test_aw.R
@@ -0,0 +1,12 @@
+context("Calculation of Akaike weights")
+
+test_that("Akaike weights sum to one", {
+ skip_on_cran()
+ aw_1 <- aw(fit_nw_1, fit_obs_1, fit_tc_1)
+ expect_error(aw(fit_nw_1, f_2_mkin), "same data")
+ expect_error(aw(fit_nw_1, 3), "mkinfit objects")
+ expect_equal(sum(aw_1), 1)
+ aw_2 <- aw(fits[c("SFO", "DFOP"), "FOCUS_D"])
+ expect_equal(sum(aw_2), 1)
+ expect_error(aw(fits), "mmkin column object")
+})
--
cgit v1.2.1
From e04fcfcfe06377ec180125e54fe4f458b0747a76 Mon Sep 17 00:00:00 2001
From: Johannes Ranke
Date: Wed, 13 Nov 2019 21:48:52 +0100
Subject: Improve README
---
README.html | 8 ++++----
README.md | 17 +++++------------
docs/index.html | 6 +++---
3 files changed, 12 insertions(+), 19 deletions(-)
diff --git a/README.html b/README.html
index f4b33afe..1e9d7932 100644
--- a/README.html
+++ b/README.html
@@ -367,7 +367,7 @@ summary {
mkin
-
+
The R package mkin provides calculation routines for the analysis of chemical degradation data, including multicompartment kinetics as needed for modelling the formation and decline of transformation products, or if several compartments are involved.
Installation
@@ -393,14 +393,14 @@ summary {
As of version 0.9-39, fitting of several models to several datasets, optionally in parallel, is supported, see for example plot.mmkin.
Model solution (forward modelling) in the function mkinpredict is performed either using the analytical solution for the case of parent only degradation, an eigenvalue based solution if only simple first-order (SFO) or SFORB kinetics are used in the model, or using a numeric solver from the deSolve package (default is lsoda).
If a C compiler is installed, the kinetic models are compiled from automatically generated C code, see vignette compiled_models. The autogeneration of C code was inspired by the ccSolve package. Thanks to Karline Soetaert for her work on that.
-
By default, kinetic rate constants and kinetic formation fractions are transformed internally using transform_odeparms so their estimators can more reasonably be expected to follow a normal distribution. This has the side effect that no constraints are needed in the optimisation. Thanks to René Lehmann for the nice cooperation on this, especially the isometric logration transformation that is now used for the formation fractions.
+
By default, kinetic rate constants and kinetic formation fractions are transformed internally using transform_odeparms so their estimators can more reasonably be expected to follow a normal distribution. This has the side effect that no constraints are needed in the optimisation. Thanks to René Lehmann for the nice cooperation on this, especially the isometric log-ratio transformation that is now used for the formation fractions.
A side effect of this is that when parameter estimates are backtransformed to match the model definition, confidence intervals calculated from standard errors are also backtransformed to the correct scale, and will not include meaningless values like negative rate constants or formation fractions adding up to more than 1, which can not occur in a single experiment with a single defined radiolabel position.
The usual one-sided t-test for significant difference from zero is nevertheless shown based on estimators for the untransformed parameters.
Summary and plotting functions. The summary of an mkinfit object is in fact a full report that should give enough information to be able to approximately reproduce the fit with other tools.
The chi-squared error level as defined in the FOCUS kinetics guidance (see below) is calculated for each observed variable.
When a metabolite decline phase is not described well by SFO kinetics, SFORB kinetics can be used for the metabolite.
Three different error models can be selected using the argument error_model to the mkinfit function.
-
Iteratively reweighted least squares fitting is now obsolete, and the variance by variable error model should now be specified as error_model = "obs".
+
The ‘variance by variable’ error model which is often fitted using Iteratively Reweighted Least Squares (IRLS) should now be specified as error_model = "obs".
A two-component error model similar to the one proposed by Rocke and Lorenzato can be selected using the argument error_model = "tc".
@@ -425,7 +425,7 @@ summary {
Development
-
Contributions are welcome! Your mkin fork is just a mouse click away… The master branch on github should always be in good shape, I implement new features in separate branches now. If you prefer subversion, project members for the r-forge project are welcome as well. Generally, the source code of the latest CRAN version should be available there. You can also browse the source code at cgit.jrwb.de/mkin.
+
Contributions are welcome!
diff --git a/README.md b/README.md
index e89bdc72..602324fa 100644
--- a/README.md
+++ b/README.md
@@ -71,7 +71,7 @@ and at [R-Forge](http://kinfit.r-forge.r-project.org/mkin_static/index.html).
so their estimators can more reasonably be expected to follow
a normal distribution. This has the side effect that no constraints
are needed in the optimisation. Thanks to René Lehmann for the nice
- cooperation on this, especially the isometric logration transformation
+ cooperation on this, especially the isometric log-ratio transformation
that is now used for the formation fractions.
* A side effect of this is that when parameter estimates are backtransformed
to match the model definition, confidence intervals calculated from
@@ -91,9 +91,9 @@ and at [R-Forge](http://kinfit.r-forge.r-project.org/mkin_static/index.html).
* Three different error models can be selected using the argument `error_model`
to the [`mkinfit`](https://pkgdown.jrwb.de/mkin/reference/mkinfit.html)
function.
-* Iteratively reweighted least squares fitting is now obsolete, and the
- variance by variable error model should now be specified as `error_model
- = "obs"`.
+* The 'variance by variable' error model which is often fitted using
+ Iteratively Reweighted Least Squares (IRLS) should now be specified as
+ `error_model = "obs"`.
* A two-component error model similar to the one proposed by
[Rocke and Lorenzato](https://pkgdown.jrwb.de/mkin/reference/sigma_twocomp.html)
can be selected using the argument `error_model = "tc"`.
@@ -160,11 +160,4 @@ will hopefully be able to learn from each other in the future as well.
## Development
-Contributions are welcome! Your
-[mkin fork](https://help.github.com/articles/fork-a-repo) is just a mouse click
-away... The master branch on github should always be in good shape, I implement
-new features in separate branches now. If you prefer subversion, project
-members for the
-[r-forge project](http://r-forge.r-project.org/R/?group_id=615) are welcome as well.
-Generally, the source code of the latest CRAN version should be available there.
-You can also browse the source code at [cgit.jrwb.de/mkin](http://cgit.jrwb.de/mkin).
+Contributions are welcome!
diff --git a/docs/index.html b/docs/index.html
index 231ef39f..c89fc122 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -127,14 +127,14 @@
As of version 0.9-39, fitting of several models to several datasets, optionally in parallel, is supported, see for example plot.mmkin.
Model solution (forward modelling) in the function mkinpredict is performed either using the analytical solution for the case of parent only degradation, an eigenvalue based solution if only simple first-order (SFO) or SFORB kinetics are used in the model, or using a numeric solver from the deSolve package (default is lsoda).
If a C compiler is installed, the kinetic models are compiled from automatically generated C code, see vignette compiled_models. The autogeneration of C code was inspired by the ccSolve package. Thanks to Karline Soetaert for her work on that.
-
By default, kinetic rate constants and kinetic formation fractions are transformed internally using transform_odeparms so their estimators can more reasonably be expected to follow a normal distribution. This has the side effect that no constraints are needed in the optimisation. Thanks to René Lehmann for the nice cooperation on this, especially the isometric logration transformation that is now used for the formation fractions.
+
By default, kinetic rate constants and kinetic formation fractions are transformed internally using transform_odeparms so their estimators can more reasonably be expected to follow a normal distribution. This has the side effect that no constraints are needed in the optimisation. Thanks to René Lehmann for the nice cooperation on this, especially the isometric log-ratio transformation that is now used for the formation fractions.
A side effect of this is that when parameter estimates are backtransformed to match the model definition, confidence intervals calculated from standard errors are also backtransformed to the correct scale, and will not include meaningless values like negative rate constants or formation fractions adding up to more than 1, which can not occur in a single experiment with a single defined radiolabel position.
The usual one-sided t-test for significant difference from zero is nevertheless shown based on estimators for the untransformed parameters.
Summary and plotting functions. The summary of an mkinfit object is in fact a full report that should give enough information to be able to approximately reproduce the fit with other tools.
The chi-squared error level as defined in the FOCUS kinetics guidance (see below) is calculated for each observed variable.
When a metabolite decline phase is not described well by SFO kinetics, SFORB kinetics can be used for the metabolite.
Three different error models can be selected using the argument error_model to the mkinfit function.
-
Iteratively reweighted least squares fitting is now obsolete, and the variance by variable error model should now be specified as error_model = "obs".
+
The ‘variance by variable’ error model which is often fitted using Iteratively Reweighted Least Squares (IRLS) should now be specified as error_model = "obs".
A two-component error model similar to the one proposed by Rocke and Lorenzato can be selected using the argument error_model = "tc".
@@ -163,7 +163,7 @@
Development
-
Contributions are welcome! Your mkin fork is just a mouse click away… The master branch on github should always be in good shape, I implement new features in separate branches now. If you prefer subversion, project members for the r-forge project are welcome as well. Generally, the source code of the latest CRAN version should be available there. You can also browse the source code at cgit.jrwb.de/mkin.
+
Contributions are welcome!
--
cgit v1.2.1
From 51535c943d2846bc73ad69a11909aac606996b7d Mon Sep 17 00:00:00 2001
From: Johannes Ranke
Date: Wed, 13 Nov 2019 22:16:43 +0100
Subject: Improve formatting using markdown
---
R/aw.R | 16 +++++++---------
docs/reference/aw.html | 12 ++++++------
man/aw.Rd | 12 ++++++------
3 files changed, 19 insertions(+), 21 deletions(-)
diff --git a/R/aw.R b/R/aw.R
index 24078f38..f46b20ec 100644
--- a/R/aw.R
+++ b/R/aw.R
@@ -4,16 +4,17 @@
#' expected Kullback-Leibler information as specified
#' by Burnham and Anderson (2004).
#'
-#' @param object An mmkin column object, containing two or more
-#' \code{\link{mkinfit}} models that have been fitted to the same data,
+#' @param object An [mmkin] column object, containing two or more
+#' [mkinfit] models that have been fitted to the same data,
#' or an mkinfit object. In the latter case, further mkinfit
#' objects fitted to the same data should be specified
#' as dots arguments.
-#' @param \dots Not used in the method for mmkin column objects,
-#' further mkinfit objects in the method for mkinfit objects.
+#' @param \dots Not used in the method for [mmkin] column objects,
+#' further [mkinfit] objects in the method for mkinfit objects.
#' @references Burnham KP and Anderson DR (2004) Multimodel
-#' Inference: Understanding AIC and BIC in Model Selection
-#' Sociological Methods & Research 33(2) 261-304
+#' Inference: Understanding AIC and BIC in Model Selection.
+#' *Sociological Methods & Research* **33**(2) 261-304
+#' @md
#' @examples
#' \dontrun{
#' f_sfo <- mkinfit("SFO", FOCUS_2006_D, quiet = TRUE)
@@ -55,6 +56,3 @@ aw.mmkin <- function(object, ...) {
if (ncol(object) > 1) stop("Please supply an mmkin column object")
do.call(aw, object)
}
-
-
-
diff --git a/docs/reference/aw.html b/docs/reference/aw.html
index b6f3ce48..22201229 100644
--- a/docs/reference/aw.html
+++ b/docs/reference/aw.html
@@ -153,24 +153,24 @@ by Burnham and Anderson (2004).
object
-
An mmkin column object, containing two or more
-mkinfit models that have been fitted to the same data,
+
An mmkin column object, containing two or more
+mkinfit models that have been fitted to the same data,
or an mkinfit object. In the latter case, further mkinfit
objects fitted to the same data should be specified
as dots arguments.
...
-
Not used in the method for mmkin column objects,
-further mkinfit objects in the method for mkinfit objects.
+
Not used in the method for mmkin column objects,
+further mkinfit objects in the method for mkinfit objects.
References
Burnham KP and Anderson DR (2004) Multimodel
- Inference: Understanding AIC and BIC in Model Selection
- Sociological Methods & Research 33(2) 261-304
+Inference: Understanding AIC and BIC in Model Selection.
+Sociological Methods & Research33(2) 261-304
Examples
# \dontrun{
diff --git a/man/aw.Rd b/man/aw.Rd
index f0994b94..40676716 100644
--- a/man/aw.Rd
+++ b/man/aw.Rd
@@ -13,14 +13,14 @@ aw(object, ...)
\method{aw}{mmkin}(object, ...)
}
\arguments{
-\item{object}{An mmkin column object, containing two or more
-\code{\link{mkinfit}} models that have been fitted to the same data,
+\item{object}{An \link{mmkin} column object, containing two or more
+\link{mkinfit} models that have been fitted to the same data,
or an mkinfit object. In the latter case, further mkinfit
objects fitted to the same data should be specified
as dots arguments.}
-\item{\dots}{Not used in the method for mmkin column objects,
-further mkinfit objects in the method for mkinfit objects.}
+\item{\dots}{Not used in the method for \link{mmkin} column objects,
+further \link{mkinfit} objects in the method for mkinfit objects.}
}
\description{
Akaike weights are calculated based on the relative
@@ -42,6 +42,6 @@ aw(f[c("SFO", "DFOP")])
}
\references{
Burnham KP and Anderson DR (2004) Multimodel
- Inference: Understanding AIC and BIC in Model Selection
- Sociological Methods & Research 33(2) 261-304
+Inference: Understanding AIC and BIC in Model Selection.
+\emph{Sociological Methods & Research} \strong{33}(2) 261-304
}
--
cgit v1.2.1
From 7ea467e0e0ba5bf51540b26e197869a58ed1a092 Mon Sep 17 00:00:00 2001
From: Johannes Ranke
Date: Mon, 9 Dec 2019 15:21:11 +0100
Subject: Consistently use "two-component error model"
instead of "two component error model"
---
R/sigma_twocomp.R | 2 +-
docs/reference/index.html | 2 +-
docs/reference/sigma_twocomp.html | 8 ++++----
man/sigma_twocomp.Rd | 2 +-
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/R/sigma_twocomp.R b/R/sigma_twocomp.R
index c9a15aa8..1e012d15 100644
--- a/R/sigma_twocomp.R
+++ b/R/sigma_twocomp.R
@@ -1,4 +1,4 @@
-#' Two component error model
+#' Two-component error model
#'
#' Function describing the standard deviation of the measurement error in
#' dependence of the measured value \eqn{y}:
diff --git a/docs/reference/index.html b/docs/reference/index.html
index 3d417267..73dfbe4c 100644
--- a/docs/reference/index.html
+++ b/docs/reference/index.html
@@ -444,7 +444,7 @@ kinetic models fitted with mkinfit
mkin would not be possible without the underlying software stack consisting of R and the packages deSolve and FME, to say the least.
-
It could not have been written without me being introduced to regulatory fate modelling of pesticides by Adrian Gurney during my time at Harlan Laboratories Ltd (formerly RCC Ltd). mkin greatly profits from and largely follows the work done by the FOCUS Degradation Kinetics Workgroup, as detailed in their guidance document from 2006, slightly updated in 2011 and in 2014.
+
mkin would not be possible without the underlying software stack consisting of R and the package deSolve. In previous version, mkin was also using the functionality of the FME package.
+
mkin could not have been written without me being introduced to regulatory fate modelling of pesticides by Adrian Gurney during my time at Harlan Laboratories Ltd (formerly RCC Ltd). mkin greatly profits from and largely follows the work done by the FOCUS Degradation Kinetics Workgroup, as detailed in their guidance document from 2006, slightly updated in 2011 and in 2014.
Also, it was inspired by the first version of KinGUI developed by BayerCropScience, which is based on the MatLab runtime environment.
Somewhat in parallel, Syngenta has sponsored the development of an mkin and KinGUII based GUI application called CAKE, which also adds IRLS and MCMC, is more limited in the model formulation, but puts more weight on usability. CAKE is available for download from the CAKE website, where you can also find a zip archive of the R scripts derived from mkin, published under the GPL license.
Finally, there is KineticEval, which contains a further development of the scripts used for KinGUII, so the different tools will hopefully be able to learn from each other in the future as well.
+
+
References
+
+
+
+Ranke J, Meinecke S (2019) Error Models for the Kinetic Evaluation of Chemical Degradation Data Environments6 (12) 124 doi:10.3390/environments6120124
+
+
+
+
+Ranke J, Wöltjen J, Meinecke S (2018) Comparison of software tools for kinetic evaluation of chemical degradation data Environmental Sciences Europe30 17 doi:10.1186/s12302-018-0145-1
+
+
+
+
Development
Contributions are welcome!
diff --git a/README.md b/README.md
index 602324fa..acbad934 100644
--- a/README.md
+++ b/README.md
@@ -112,10 +112,11 @@ and one for the [github master branch](https://github.com/jranke/mkin/blob/maste
## Credits and historical remarks
`mkin` would not be possible without the underlying software stack consisting
-of R and the packages [deSolve](https://cran.r-project.org/package=deSolve)
-and [FME](https://cran.r-project.org/package=FME), to say the least.
+of R and the package [deSolve](https://cran.r-project.org/package=deSolve).
+In previous version, `mkin` was also using the functionality of the
+[FME](https://cran.r-project.org/package=FME) package.
-It could not have been written without me being introduced to regulatory fate
+`mkin` could not have been written without me being introduced to regulatory fate
modelling of pesticides by Adrian Gurney during my time at Harlan Laboratories
Ltd (formerly RCC Ltd). `mkin` greatly profits from and largely follows
the work done by the
@@ -157,6 +158,23 @@ Finally, there is
a further development of the scripts used for KinGUII, so the different tools
will hopefully be able to learn from each other in the future as well.
+## References
+
+
+
Ranke J, Meinecke S (2019)
+ Error Models for the Kinetic Evaluation of Chemical Degradation Data
+ Environments
+ 6 (12) 124
+ doi:10.3390/environments6120124
+
+
+
Ranke J, Wöltjen J, Meinecke S (2018)
+ Comparison of software tools for kinetic evaluation of chemical degradation data
+ Environmental Sciences Europe
+ 30 17
+ doi:10.1186/s12302-018-0145-1
+
+
## Development
diff --git a/docs/index.html b/docs/index.html
index c89fc122..2e960df1 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -151,8 +151,8 @@
Credits and historical remarks
-
mkin would not be possible without the underlying software stack consisting of R and the packages deSolve and FME, to say the least.
-
It could not have been written without me being introduced to regulatory fate modelling of pesticides by Adrian Gurney during my time at Harlan Laboratories Ltd (formerly RCC Ltd). mkin greatly profits from and largely follows the work done by the FOCUS Degradation Kinetics Workgroup, as detailed in their guidance document from 2006, slightly updated in 2011 and in 2014.
+
mkin would not be possible without the underlying software stack consisting of R and the package deSolve. In previous version, mkin was also using the functionality of the FME package.
+
mkin could not have been written without me being introduced to regulatory fate modelling of pesticides by Adrian Gurney during my time at Harlan Laboratories Ltd (formerly RCC Ltd). mkin greatly profits from and largely follows the work done by the FOCUS Degradation Kinetics Workgroup, as detailed in their guidance document from 2006, slightly updated in 2011 and in 2014.
Also, it was inspired by the first version of KinGUI developed by BayerCropScience, which is based on the MatLab runtime environment.
Somewhat in parallel, Syngenta has sponsored the development of an mkin and KinGUII based GUI application called CAKE, which also adds IRLS and MCMC, is more limited in the model formulation, but puts more weight on usability. CAKE is available for download from the CAKE website, where you can also find a zip archive of the R scripts derived from mkin, published under the GPL license.
Finally, there is KineticEval, which contains a further development of the scripts used for KinGUII, so the different tools will hopefully be able to learn from each other in the future as well.
+
+
+References
+
+
Ranke J, Meinecke S (2019)
+ Error Models for the Kinetic Evaluation of Chemical Degradation Data
+ Environments
+ 6 (12) 124
+ doi:10.3390/environments6120124
+
+
Ranke J, Wöltjen J, Meinecke S (2018)
+ Comparison of software tools for kinetic evaluation of chemical degradation data
+ Environmental Sciences Europe
+ 30 17
+ doi:10.1186/s12302-018-0145-1
+
+
+
Development
--
cgit v1.2.1
From 7c8e06d4bae9ec80574147005b7e933937447220 Mon Sep 17 00:00:00 2001
From: Johannes Ranke
Date: Tue, 10 Dec 2019 20:56:10 +0100
Subject: More additions to the README
---
README.html | 2 +-
README.md | 10 +++++++---
docs/index.html | 2 +-
3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/README.html b/README.html
index dd4ea2c4..d7ebe451 100644
--- a/README.html
+++ b/README.html
@@ -414,7 +414,7 @@ summary {
Credits and historical remarks
-
mkin would not be possible without the underlying software stack consisting of R and the package deSolve. In previous version, mkin was also using the functionality of the FME package.
+
mkin would not be possible without the underlying software stack consisting of, among others, R and the package deSolve. In previous version, mkin was also using the functionality of the FME package. Please refer to the package page on CRAN for the full list of imported and suggested R packages. Also, Debian Linux, the vim editor and the Nvim-R plugin have been invaluable in its development.
mkin could not have been written without me being introduced to regulatory fate modelling of pesticides by Adrian Gurney during my time at Harlan Laboratories Ltd (formerly RCC Ltd). mkin greatly profits from and largely follows the work done by the FOCUS Degradation Kinetics Workgroup, as detailed in their guidance document from 2006, slightly updated in 2011 and in 2014.
Also, it was inspired by the first version of KinGUI developed by BayerCropScience, which is based on the MatLab runtime environment.
diff --git a/README.md b/README.md
index acbad934..8a0ecc50 100644
--- a/README.md
+++ b/README.md
@@ -111,10 +111,14 @@ and one for the [github master branch](https://github.com/jranke/mkin/blob/maste
## Credits and historical remarks
-`mkin` would not be possible without the underlying software stack consisting
-of R and the package [deSolve](https://cran.r-project.org/package=deSolve).
+`mkin` would not be possible without the underlying software stack consisting of,
+among others, R and the package [deSolve](https://cran.r-project.org/package=deSolve).
In previous version, `mkin` was also using the functionality of the
-[FME](https://cran.r-project.org/package=FME) package.
+[FME](https://cran.r-project.org/package=FME) package. Please refer to the
+[package page on CRAN](https://cran.r-project.org/package=mkin) for the full list
+of imported and suggested R packages. Also, [Debian Linux](https://debian.org),
+the vim editor and the [Nvim-R](https://github.com/jalvesaq/Nvim-R) plugin have
+been invaluable in its development.
`mkin` could not have been written without me being introduced to regulatory fate
modelling of pesticides by Adrian Gurney during my time at Harlan Laboratories
diff --git a/docs/index.html b/docs/index.html
index 2e960df1..fcb9c90b 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -151,7 +151,7 @@
Credits and historical remarks
-
mkin would not be possible without the underlying software stack consisting of R and the package deSolve. In previous version, mkin was also using the functionality of the FME package.
+
mkin would not be possible without the underlying software stack consisting of, among others, R and the package deSolve. In previous version, mkin was also using the functionality of the FME package. Please refer to the package page on CRAN for the full list of imported and suggested R packages. Also, Debian Linux, the vim editor and the Nvim-R plugin have been invaluable in its development.
mkin could not have been written without me being introduced to regulatory fate modelling of pesticides by Adrian Gurney during my time at Harlan Laboratories Ltd (formerly RCC Ltd). mkin greatly profits from and largely follows the work done by the FOCUS Degradation Kinetics Workgroup, as detailed in their guidance document from 2006, slightly updated in 2011 and in 2014.
Also, it was inspired by the first version of KinGUI developed by BayerCropScience, which is based on the MatLab runtime environment.
--
cgit v1.2.1
From 1868c1c6b98afa4c8a11b7c065d717bfb4ec1a8e Mon Sep 17 00:00:00 2001
From: Johannes Ranke
Date: Mon, 16 Dec 2019 02:51:19 +0100
Subject: Argument ymax for plot.mmkin
---
R/plot.mmkin.R | 26 ++++++++++++++++----------
docs/reference/plot.mmkin.html | 8 ++++++--
man/plot.mmkin.Rd | 4 +++-
3 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/R/plot.mmkin.R b/R/plot.mmkin.R
index eefafe12..182e74ca 100644
--- a/R/plot.mmkin.R
+++ b/R/plot.mmkin.R
@@ -1,13 +1,13 @@
#' Plot model fits (observed and fitted) and the residuals for a row or column
#' of an mmkin object
-#'
+#'
#' When x is a row selected from an mmkin object (\code{\link{[.mmkin}}), the
#' same model fitted for at least one dataset is shown. When it is a column,
#' the fit of at least one model to the same dataset is shown.
-#'
+#'
#' If the current plot device is a \code{\link[tikzDevice]{tikz}} device, then
#' latex is being used for the formatting of the chi2 error level.
-#'
+#'
#' @param x An object of class \code{\link{mmkin}}, with either one row or one
#' column.
#' @param main The main title placed on the outer margin of the plot.
@@ -24,12 +24,13 @@
#' @param cex Passed to the plot functions and \code{\link{mtext}}.
#' @param rel.height.middle The relative height of the middle plot, if more
#' than two rows of plots are shown.
+#' @param ymax Maximum y axis value for \code{\link{plot.mkinfit}}.
#' @param \dots Further arguments passed to \code{\link{plot.mkinfit}} and
#' \code{\link{mkinresplot}}.
#' @return The function is called for its side effect.
#' @author Johannes Ranke
#' @examples
-#'
+#'
#' \dontrun{
#' # Only use one core not to offend CRAN checks
#' fits <- mmkin(c("FOMC", "HS"),
@@ -37,22 +38,23 @@
#' cores = 1, quiet = TRUE, error_model = "tc")
#' plot(fits[, "FOCUS C"])
#' plot(fits["FOMC", ])
-#'
+#'
#' # We can also plot a single fit, if we like the way plot.mmkin works, but then the plot
#' # height should be smaller than the plot width (this is not possible for the html pages
#' # generated by pkgdown, as far as I know).
#' plot(fits["FOMC", "FOCUS C"]) # same as plot(fits[1, 2])
-#'
+#'
#' # Show the error models
#' plot(fits["FOMC", ], resplot = "errmod")
#' }
-#'
+#'
#' @export
-plot.mmkin <- function(x, main = "auto", legends = 1,
+plot.mmkin <- function(x, main = "auto", legends = 1,
resplot = c("time", "errmod"),
show_errmin = TRUE,
errmin_var = "All data", errmin_digits = 3,
- cex = 0.7, rel.height.middle = 0.9, ...) {
+ cex = 0.7, rel.height.middle = 0.9,
+ ymax = "auto", ...) {
n.m <- nrow(x)
n.d <- ncol(x)
@@ -107,7 +109,11 @@ plot.mmkin <- function(x, main = "auto", legends = 1,
}
fit <- x[[i.fit]]
- plot(fit, legend = legends == i.fit, ...)
+ if (ymax == "auto") {
+ plot(fit, legend = legends == i.fit, ...)
+ } else {
+ plot(fit, legend = legends == i.fit, ylim = c(0, ymax), ...)
+ }
title(main, outer = TRUE, line = -2)
diff --git a/docs/reference/plot.mmkin.html b/docs/reference/plot.mmkin.html
index 8b68cfae..18907aa2 100644
--- a/docs/reference/plot.mmkin.html
+++ b/docs/reference/plot.mmkin.html
@@ -73,7 +73,7 @@ the fit of at least one model to the same dataset is shown." />
mkin
- 0.9.49.6
+ 0.9.49.8
@@ -147,7 +147,7 @@ the fit of at least one model to the same dataset is shown.
plot(x, main="auto", legends=1,
resplot=c("time", "errmod"), show_errmin=TRUE,
errmin_var="All data", errmin_digits=3, cex=0.7,
- rel.height.middle=0.9, ...)
+ rel.height.middle=0.9, ymax="auto", ...)
Arguments
@@ -195,6 +195,10 @@ chi2 error percentage.
The relative height of the middle plot, if more
than two rows of plots are shown.
Further arguments passed to plot.mkinfit and
diff --git a/man/plot.mmkin.Rd b/man/plot.mmkin.Rd
index 333998da..605e458e 100644
--- a/man/plot.mmkin.Rd
+++ b/man/plot.mmkin.Rd
@@ -8,7 +8,7 @@ of an mmkin object}
\method{plot}{mmkin}(x, main = "auto", legends = 1,
resplot = c("time", "errmod"), show_errmin = TRUE,
errmin_var = "All data", errmin_digits = 3, cex = 0.7,
- rel.height.middle = 0.9, ...)
+ rel.height.middle = 0.9, ymax = "auto", ...)
}
\arguments{
\item{x}{An object of class \code{\link{mmkin}}, with either one row or one
@@ -36,6 +36,8 @@ chi2 error percentage.}
\item{rel.height.middle}{The relative height of the middle plot, if more
than two rows of plots are shown.}
+\item{ymax}{Maximum y axis value for \code{\link{plot.mkinfit}}.}
+
\item{\dots}{Further arguments passed to \code{\link{plot.mkinfit}} and
\code{\link{mkinresplot}}.}
}
--
cgit v1.2.1
From bc42b66fab81afaf4fd90aeb24cdf2b0c2d44202 Mon Sep 17 00:00:00 2001
From: Johannes Ranke
Date: Wed, 8 Jan 2020 15:06:49 +0100
Subject: Typos in NEWS, update static docs
---
NEWS.md | 2 +-
docs/news/index.html | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index 28cf76ad..622a82b0 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -14,7 +14,7 @@
- Fix a bug introduced in 0.9.49.6 that occurred if the direct optimisation yielded a higher likelihood than the three-step optimisation in the d_3 algorithm, which caused the fitted parameters of the three-step optimisation to be returned instead of the parameters of the direct optimisation
-- Add an 'nobs' method for mkinfit methods, enabling the default 'BIC' method from the stats package. Also, add a 'BIC' method for mmkin column objects.
+- Add a 'nobs' method for mkinfit objects, enabling the default 'BIC' method from the stats package. Also, add a 'BIC' method for mmkin column objects.
# mkin 0.9.49.6 (2019-10-31)
diff --git a/docs/news/index.html b/docs/news/index.html
index 6b0b89fa..00257521 100644
--- a/docs/news/index.html
+++ b/docs/news/index.html
@@ -147,7 +147,7 @@
Fix a bug introduced in 0.9.49.6 that occurred if the direct optimisation yielded a higher likelihood than the three-step optimisation in the d_3 algorithm, which caused the fitted parameters of the three-step optimisation to be returned instead of the parameters of the direct optimisation
-
Add an ‘nobs’ method for mkinfit methods, enabling the default ‘BIC’ method from the stats package. Also, add a ‘BIC’ method for mmkin column objects.
+
Add a ‘nobs’ method for mkinfit objects, enabling the default ‘BIC’ method from the stats package. Also, add a ‘BIC’ method for mmkin column objects.
--
cgit v1.2.1
From 571d328361fe9e4d47ceca35cc622ad7f930d608 Mon Sep 17 00:00:00 2001
From: Johannes Ranke
Date: Wed, 8 Jan 2020 15:31:10 +0100
Subject: Todays date in DESCRIPTION, update check log
---
DESCRIPTION | 2 +-
check.log | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/DESCRIPTION b/DESCRIPTION
index b0bcc39d..f9bed994 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -2,7 +2,7 @@ Package: mkin
Type: Package
Title: Kinetic Evaluation of Chemical Degradation Data
Version: 0.9.49.8
-Date: 2019-11-01
+Date: 2020-01-08
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/check.log b/check.log
index 85055c74..b7555c55 100644
--- a/check.log
+++ b/check.log
@@ -1,5 +1,5 @@
* using log directory ‘/home/jranke/git/mkin/mkin.Rcheck’
-* using R version 3.6.1 (2019-07-05)
+* using R version 3.6.2 (2019-12-12)
* using platform: x86_64-pc-linux-gnu (64-bit)
* using session charset: UTF-8
* using options ‘--no-tests --as-cran’
@@ -63,6 +63,7 @@ Maintainer: ‘Johannes Ranke ’
* checking package vignettes in ‘inst/doc’ ... OK
* checking re-building of vignette outputs ... OK
* checking PDF version of manual ... OK
+* checking for detritus in the temp directory ... OK
* DONE
Status: OK
--
cgit v1.2.1
From 70fe6d14e27fa8fb0634856ecc45a27f4f689d88 Mon Sep 17 00:00:00 2001
From: Johannes Ranke
Date: Thu, 9 Jan 2020 17:50:23 +0100
Subject: Remove unused FME package from DESCRIPTION text
---
DESCRIPTION | 13 ++++++-------
build.log | 2 +-
docs/404.html | 2 +-
docs/articles/index.html | 2 +-
docs/authors.html | 2 +-
docs/index.html | 11 +++++------
docs/news/index.html | 2 +-
docs/reference/index.html | 2 +-
docs/reference/parms.html | 2 +-
9 files changed, 18 insertions(+), 20 deletions(-)
diff --git a/DESCRIPTION b/DESCRIPTION
index f9bed994..0bc78ed2 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,8 +1,8 @@
Package: mkin
Type: Package
Title: Kinetic Evaluation of Chemical Degradation Data
-Version: 0.9.49.8
-Date: 2020-01-08
+Version: 0.9.49.9
+Date: 2020-01-09
Authors@R: c(person("Johannes", "Ranke", role = c("aut", "cre", "cph"),
email = "jranke@uni-bremen.de",
comment = c(ORCID = "0000-0003-4371-6538")),
@@ -12,11 +12,10 @@ Authors@R: c(person("Johannes", "Ranke", role = c("aut", "cre", "cph"),
Description: Calculation routines based on the FOCUS Kinetics Report (2006,
2014). Includes a function for conveniently defining differential equation
models, model solution based on eigenvalues if possible or using numerical
- solvers and a choice of the optimisation methods made available by the 'FME'
- package. If a C compiler (on windows: 'Rtools') is installed, differential
- equation models are solved using compiled C functions. Please note that no
- warranty is implied for correctness of results or fitness for a particular
- purpose.
+ solvers. If a C compiler (on windows: 'Rtools') is installed, differential
+ equation models are solved using automatically generated C functions. Please
+ note that no warranty is implied for correctness of results or fitness for a
+ particular purpose.
Imports: stats, graphics, methods, deSolve, R6, inline, parallel, numDeriv,
lmtest
Suggests: knitr, rbenchmark, tikzDevice, testthat, rmarkdown, covr, vdiffr,
diff --git a/build.log b/build.log
index ffd56a90..b0765ebb 100644
--- a/build.log
+++ b/build.log
@@ -6,5 +6,5 @@
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* looking to see if a ‘data/datalist’ file should be added
-* building ‘mkin_0.9.49.8.tar.gz’
+* building ‘mkin_0.9.49.9.tar.gz’
diff --git a/docs/404.html b/docs/404.html
index 2a71e496..3658a137 100644
--- a/docs/404.html
+++ b/docs/404.html
@@ -67,7 +67,7 @@
mkin
- 0.9.49.8
+ 0.9.49.9
diff --git a/docs/articles/index.html b/docs/articles/index.html
index ac5f5df1..3e181a2c 100644
--- a/docs/articles/index.html
+++ b/docs/articles/index.html
@@ -67,7 +67,7 @@
mkin
- 0.9.49.8
+ 0.9.49.9
diff --git a/docs/authors.html b/docs/authors.html
index fb50f268..2bb2557a 100644
--- a/docs/authors.html
+++ b/docs/authors.html
@@ -67,7 +67,7 @@
mkin
- 0.9.49.8
+ 0.9.49.9
diff --git a/docs/index.html b/docs/index.html
index fcb9c90b..fe334eb8 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -14,11 +14,10 @@
+ solvers. If a C compiler (on windows: Rtools) is installed, differential
+ equation models are solved using automatically generated C functions. Please
+ note that no warranty is implied for correctness of results or fitness for a
+ particular purpose.">