jranke / mkin Goto Github PK
View Code? Open in Web Editor NEWR package for fitting kinetic models with one or more state variables to chemical degradation data
Home Page: https://pkgdown.jrwb.de/mkin
R package for fitting kinetic models with one or more state variables to chemical degradation data
Home Page: https://pkgdown.jrwb.de/mkin
The parameter optimisation with a water-sediment system model without sediment->sink path does not work.
water_sed_no_sed_sink <- mkinmod(
use_of_ff = "min",
water = mkinsub("SFO", "sediment"),
sediment = mkinsub("SFO", "water", sink = FALSE))
mkinfit(water_sed_no_sed_sink, inputdata, quiet = TRUE)
gives an error:
Error in eval(substitute(expr), data, enclos = parent.frame()) :
object 'k_sediment_sink' not found
Background: mkinmod
uses cfunction
from the inline
package to build a dynamically loadable shared object (called DLL in R) in order to speed up the solution of degradation models (that do not have an analytical solution implemented) with the ode
function of the deSolve
package. When such an object is created and loaded by cfunction
, the corresponding R function has a finalizer attached to its environment which unloads the DLL and removes the corresponding file upon garbage collection, but at the latest when the R session is terminated.
If the knitr
package is used for the preparation of reproducible reports there is a caching feature that stores the results of certain code chunks. These are saved to files that can efficiently be read when necessary in the next rendering of the report by knitr
. However, the DLLs pepared by cfunction
are unavailable if the DLLs were cleaned up in between.
Symptom: When rendering a knitr object that restored an mkinmod
object and this object is needed to do further simulations, the DLL can not be loaded, currently resulting in termination of the report generation with an error message:
Quitting from lines x-y (report.rmd)
Error in dyn.load(get("libLFile", env)) :
unable to load shared object '/tmp/Rtmp....../file...........so':
/tmp/Rtmp....../file.............so: cannot open shared object file: No such file or directory
Possible solutions:
a) trigger a recompile of the DLL whenever such a situation is encountered by a function that is trying to use the expired mkinmod
object (such as mkinfit
or plotting functions)
b) trigger a recompile of the DLL whenever an mkinmod
object is restored from the knitr cache and the DLL is unavailable
c) add the possibility in mkinmod
to store the DLL in a user defined location.
Option a) could be done within the mkinfit
package. However, as it would be triggered by functions working on the restored mkinmod
object, these would either only recompile their local copy or they would need modify an object from outside their usual scope.
Option b) would require understanding more about knitr and and it is not clear to me if it can be done without modifying knitr
Therefore, option c) appears to to be the preferable solution.
One way to achieve this is to fix the functions for saving and restoring DLLs that are present in the inline
package (eddelbuettel/inline#13) and to used the saving function in mkinmod
and the reading function if necessary in the functions working with mkinmod
objects.
This will lead to confusion in the graphical user interface. If you do so by accident, it is recommended to close the respective tab in the browser and to start the user interface again.
For example, when one state variable has a target that is not a state variable, as for example in
my_model <- mkinmod(parent = mkinsub("SFO", c("m1", "m2")),
m1 = mkinsub("SFO"))
where m2 is a target of parent but not a state variable, the error message is:
Error in switch(spec[[target]]$type, SFO = target, IORE = target, SFORB = paste(target, :
EXPR must be a length 1 vector
which is not very helpful for finding the problem.
Should be fixed before releasing 1.0
When loading the FOCUS_2006_Z_gmkin dataset distributed with the package, the fit list is not updated when using Firefox 28 on Windows 7. This works OK with Firefox 29 on Linux and Windows, as well as using Chrome on Windows 7.
When generating datasets with sigma_low
= 0.5 and rsd_high
= 0.07 (as e.g. was done for the synthetic_data_for_UBA_2014
) and using many replicates and no censoring (LOD = -Inf), the fitted components of the error model are still systematically lower than the input parameters of the error model used for generating the data. With 100 or 1000 replicates I get 0.33 instead of 0.5 for sigma_low
and 0.056 instead of 0.07 for rsd_high
.
The parameter estimates of the degradation model, however, are clearly closer to the input parameters when the two-component error model reweighting is applied, just the parameters of the error model cannot be reproduced in the fit at the moment.
Therefore, I am looking for a better way to fit the error model to the residuals.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.