aboutsummaryrefslogblamecommitdiff
path: root/docs/add_err.html
blob: 78c69d3e914d343ad2dbc1defa3f47367067d170 (plain) (tree)








































































































































































































                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
<title>add_err. mkin 0.9.44.9000</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="
  Johannes Ranke
">

<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/bootstrap-responsive.css" rel="stylesheet">
<link href="css/highlight.css" rel="stylesheet">
<link href="css/staticdocs.css" rel="stylesheet">

<!--[if lt IE 9]>
  <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>
<script type="text/javascript"
  src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
  </head>

  <body>
    <div class="navbar">
  <div class="navbar-inner">
    <div class="container">
      <a class="brand" href="index.html">mkin 0.9.44.9000</a>
      <div class="nav">
        <ul class="nav">
          <li><a href="index.html">Home</a></li>
          <li><a href="reference.html">Reference</a></li>
        </ul>
      </div>
    </div>
  </div>
</div>


    <div class="container">
      <header>
        
      </header>
      
      <h1>
  Add normally distributed errors to simulated kinetic degradation data
</h1>

<div class="row">
  <div class="span8">
    <h2>Usage</h2>
    <pre><span class="functioncall"><a href='add_err.html'>add_err</a></span><span class="keyword">(</span><span class="symbol">prediction</span><span class="keyword">,</span> <span class="symbol">sdfunc</span><span class="keyword">,</span>
          <span class="argument">n</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">1000</span><span class="keyword">,</span> <span class="argument">LOD</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">0.1</span><span class="keyword">,</span> <span class="argument">reps</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">2</span><span class="keyword">,</span>
          <span class="argument">digits</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">1</span><span class="keyword">,</span> <span class="argument">seed</span>&nbsp;<span class="argument">=</span>&nbsp;<span class="number">NA</span><span class="keyword">)</span></pre>
    
    <h2>Arguments</h2>
    <dl>
      <dt>prediction</dt>
      <dd>
    A prediction from a kinetic model as produced by <code><a href='mkinpredict.html'>mkinpredict</a></code>.
  </dd>
      <dt>sdfunc</dt>
      <dd>
    A function taking the predicted value as its only argument and returning
    a standard deviation that should be used for generating the random error
    terms for this value.
  </dd>
      <dt>n</dt>
      <dd>
    The number of datasets to be generated.
  </dd>
      <dt>LOD</dt>
      <dd>
    The limit of detection (LOD). Values that are below the LOD after adding
    the random error will be set to NA.
  </dd>
      <dt>reps</dt>
      <dd>
    The number of replicates to be generated within the datasets.
  </dd>
      <dt>digits</dt>
      <dd>
    The number of digits to which the values will be rounded.
  </dd>
      <dt>seed</dt>
      <dd>
    The seed used for the generation of random numbers. If NA, the seed 
    is not set.
  </dd>
    </dl>
    
    <div class="Description">
      <h2>Description</h2>

      <p>Normally distributed errors are added to data predicted for a specific
  degradation model using <code><a href='mkinpredict.html'>mkinpredict</a></code>. The variance of the error
  may depend on the predicted value and is specified as a standard deviation.</p>

    </div>

    <div class="Value">
      <h2>Value</h2>

      <p><dl>
  A list of datasets compatible with <code><a href='mmkin.html'>mmkin</a></code>, i.e.
  the components of the list are datasets compatible with 
  <code><a href='mkinfit.html'>mkinfit</a></code>.
</dl></p>

    </div>

    <div class="References">
      <h2>References</h2>

      <p>Ranke J and Lehmann R (2015) To t-test or not to t-test, that is the question. XV Symposium on Pesticide Chemistry 2-4 September 2015, Piacenza, Italy
  http://chem.uft.uni-bremen.de/ranke/posters/piacenza_2015.pdf</p>

    </div>
    
    <h2 id="examples">Examples</h2>
    <pre class="examples"><div class='input'><span class="comment"># The kinetic model</span>
<span class="symbol">m_SFO_SFO</span> <span class="assignement">&lt;-</span> <span class="functioncall"><a href='mkinmod.html'>mkinmod</a></span><span class="keyword">(</span><span class="argument">parent</span> <span class="argument">=</span> <span class="functioncall"><a href='mkinsub.html'>mkinsub</a></span><span class="keyword">(</span><span class="string">"SFO"</span><span class="keyword">,</span> <span class="string">"M1"</span><span class="keyword">)</span><span class="keyword">,</span>
                     <span class="argument">M1</span> <span class="argument">=</span> <span class="functioncall"><a href='mkinsub.html'>mkinsub</a></span><span class="keyword">(</span><span class="string">"SFO"</span><span class="keyword">)</span><span class="keyword">,</span> <span class="argument">use_of_ff</span> <span class="argument">=</span> <span class="string">"max"</span><span class="keyword">)</span></div>
<strong class='message'>Successfully compiled differential equation model from auto-generated C code.</strong>
<div class='input'>
<span class="comment"># Generate a prediction for a specific set of parameters</span>
<span class="symbol">sampling_times</span> <span class="assignement">=</span> <span class="functioncall"><a href='http://www.rdocumentation.org/packages/base/topics/c'>c</a></span><span class="keyword">(</span><span class="number">0</span><span class="keyword">,</span> <span class="number">1</span><span class="keyword">,</span> <span class="number">3</span><span class="keyword">,</span> <span class="number">7</span><span class="keyword">,</span> <span class="number">14</span><span class="keyword">,</span> <span class="number">28</span><span class="keyword">,</span> <span class="number">60</span><span class="keyword">,</span> <span class="number">90</span><span class="keyword">,</span> <span class="number">120</span><span class="keyword">)</span>

<span class="comment"># This is the prediction used for the "Type 2 datasets" on the Piacenza poster</span>
<span class="comment"># from 2015</span>
<span class="symbol">d_SFO_SFO</span> <span class="assignement">&lt;-</span> <span class="functioncall"><a href='mkinpredict.html'>mkinpredict</a></span><span class="keyword">(</span><span class="symbol">m_SFO_SFO</span><span class="keyword">,</span>
                         <span class="functioncall"><a href='http://www.rdocumentation.org/packages/base/topics/c'>c</a></span><span class="keyword">(</span><span class="argument">k_parent</span> <span class="argument">=</span> <span class="number">0.1</span><span class="keyword">,</span> <span class="argument">f_parent_to_M1</span> <span class="argument">=</span> <span class="number">0.5</span><span class="keyword">,</span>
                           <span class="argument">k_M1</span> <span class="argument">=</span> <span class="functioncall"><a href='http://www.rdocumentation.org/packages/base/topics/Log'>log</a></span><span class="keyword">(</span><span class="number">2</span><span class="keyword">)</span><span class="keyword">/</span><span class="number">1000</span><span class="keyword">)</span><span class="keyword">,</span>
                         <span class="functioncall"><a href='http://www.rdocumentation.org/packages/base/topics/c'>c</a></span><span class="keyword">(</span><span class="argument">parent</span> <span class="argument">=</span> <span class="number">100</span><span class="keyword">,</span> <span class="argument">M1</span> <span class="argument">=</span> <span class="number">0</span><span class="keyword">)</span><span class="keyword">,</span>
                         <span class="symbol">sampling_times</span><span class="keyword">)</span>

<span class="comment"># Add an error term with a constant (independent of the value) standard deviation</span>
<span class="comment"># of 10, and generate three datasets</span>
<span class="symbol">d_SFO_SFO_err</span> <span class="assignement">&lt;-</span> <span class="functioncall"><a href='add_err.html'>add_err</a></span><span class="keyword">(</span><span class="symbol">d_SFO_SFO</span><span class="keyword">,</span> <span class="keyword">function</span><span class="keyword">(</span><span class="formalargs">x</span><span class="keyword">)</span> <span class="number">10</span><span class="keyword">,</span> <span class="argument">n</span> <span class="argument">=</span> <span class="number">3</span><span class="keyword">,</span> <span class="argument">seed</span> <span class="argument">=</span> <span class="number">123456789</span> <span class="keyword">)</span>

<span class="comment"># Name the datasets for nicer plotting</span>
<span class="functioncall"><a href='http://www.rdocumentation.org/packages/base/topics/names'>names</a></span><span class="keyword">(</span><span class="symbol">d_SFO_SFO_err</span><span class="keyword">)</span> <span class="assignement">&lt;-</span> <span class="functioncall"><a href='http://www.rdocumentation.org/packages/base/topics/paste'>paste</a></span><span class="keyword">(</span><span class="string">"Dataset"</span><span class="keyword">,</span> <span class="number">1</span><span class="keyword">:</span><span class="number">3</span><span class="keyword">)</span>

<span class="comment"># Name the model in the list of models (with only one member in this case)</span>
<span class="comment"># for nicer plotting later on.</span>
<span class="comment"># Be quiet and use the faster Levenberg-Marquardt algorithm, as the datasets</span>
<span class="comment"># are easy and examples are run often. Use only one core not to offend CRAN</span>
<span class="comment"># checks</span>
<span class="symbol">f_SFO_SFO</span> <span class="assignement">&lt;-</span> <span class="functioncall"><a href='mmkin.html'>mmkin</a></span><span class="keyword">(</span><span class="functioncall"><a href='http://www.rdocumentation.org/packages/base/topics/list'>list</a></span><span class="keyword">(</span><span class="string">"SFO-SFO"</span> <span class="argument">=</span> <span class="symbol">m_SFO_SFO</span><span class="keyword">)</span><span class="keyword">,</span>
                   <span class="symbol">d_SFO_SFO_err</span><span class="keyword">,</span> <span class="argument">cores</span> <span class="argument">=</span> <span class="number">1</span><span class="keyword">,</span>
                   <span class="argument">quiet</span> <span class="argument">=</span> <span class="number">TRUE</span><span class="keyword">,</span> <span class="argument">method.modFit</span> <span class="argument">=</span> <span class="string">"Marq"</span><span class="keyword">)</span>

<span class="functioncall"><a href='http://www.rdocumentation.org/packages/graphics/topics/plot'>plot</a></span><span class="keyword">(</span><span class="symbol">f_SFO_SFO</span><span class="keyword">)</span></div>
<p><img src='add_err-4.png' alt='' width='540' height='400' /></p>
<div class='input'>
<span class="comment"># We would like to inspect the fit for dataset 3 more closely</span>
<span class="comment"># Using double brackets makes the returned object an mkinfit object</span>
<span class="comment"># instead of a list of mkinfit objects, so plot.mkinfit is used</span>
<span class="functioncall"><a href='http://www.rdocumentation.org/packages/graphics/topics/plot'>plot</a></span><span class="keyword">(</span><span class="symbol">f_SFO_SFO</span><span class="keyword">[[</span><span class="number">3</span><span class="keyword">]</span><span class="keyword">]</span><span class="keyword">,</span> <span class="argument">show_residuals</span> <span class="argument">=</span> <span class="number">TRUE</span><span class="keyword">)</span></div>
<p><img src='add_err-6.png' alt='' width='540' height='400' /></p>
<div class='input'>
<span class="comment"># If we use single brackets, we should give two indices (model and dataset),</span>
<span class="comment"># and plot.mmkin is used</span>
<span class="functioncall"><a href='http://www.rdocumentation.org/packages/graphics/topics/plot'>plot</a></span><span class="keyword">(</span><span class="symbol">f_SFO_SFO</span><span class="keyword">[</span><span class="number">1</span><span class="keyword">,</span> <span class="number">3</span><span class="keyword">]</span><span class="keyword">)</span></div>
<p><img src='add_err-8.png' alt='' width='540' height='400' /></p>
<div class='input'></div></pre>
  </div>
  <div class="span4 sidebar">
    <!-- <ul>
      <li>add_err</li>
    </ul>
    <ul>
      <li> manip </li>
    </ul> -->



    <h2>Author</h2>
    
  Johannes Ranke


  </div>
</div>
      
      <footer>
      <p class="pull-right"><a href="#">Back to top</a></p>
<p>Built by <a href="https://github.com/hadley/staticdocs">staticdocs</a>. Styled with <a href="https://getbootstrap.com/2.0.4/">bootstrap</a>.</p>
      </footer>
    </div>
  </body>
</html>

Contact - Imprint