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 --- man/loftest.Rd | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 man/loftest.Rd (limited to 'man') 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 +} -- 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 --- man/lrtest.mkinfit.Rd | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'man') 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 c3700bec3a704660d3ade7a54c56b7084beb02b4 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 13 Nov 2019 21:15:35 +0100 Subject: Calculate Akaike weights --- man/aw.Rd | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 man/aw.Rd (limited to 'man') 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 +} -- 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 --- man/aw.Rd | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'man') 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" --- man/sigma_twocomp.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'man') diff --git a/man/sigma_twocomp.Rd b/man/sigma_twocomp.Rd index 3e7854f1..0004144f 100644 --- a/man/sigma_twocomp.Rd +++ b/man/sigma_twocomp.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/sigma_twocomp.R \name{sigma_twocomp} \alias{sigma_twocomp} -\title{Two component error model} +\title{Two-component error model} \usage{ sigma_twocomp(y, sigma_low, rsd_high) } -- 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 --- man/plot.mmkin.Rd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'man') 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