From b2779693fad072b6bdf5046ca2f1e9e9655eb5a2 Mon Sep 17 00:00:00 2001
From: Johannes Ranke <jranke@uni-bremen.de>
Date: Thu, 17 Nov 2016 16:59:50 +0100
Subject: Add comments to R code in mkin vignette

---
 vignettes/mkin.Rmd | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

(limited to 'vignettes/mkin.Rmd')

diff --git a/vignettes/mkin.Rmd b/vignettes/mkin.Rmd
index 906b3b01..a3982df9 100644
--- a/vignettes/mkin.Rmd
+++ b/vignettes/mkin.Rmd
@@ -34,14 +34,16 @@ measures for data series within one or more compartments, for parent and
 metabolites.
 
 ```{r, echo = TRUE, cache = TRUE, fig = TRUE, fig.width = 8, fig.height = 7}
-require(mkin)
+library(mkin)
+# Define the kinetic model
 m_SFO_SFO_SFO <- mkinmod(parent = mkinsub("SFO", "M1"),
                          M1 = mkinsub("SFO", "M2"),
                          M2 = mkinsub("SFO"), 
                          use_of_ff = "max", quiet = TRUE)
 
-sampling_times = c(0, 1, 3, 7, 14, 28, 60, 90, 120)
 
+# Produce model predictions using some arbitrary parameters
+sampling_times = c(0, 1, 3, 7, 14, 28, 60, 90, 120)
 d_SFO_SFO_SFO <- mkinpredict(m_SFO_SFO_SFO,
   c(k_parent = 0.03, 
     f_parent_to_M1 = 0.5, k_M1 = log(2)/100, 
@@ -49,17 +51,23 @@ d_SFO_SFO_SFO <- mkinpredict(m_SFO_SFO_SFO,
   c(parent = 100, M1 = 0, M2 = 0),
   sampling_times)
 
-d_SFO_SFO_SFO_err <- add_err(d_SFO_SFO_SFO, function(x) 3, n = 1, seed = 123456789 )
+# Generate a dataset by adding normally distributed errors with 
+# standard deviation 3, for two replicates at each sampling time
+d_SFO_SFO_SFO_err <- add_err(d_SFO_SFO_SFO, reps = 2,
+                             sdfunc = function(x) 3, 
+                             n = 1, seed = 123456789 )
 
+# Fit the model to the dataset
 f_SFO_SFO_SFO <- mkinfit(m_SFO_SFO_SFO, d_SFO_SFO_SFO_err[[1]], quiet = TRUE)
 
+# Plot the results separately for parent and metabolites
 plot_sep(f_SFO_SFO_SFO, lpos = c("topright", "bottomright", "bottomright"))
 ```
 
 # Background
 
 Many approaches are possible regarding the evaluation of chemical degradation
-data.  
+data. 
 
 The now deprecated `kinfit` package [@pkg:kinfit] in `R` [@rcore2016]
 implements the approach recommended in the kinetics report provided by the
-- 
cgit v1.2.1

