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 --- 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 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 349 insertions(+) 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 (limited to 'docs/reference') 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

Likelihood ratio test for mkinfit models

+ +

loftest()

+ +

Lack-of-fit test for models fitted to data with replicates

+ +

mkinerrmin()

diff --git a/docs/reference/loftest-1.png b/docs/reference/loftest-1.png new file mode 100644 index 00000000..3d20f41e Binary files /dev/null and b/docs/reference/loftest-1.png differ diff --git a/docs/reference/loftest-2.png b/docs/reference/loftest-2.png new file mode 100644 index 00000000..be8bf815 Binary files /dev/null and b/docs/reference/loftest-2.png differ diff --git a/docs/reference/loftest-3.png b/docs/reference/loftest-3.png new file mode 100644 index 00000000..c66c95f1 Binary files /dev/null and b/docs/reference/loftest-3.png differ diff --git a/docs/reference/loftest-4.png b/docs/reference/loftest-4.png new file mode 100644 index 00000000..da86d97f Binary files /dev/null and b/docs/reference/loftest-4.png differ diff --git a/docs/reference/loftest-5.png b/docs/reference/loftest-5.png new file mode 100644 index 00000000..54b176e7 Binary files /dev/null and b/docs/reference/loftest-5.png differ diff --git a/docs/reference/loftest.html b/docs/reference/loftest.html new file mode 100644 index 00000000..757f0bbe --- /dev/null +++ b/docs/reference/loftest.html @@ -0,0 +1,343 @@ + + + + + + + + +Lack-of-fit test for models fitted to data with replicates — loftest • mkin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+
+ + +
+

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)
#> +#> Call: +#> lm(formula = value ~ time, data = test_data_anova) +#> +#> Residuals: +#> Min 1Q Median 3Q Max +#> -6.1000 -0.5625 0.0000 0.5625 6.1000 +#> +#> Coefficients: +#> Estimate Std. Error t value Pr(>|t|) +#> (Intercept) 103.150 2.323 44.409 7.44e-12 *** +#> time1 -19.950 3.285 -6.073 0.000185 *** +#> time3 -50.800 3.285 -15.465 8.65e-08 *** +#> time7 -68.500 3.285 -20.854 6.28e-09 *** +#> time14 -79.750 3.285 -24.278 1.63e-09 *** +#> time28 -86.000 3.285 -26.181 8.35e-10 *** +#> time60 -94.900 3.285 -28.891 3.48e-10 *** +#> time90 -98.500 3.285 -29.986 2.49e-10 *** +#> time120 -100.450 3.285 -30.580 2.09e-10 *** +#> --- +#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 +#> +#> Residual standard error: 3.285 on 9 degrees of freedom +#> Multiple R-squared: 0.9953, Adjusted R-squared: 0.9912 +#> F-statistic: 240.5 on 8 and 9 DF, p-value: 1.417e-09 +#>
logLik(anova_fit) # We get the same likelihood and degrees of freedom
#> 'log Lik.' -40.71015 (df=10)
# +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")
#> Successfully compiled differential equation model from auto-generated C code.
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)
#> Likelihood ratio test +#> +#> Model 1: ANOVA with error model const +#> Model 2: m_synth_SFO_lin with error model const and fixed parameter(s) M1_0, M2_0 +#> #Df LogLik Df Chisq Pr(>Chisq) +#> 1 28 -93.606 +#> 2 7 -171.927 -21 156.64 < 2.2e-16 *** +#> --- +#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# +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")
#> Successfully compiled differential equation model from auto-generated C code.
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)
#> Likelihood ratio test +#> +#> Model 1: ANOVA with error model const +#> Model 2: m_synth_SFO_par with error model const and fixed parameter(s) M1_0, M2_0 +#> #Df LogLik Df Chisq Pr(>Chisq) +#> 1 28 -93.606 +#> 2 7 -156.331 -21 125.45 < 2.2e-16 *** +#> --- +#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# +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")
#> 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)
#> +#> Call: +#> lm(formula = observed ~ time:variable - 1, data = test_data_anova_2) +#> +#> Residuals: +#> Min 1Q Median 3Q Max +#> -6.1000 -0.5875 0.0000 0.5875 6.1000 +#> +#> Coefficients: (2 not defined because of singularities) +#> Estimate Std. Error t value Pr(>|t|) +#> time0:variableparent 103.150 1.573 65.562 < 2e-16 *** +#> time1:variableparent 83.200 1.573 52.882 < 2e-16 *** +#> time3:variableparent 52.350 1.573 33.274 < 2e-16 *** +#> time7:variableparent 34.650 1.573 22.024 < 2e-16 *** +#> time14:variableparent 23.400 1.573 14.873 6.35e-14 *** +#> time28:variableparent 17.150 1.573 10.901 5.47e-11 *** +#> time60:variableparent 8.250 1.573 5.244 1.99e-05 *** +#> time90:variableparent 4.650 1.573 2.956 0.006717 ** +#> time120:variableparent 2.700 1.573 1.716 0.098507 . +#> time0:variableM1 NA NA NA NA +#> time1:variableM1 11.850 1.573 7.532 6.93e-08 *** +#> time3:variableM1 22.700 1.573 14.428 1.26e-13 *** +#> time7:variableM1 33.050 1.573 21.007 < 2e-16 *** +#> time14:variableM1 31.250 1.573 19.863 < 2e-16 *** +#> time28:variableM1 18.900 1.573 12.013 7.02e-12 *** +#> time60:variableM1 7.550 1.573 4.799 6.28e-05 *** +#> time90:variableM1 3.850 1.573 2.447 0.021772 * +#> time120:variableM1 2.050 1.573 1.303 0.204454 +#> time0:variableM2 NA NA NA NA +#> time1:variableM2 6.700 1.573 4.259 0.000254 *** +#> time3:variableM2 16.750 1.573 10.646 8.93e-11 *** +#> time7:variableM2 25.800 1.573 16.399 6.89e-15 *** +#> time14:variableM2 28.600 1.573 18.178 6.35e-16 *** +#> time28:variableM2 25.400 1.573 16.144 9.85e-15 *** +#> time60:variableM2 21.600 1.573 13.729 3.81e-13 *** +#> time90:variableM2 17.800 1.573 11.314 2.51e-11 *** +#> time120:variableM2 14.100 1.573 8.962 2.79e-09 *** +#> --- +#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 +#> +#> Residual standard error: 2.225 on 25 degrees of freedom +#> Multiple R-squared: 0.9979, Adjusted R-squared: 0.9957 +#> F-statistic: 469.2 on 25 and 25 DF, p-value: < 2.2e-16 +#>
# } +
+
+ +
+ + +
+ + +
+

Site built with pkgdown 1.4.1.

+
+ +
+
+ + + + + + + + -- 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 --- docs/reference/index.html | 2 +- docs/reference/lrtest.mkinfit.html | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'docs/reference') 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

-

lrtest(<mkinfit>)

+

lrtest(<mkinfit>) lrtest(<mmkin>)

Likelihood ratio test for mkinfit models

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, ...)
+lrtest(object, object_2 = NULL, ...) + +# S3 method for mmkin +lrtest(object, ...)

Arguments

- + -- 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 --- docs/reference/aw.html | 214 ++++++++++++++++++++++++++++++++++++++++++++++ docs/reference/index.html | 6 ++ 2 files changed, 220 insertions(+) create mode 100644 docs/reference/aw.html (limited to 'docs/reference') diff --git a/docs/reference/aw.html b/docs/reference/aw.html new file mode 100644 index 00000000..b6f3ce48 --- /dev/null +++ b/docs/reference/aw.html @@ -0,0 +1,214 @@ + + + + + + + + +Calculate Akaike weights for model averaging — aw • mkin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+
+ + +
+

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 mkinfit object

An mkinfit object, or an mmkin column +object containing two fits to the same data.

object_2
+ + + + + + + + + +
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

+ +

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)
#> [1] 1
aw_sfo_dfop # SFO gets more weight as it has less parameters and a similar fit
#> [1] 0.5970258 0.4029742
f <- mmkin(c("SFO", "FOMC", "DFOP"), list("FOCUS D" = FOCUS_2006_D), cores = 1, quiet = TRUE) +aw(f)
#> [1] 0.4808722 0.1945539 0.3245740
sum(aw(f))
#> [1] 1
aw(f[c("SFO", "DFOP")])
#> [1] 0.5970258 0.4029742
# } +
+ + + + + +
+ + +
+

Site built with pkgdown 1.4.1.

+
+ +
+ + + + + + + + + diff --git a/docs/reference/index.html b/docs/reference/index.html index 4398469b..3d417267 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -233,6 +233,12 @@ more datasets

with mkinfit

+ +

aw()

+ +

Calculate Akaike weights for model averaging

+ +

CAKE_export()

-- 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 --- docs/reference/aw.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'docs/reference') 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 & Research 33(2) 261-304

Examples

# \dontrun{ -- 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" --- docs/reference/index.html | 2 +- docs/reference/sigma_twocomp.html | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/reference') 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

sigma_twocomp()

-

Two component error model

+

Two-component error model

diff --git a/docs/reference/sigma_twocomp.html b/docs/reference/sigma_twocomp.html index d95e1c28..1795e6c3 100644 --- a/docs/reference/sigma_twocomp.html +++ b/docs/reference/sigma_twocomp.html @@ -6,7 +6,7 @@ -Two component error model — sigma_twocomp • mkin +Two-component error model — sigma_twocomp • mkin @@ -35,7 +35,7 @@ - + @@ -70,7 +70,7 @@ dependence of the measured value \(y\):" /> mkin - 0.9.49.6 + 0.9.49.8
@@ -128,7 +128,7 @@ dependence of the measured value \(y\):" />
-- 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 --- docs/reference/plot.mmkin.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'docs/reference') 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.

ymax

Maximum y axis value for plot.mkinfit.

...

Further arguments passed to plot.mkinfit and -- 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 --- docs/reference/index.html | 2 +- docs/reference/parms.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/reference') diff --git a/docs/reference/index.html b/docs/reference/index.html index 73dfbe4c..6ccc9255 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -67,7 +67,7 @@ mkin - 0.9.49.8 + 0.9.49.9 diff --git a/docs/reference/parms.html b/docs/reference/parms.html index e3c52c53..2162fdc0 100644 --- a/docs/reference/parms.html +++ b/docs/reference/parms.html @@ -71,7 +71,7 @@ considering the error structure that was assumed for the fit." /> mkin - 0.9.49.8 + 0.9.49.9 -- cgit v1.2.1