From 20b9c584e7c43ecbb708459e531c24a1a4751e17 Mon Sep 17 00:00:00 2001
From: Johannes Ranke ‘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
+
Likelihood ratio test for mkinfit models
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, ...)+ +
object | +A model object with a defined loftest method |
+
---|---|
... | +Not used |
+
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.
+lrtest
+# \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 residualsloftest(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 +#>#> '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")#>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 formationloftest(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")#>sfo_par_fit <- mkinfit(m_synth_SFO_par, test_data_2, quiet = TRUE) +plot_res(sfo_par_fit) # much better for metabolitesloftest(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")#>dfop_par_fit <- mkinfit(m_synth_DFOP_par, test_data_2, quiet = TRUE) +plot_res(dfop_par_fit) # No visual lack of fitloftest(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 +#># } +
Likelihood ratio test for mkinfit models
# S3 method for mkinfit -lrtest(object, object_2 = NULL, ...)+lrtest(object, object_2 = NULL, ...) + +# S3 method for mmkin +lrtest(object, ...)
object | -An |
+ An |
||||
---|---|---|---|---|---|---|
object_2 | -- cgit v1.2.1 From c3700bec3a704660d3ade7a54c56b7084beb02b4 Mon Sep 17 00:00:00 2001 From: Johannes Ranke
object | +An mmkin column object, containing two or more
+ |
+
---|---|
... | +Not used in the method for mmkin column objects, +further mkinfit objects in the method for mkinfit objects. |
+
Burnham KP and Anderson DR (2004) Multimodel + Inference: Understanding AIC and BIC in Model Selection + Sociological Methods & Research 33(2) 261-304
+ ++# \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] 1aw_sfo_dfop # SFO gets more weight as it has less parameters and a similar fit#> [1] 0.5970258 0.4029742f <- mmkin(c("SFO", "FOMC", "DFOP"), list("FOCUS D" = FOCUS_2006_D), cores = 1, quiet = TRUE) +aw(f)#> [1] 0.4808722 0.1945539 0.3245740#> [1] 1#> [1] 0.5970258 0.4029742# } +
Calculate Akaike weights for model averaging
plot.mmkin
.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
).compiled_models
. The autogeneration of C code was inspired by the ccSolve
package. Thanks to Karline Soetaert for her work on that.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.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.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.error_model
to the mkinfit
function.error_model = "obs"
.error_model = "obs"
.error_model = "tc"
.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!
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.
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# \dontrun{ -- cgit v1.2.1 From 7ea467e0e0ba5bf51540b26e197869a58ed1a092 Mon Sep 17 00:00:00 2001 From: Johannes RankeDate: 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') 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 - + Two component error model
Two-component error model
sigma_twocomp.Rd
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.
The companion package kinfit (now deprecated) was started in 2008 and first published on CRAN on 01 May 2010.
The first mkin
code was published on 11 May 2010 and the first CRAN version on 18 May 2010.
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.
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 + |
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.
The companion package kinfit (now deprecated) was started in 2008 and first published on CRAN on 01 May 2010.
-- cgit v1.2.1 From 1868c1c6b98afa4c8a11b7c065d717bfb4ec1a8e Mon Sep 17 00:00:00 2001 From: Johannes RankeThe relative height of the middle plot, if more than two rows of plots are shown. |
+ |
ymax | +Maximum y axis value for |
+
---|---|
... | Further arguments passed to 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. |