oecd-tg305 r-package bcmfr r-package bcmf… · 1 introduction ... 2 potential future updates of...

48
1 OECD-TG305 R-Package bcmfR User Guide (v0.3-2) [email protected] 2016-12-09

Upload: vandat

Post on 14-Mar-2018

222 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

1

OECD-TG305 R-Package bcmfR User Guide (v0.3-2)

[email protected]

2016-12-09

Page 2: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

2

CONTENTS 1 Introduction ............................................................................................................................................................. 3

2 Installation ............................................................................................................................................................... 4

2.1 Installing R and RStudio ............................................................................................................................... 4

2.2 R-packages needed by bcmfR .................................................................................................................... 4

2.3 Installing bcmfR Version 0.3-2.................................................................................................................. 5

3 Input files for bcmfR ............................................................................................................................................ 7

3.1 YAML metadata part .................................................................................................................................... 7

3.2 CSV data part ................................................................................................................................................ 8

3.3 Required input parameters for the Aqueous Exposure test ........................................................................... 9

3.4 Required input parameters Dietary Exposure test ......................................................................................... 9

4 Running bcmfR reproducibly ............................................................................................................................. 11

4.1 Aqueous Exposure Test Run Notebook ...................................................................................................... 11

4.2 Dietary Exposure Test Run Notebook ........................................................................................................ 22

5 Appendix ............................................................................................................................................................... 34

5.1 Description File ........................................................................................................................................... 34

5.2 Background on the Input File for BcfmR. ................................................................................................... 34

5.2.1 YAML metadata part...................................................................................................................... 34

5.2.2 CSV data part ................................................................................................................................. 36

5.3 Aqueous Exposure test data file (.csvy) ...................................................................................................... 37

5.4 Dietary Exposure test data file (.csvy) ........................................................................................................ 39

5.5 Aqueous Exposure Test R Script ................................................................................................................ 41

5.6 Dietary Exposure Test R Script ................................................................................................................... 44

5.7 Personalisation of R-settings ....................................................................................................................... 46

5.7.1 Change configuration after installing R ......................................................................................... 46

5.7.2 Change working directory in RStudio ............................................................................................ 47

5.7.3 Installing development versions of packages in RStudio ............................................................... 48

Page 3: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

3

1 INTRODUCTION The OECD Test Guideline 305 (Bioaccumulation in Fish: Aqueous and Dietary Exposure) and the accompanying Guidance Document (Guidance document to OECD TG 305)1 describe different parameters that can be derived from data collected in a test that is performed according to OECD Test Guideline 305. The R-package bcmfR was developed to assist in deriving these parameters by implementing the mathematical/statistical models that are put forward in these documents.

This User Guide describes the installation and use of the R-package bcmfR (Version 0.3-2)2.

Chapter 2 explains the installation procedures for R, R Studio, and several R-packages that are required by the R-package bcmfR. Chapter 3 shows the compilation of input files, and finally Chapter 4 shows how to actually run the script and regain the output for the aqueous exposure test (section 4.1) and the dietary exposure test (section 4.2).

Package bcmfR is not available on the R archive site ‘CRAN’, yet, and can be regarded for now as an in development version.

If you use the package for research or guidance purposes, and would like to communicate any findings, bugs, or suggestions for improvement, then please send an email to the maintainer of the package (see the DESCRIPTION file of the package, reproduced in Appendix 5.1)3.

1 Both OECD Test Guideline 305 (Bioaccumulation in Fish: Aqueous and Dietary Exposure) and the

accompanying Guidance Document (Guidance document to OECD TG 305) are available at the OECD public website (www.oecd.org/env/ehs/testing).

2 Potential future updates of the R-package bcmfR will be made available via the OECD public website (www.oecd.org/env/ehs/testing).

3 Before considering to install or run any software that is mentioned in this document, notice that both R, and the present R-package bcmfR, come with ABSOLUTELY NO WARRANTY.

Page 4: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

4

2 INSTALLATION To be able to use the bcmfR package different types of software need to be installed:

1. The statistical software packages ‘R’ and ‘RStudio’. 2. Several R-packages that are used by the bcmfR package. 3. The bcmfR package itself.

Each of these installations requires a different approach. These are further explained in the next sections of this chapter. In principle, installation of these different types of software is needed only once.

2.1 INSTALLING R AND RSTUDIO To use the bcmfR package, the statistical software package ‘R’ needs to be installed (version 3.3.24). In addition, it is recommended to have installed the ‘RStudio’ IDE (Integrated Development Environment) program (version 1.0.44).

The latest version of R can be found here: https://www.r-project.org/

The latest version of R Studio can be found here: https://www.rstudio.com/

Guidance on how to install R and RStudio (under Windows5) is given in a 15-minute video by Sagar Nikam:

https://www.youtube.com/watch?v=MFfRQuQKGYg

The video also provides a short introduction to R/RStudio, e.g. on how to type code and where to expect the answer. For a first introduction to R/RStudio, this is a good place to start. The video is from February 2013, so the R and RStudio versions demonstrated in the video are somewhat outdated, and current versions may look slightly different. Nevertheless, most of the content is still valid for current versions.

From Windows 7 onwards, you may want to select the 64-bit version of R, in addition to, or instead of, the 32-bit version. RStudio will automatically run the 64-bit version, when installed. Appendix 5.5.1 shows some options for further personalisation of the configurations for R.

2.2 R-PACKAGES NEEDED BY bcmfR To ensure that the R-package bcmfR runs smoothly, some additional R-compatible packages that are required by the R-package bcmfR need to be installed in R as well:

car (version 2.1-3Error! Bookmark not defined.)

stringr (version 1.0.0Error! Bookmark not defined.)

lucid (version 1.4Error! Bookmark not defined.)

nlstools (version 1.0-2Error! Bookmark not defined.)

ggplot2 (version 2.0.0Error! Bookmark not defined.)

ggthemes (version 3.3.0Error! Bookmark not defined.)

rio (version 0.4.16Error! Bookmark not defined.)

4 Version release numbers in this manual refer to numbers for which it was verified at the time of writing

(December 2016) the manual that the R-package bcmfR (Version 0.3-2) runs correctly. That does not mean that it will not work on newer version of R or its packages, but as the software is open source and continuously under development, some functionalities may disappear in newer versions, in particular in certain packages.

5 R and RStudio are also available for Apple iOS and Linux-based computers (in principle, the current package should work on those platforms as well, but this has not been tested yet). YouTube provides instruction videos for those platforms as well.

Page 5: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

5

To learn how to install an R package, the video by thenewboston may be useful:

https://www.youtube.com/watch?v=LUhU_GX6fys

As shown in the video, recent versions of the packages can be installed from the CRAN archive network. When installing a package, ensure that the box “Install dependencies” is checked. This ensures that other packages that are needed for a certain package will be installed as well (see also Appendix 5.7.3 on installing packages).

In general, installing packages needs to be done only once (unless they are actively uninstalled).

To ensure that a package is installed, check the Packages tab in the lower right main panel in RStudio:

All packages that are installed are listed here.

To activate a certain package, the tick-box on the left needs to be checked:

2.3 INSTALLING bcmfR VERSION 0.3-2 The R-package bcmfR is intended to be distributed through CRAN and its mirror sites in the near future, but for now, bcmfR is distributed as a so-called local .zip archive package file. This is a binary form of the R-package bcmfR, only for the Windows operating system. For other operating systems the package will not be available until it is on CRAN. The current .zip archive package file has the advantage that it can be easily distributed (e.g. via email, or on a data stick) 6.

Such a local .zip archive package file requires a slightly different installation than installing from CRAN.

The file bcmfR_0.3-2.zip needs to be saved on a computer that has R/R Studio installed (e.g. in My Documents). To install the .zip binary package, click on Install of the Packages tab in RStudio, which will open the Install Packages dialog box:

6 This .zip archive package file is made available via the OECD public website (www.oecd.org/env/ehs/testing).

Page 6: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

6

The default option (blue) is Repository (CRAN, CRANextra). But for now choose Package Archive File (.zip; .tar.gz) instead. This allows browsing to the relevant directory (e.g. My Documents) where the file bcmfR_0.3-2.zip can be selected. Clicking the Install button will then install bcmfR as if it came from CRAN and it should appear in the list of packages:

To activate the package, the tick-box on the left needs to be checked.

Page 7: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

7

3 INPUT FILES FOR bcmfR The input file format in bcmfR is a combination of the well-known .csv (comma-separated values) textual file format, preceded by a metadata header specified in YAML (see Appendix 5.2 for details). This combination is indicated as a .csvy file. Two example files, one for aqueous (reproduced in Appendix 5.3) and one for dietary exposure (reproduced in Appendix 5.2) are included in bcmfR 0.3-2. These can be used as a template to quickly define one’s own experimental dataset for BCF or BMF estimation.

3.1 YAML METADATA PART Details on YAML (YAML Ain’t Markup Language) and its rules are given in Appendix 5.2. Here we only describe how to quickly define one’s own dataset for BCF or BMF estimation.

To illustrate this, the YAML section of the example dietary exposure .csvy file is reproduced here in two parts (see Appendix 5.4 for the full reproduction of file ‘TEST-Dietary-RHCB10-22.1ugXpergFood.csvy’). After the first part a short explanation on that part is given before reproducing the second part of the YAML-section.

---

# Dietary Exposure Fish Test

filename: Test-Dietary-RHCB10-22.1ugXpergFood.csvy

# type of experiment

type: Dietary Exposure Fish Test

guideline: OECD 305

# where data came from

data source:

name: DM

origin: OECD Ring

comments:

# test chemical and biological species

chemical:

name: RHCB10

chemical info:

species:

name: Oncorhynchus?

biological info:

As shown above the first part of the file gives the general information on the test and these will generally be very similar between different tests performed in the same test facility. Nevertheless it is encouraged to ensure these data are correctly entered to ensure unambiguous identification of the test data.

Clearly the filename will always change, and usually the test chemical as well. Type of experiment and data source however, will generally not change and also test species will often be the same.

The second part of the YAML-section (shown below) includes more specific details on the test setup (e.g. test duration, exposure concentration, what is measured) as well as some of the outcomes (e.g. fish growth rate and lipid content). These usually have to be adapted for each test as these are essential for the calculations to derive BCF or BMF and related parameters from the test data.

# food concentration and ingestion rate

cfood:

Page 8: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

8

value: 22.10

unit: ugX/gFood

ingestion:

value: 0.03

unit: gFood/gFish/day

# feeding period

tfeed:

value: 13.00

unit: day

# lipid fractions

lipidfood:

value: 15.00

unit: percent

lipidfish:

value: 4.65

unit: percent

# time span of depuration

tdepur:

value: 0.00

unit: day

tend:

value: 28.00

unit: day

# fish growth

kgrowth:

value: 0.0373

unit: 1/day

# measured timeseries

time:

name: Time

unit: day

cfish:

name: CFish

unit: ugX/gFish

---

3.2 CSV DATA PART The actual measurements from the experiments will form the CSV data part of the .csvy file. Assuming these data are stored in MS-Excel in a separate sheet, they can be exported to a .csv file via the Save As command in MS-Excel (https://www.youtube.com/watch?v=aBijHzKyteU).

The idea behind .csvy files is to combine the YAML metadata header with the .csv data, which is shown for the same file used in Section 3.1:

[middle of the file]

Page 9: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

9

cfish:

name: CFish

unit: ugX/gFish

---

Time,CFish

1.0,5.930

1.0,5.050

1.0,4.790

3.0,3.790

3.0,4.530

3.0,2.250

[incomplete]

The triple dash (---) indicates the end of the YAML-part. On the next line the experimental measurements are given in .csv form. Thus, when a .csv file was generated from a possibly larger spreadsheet, the .csv text can easily be copied in after the YAML header.

Note also that we announce the header names, as well as the units of the measured data (as part of the metadata). Now the rio package can read this file in one sweep and it stores the experimental data as ‘attributes’ of the measurement data frame in the R/RStudio session. In this way, the data and its metadata always stay together.

3.3 REQUIRED INPUT PARAMETERS FOR THE AQUEOUS EXPOSURE TEST For the aqueous exposure essential input parameters include the average concentration of the test compound in water (cwater), the time that the exposure phase begins (tstart), the time that the depuration phase begins (tdepur, which equals the time that the exposure phase ends), the time that the depuration phase (and the experiment) ends (tend), the average growth rate (kgrowth) and the average lipid content of the test organisms (lipidfish). These should all be included in the YAML metadata header in the aqueous exposure .csvy input file (see Appendix 5.1) and are shown in RStudio while running bcmfR7:

The test parameters (conditions) are in the same order as those in the input file (see Appendix 5.1). These are exactly the values (and units) to adapt in a .csvy input file for a different aqueous exposure test.

3.4 REQUIRED INPUT PARAMETERS DIETARY EXPOSURE TEST For the dietary exposure essential input parameters include the average concentration of the test compound in food (cfood), the average amount of food ingested (ingestion), the time that the exposure phase ends (tfeed), the average

7 Datasets are made visible by clicking on the dataset icon in the upper right corner of the ‘Environment’ pane

(situated in the upper right corner of your screen).

Page 10: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

10

lipid content of the food (lipidfood), the average lipid content of the test organisms (lipidfish), the time that the depuration phase begins (tdepur), the time that the depuration phase (and the experiment) ends (tend), and the average growth rate (kgrowth). These should all be included in the YAML metadata header in the dietary exposure .csvy input file (see Appendix 5.2) and are shown in RStudio while running bcmfR:

Similar as for the aqueous exposure test, these are the values (and units) to adapt in a .csvy input file for another dietary exposure test.

Page 11: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

11

4 RUNNING bcmfR REPRODUCIBLY The bcmfR package has three calculation modes: Un-transformed, Ln-transformed, and Box-Cox transformed, as explained in the Guidance Document to OECD TG 305, Section 3.4. These transformations are applied to the major response data of interest, i.e. the concentration of chemical in the test organism (cfish). Transformations influence the fit of the models, the uncertainty of the estimates and further predictions. The rationale behind transformations in relation to the supposed error distribution is further discussed in the Guidance Document (Section 3.3).

4.1 AQUEOUS EXPOSURE TEST RUN NOTEBOOK The Aqueous Exposure Test R-script is reproduced in Appendix 5.3. This text has to be copied (as plain ASCII) to a new script file in RStudio, i.e. create an R Script file (under menu File> New File> R Script) and copy the text in the new window.

This file can be saved for later use in the working directory (see Appendix 5.5.2 to change what that directory is).

To ensure that the desired test data are used as input, the script has to be altered around line 22 where the input file is defined:

# --- READ AQUEOUS TEST DATA

readTest_Aqueous("TEST-Aqueous-CRCase3-2.0ugXperLiter.csvy")

# --- SHOW TEST PARAMS

TEST.Aqueous.Param

Here the filename "TEST-Aqueous-CRCase3-2.0ugXperLiter.csvy" should be replaced by the filename of the correct input file that contains the required test data (see Chapter 3 on how to compile these). The input file should be stored in the RStudio working directory (see Appendix 5.5.2 to change what that directory is).

By selecting the few lines indicated above and then clicking the ‘run icon’, it can be checked if the right data are read for further analysis8.

To obtain reproducible output (i.e. a computation that each time it is run on the same input file will generate the same output file) in RStudio, click the Compile Notebook button (see below). There are three output document options (HTML, PDF, MS-Word), all showing similar output:

8 In a similar way other parts of the script can be evaluated line by line or section by section when a line or

section of the script is selected and followed by clicking the ‘run icon’. In most cases, however, one will directly choose to generate an output file.

Page 12: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

12

Based on the MS-Word output document the different steps and output are briefly described below (explanatory text that is not part of the output is outlined to the left)9.

The first part briefly describes the program and scripts that are run:

RUN-Aqueous.R Mon Apr 11 12:59:20 2016

# === BEGIN OF R SCRIPT ==== # __________________________ # # RUN-Aqueous.R # __________________________ # # --- bcmfR [0.3-2] R Script # === LOAD PROGRAM ==== # --- ATTACH PACKAGE library(bcmfR) # --- SHOW PROGRAM VERSION PROG.Version

## [1] "0.3-2"

Then input data are read and test data and parameters (including units) are shown: # === READ DATA ==== # --- READ AQUEOUS TEST DATA readTest_Aqueous("TEST-Aqueous-CRCase3-2.0ugXperLiter.csvy")

## time.data cfish.data ## 1 0.04 10.50 ## 2 0.08 7.73 ## 3 0.17 24.12 ## 4 0.33 128.80 ## 5 1.00 553.70 ## 6 2.00 1105.47 ## 7 4.00 2464.88 ## 8 7.00 3025.53 ## 9 9.00 3195.05 ## 10 11.00 4485.04 ## 11 14.00 4652.28 ## 12 14.04 4167.07 ## 13 14.08 5385.64 ## 14 14.17 6692.33 ## 15 14.33 4674.34 ## 16 15.00 2329.99 ## 17 16.00 3797.43 ## 18 18.00 1328.29 ## 19 21.00 1080.29 ## 20 29.00 438.57 ## 21 35.00 128.83

9 In generating output documents, the rio package aims to minimise the number of pages needed for output,

which may result in figures appearing at a (slightly) different place in the document than expected.

Page 13: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

13

# --- SHOW TEST PARAMS TEST.Aqueous.Param

## value unit ## cwater 2.0000 ugX/L ## tstart 0.0000 day ## tdepur 14.0000 day ## tend 35.0000 day ## kgrowth 0.0373 1/day ## lipidfish 4.6500 percent

The first model fitting uses untransformed data (see Guidance Document, Section 3.4.1 for further details). The fitted k1 (fitk1) and k2 (fitk2) are shown, as well as some further details of the fit:

# === UNTRANSFORMED FIT ==== # --- FIT BCF MODEL fitModel_Aqueous()

## Nonlinear regression model ## model: cfish.data ~ runModel_Aqueous(time.data, cwater, tdepur, fitk1, fitk2) ## data: datacfish ## fitk1 fitk2 ## 451.3105 0.1784 ## residual sum-of-squares: 10797483 ## ## Number of iterations to convergence: 3 ## Achieved convergence tolerance: 2.88e-06

The model diagnostics show results from the Shapiro-Wilk normality test and the Runs test (see Guidance Document, Annex 2, section A2.1.3). In addition a set of four model diagnostic plots is given for further inspection (see Guidance Document, Section 3.4.1 for further details):

# --- MODEL DIAGNOSTICS modelDiag_Aqueous()

Page 14: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

14

## ## ------ ## Shapiro-Wilk normality test ## ## data: stdres ## W = 0.89165, p-value = 0.02419 ## ## ## ------

## ## Runs Test ## ## data: as.factor(run) ## Standard Normal = -1.1114, p-value = 0.2664 ## alternative hypothesis: two.sided

The next step results in a plot that enables visual inspection of the fit through the data points: # --- CALC BEST FIT runBestFit_Aqueous() -> rbf.a.un # --- PLOT BEST FIT plotBestFit_Aqueous()

Page 15: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

15

In a final step confidence limits are calculated and shown in the plot and a summary table is given that shows the different model parameters with their standard error and 95% confidence limits. These include the uptake rate k1 (k1), the depuration rate k2 (k2), the growth corrected depuration rate k2g (k2g), the kinetic BCF (BCFK), the growth corrected kinetic BCF (BCFKg), the growth corrected half life t1/2g (i.e. time until the growth corrected concentration in fish is 50% of the initial concentration in fish; thalfg)10, and the kinetic BCF corrected for growth and lipid content (BCFKgL) (see Guidance Document, Section 3.4.1 for further details):

# --- BAYESIAN BOOTSTRAP bootModel_Aqueous() -> bbm.a.un # --- CALC MODEL CONF LIMITS runConfFit_Aqueous() -> rcf.a.un # --- PLOT MODEL FIT AND CONF LIMITS plotConfFit_Aqueous()

# --- BCF SUMMARY TABLE summaryTable_Aqueous(digits = 5)

## Estimate Std.Error 2.5% 97.5% ## k1 451.31 79.05 296.37 606.25 ## k2 0.178 0.0379 0.1041 0.253 ## k2g 0.141 0.0379 0.0668 0.215 ## BCFK 2529.5 179.68 2177.3 2881.6

10 The growth corrected half life t1/2g is given as output from the R-package, as it is indicated in OECD TG 305

as a required value for reporting.

Page 16: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

16

## BCFKg 3198 369.8 2473.2 3922.8 ## thalfg 4.911 1.3198 2.3238 7.497 ## BCFKgL 3438.7 397.64 2659.4 4218.1

The second model fitting on ln-transformed data (see Guidance Document, Section 3.4.2 for further details), and output is given in a similar way as described above for the untransformed data:

# === LN-TRANSFORMED FIT ==== # --- FIT BCF MODEL fitModel_Aqueous_Ln()

## Nonlinear regression model ## model: ln.cfish.data ~ log(runModel_Aqueous(time.data, cwater, tdepur, fitk1, fitk2) + lnstarter) ## data: datacfish ## fitk1 fitk2 ## 240.3745 0.1277 ## residual sum-of-squares: 7.113 ## ## Number of iterations to convergence: 4 ## Achieved convergence tolerance: 4.556e-07

# --- MODEL DIAGNOSTICS modelDiag_Aqueous_Ln()

## ## ------ ## Shapiro-Wilk normality test ## ## data: stdres ## W = 0.8784, p-value = 0.01364 ##

Page 17: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

17

## ## ------

## ## Runs Test ## ## data: as.factor(run) ## Standard Normal = -2.8764, p-value = 0.004023 ## alternative hypothesis: two.sided

# --- CALC BEST FIT runBestFit_Aqueous_Ln() -> rbf.a.ln # --- PLOT BEST FIT plotBestFit_Aqueous_Ln()

# --- BAYESIAN BOOTSTRAP bootModel_Aqueous_Ln() -> bbm.a.ln # --- CALC MODEL CONF LIMITS runConfFit_Aqueous_Ln() -> rcf.a.ln # --- PLOT MODEL CONF LIMITS plotConfFit_Aqueous_Ln()

To facilitate comparison with the previous fits with untransformed data (see Guidance Document, Section 3.4.3) plots are given that show the data on the original, linear scale:

Page 18: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

18

# --- PLOT BEST FIT ON ORIGINAL SCALE plotInvBestFit_Aqueous_Ln()

# --- PLOT CONF FIT ON ORIGINAL SCALE plotInvConfFit_Aqueous_Ln()

# --- BCF SUMMARY TABLE summaryTable_Aqueous_Ln(digits = 5)

## Estimate Std.Error 2.5% 97.5% ## k1 240.37 42.89 156.31 324.44 ## k2 0.1277 0.0207 0.0872 0.168 ## k2g 0.0904 0.0207 0.0499 0.131 ## BCFK 1882.3 264.29 1364.3 2400.3 ## BCFKg 2658.9 460.31 1756.7 3561.1 ## thalfg 7.6655 1.752 4.2316 11.099 ## BCFKgL 2859 494.96 1888.9 3829.1

The final model fitting uses the Box-Cox optimisation procedure to find an optimum data transformation (see Guidance Document, Section 3.4.4 for further details), for which a Box-Cox plot is given, followed by the optimised lambda estimate:

# === BC-TRANSFORMED FIT ==== # --- BOX-COX PLOT AND LAMBDA ESTIMATE modelTrans_BoxCox_Aqueous() -> lambda.est

Page 19: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

19

# --- SHOW LAMBDA FIT AND CONF LIMITS lambda.est

## fit conflo confup ## 0.3300000 0.1743490 0.5114643

Based on this optimised lambda estimate, the data are transformed and the BCF model is fitted again in a similar way as shown above for the ln-transformed data, including plots that show the data on the original, linear scale:

# --- FIT BCF MODEL fitModel_Aqueous_BoxCox(lambda = lambda.est["fit"])

## Nonlinear regression model ## model: bc.cfish.data ~ car::bcPower(runModel_Aqueous(time.data, cwater, tdepur, fitk1, fitk2) + lnstarter, lambda) ## data: datacfish ## fitk1 fitk2 ## 375.5078 0.1585 ## residual sum-of-squares: 293.6 ## ## Number of iterations to convergence: 3 ## Achieved convergence tolerance: 1.7e-07

# --- MODEL DIAGNOSTICS modelDiag_Aqueous_BoxCox()

Page 20: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

20

## ## ------ ## Shapiro-Wilk normality test ## ## data: stdres ## W = 0.96146, p-value = 0.546 ## ## ## ------

## ## Runs Test ## ## data: as.factor(run) ## Standard Normal = -1.1114, p-value = 0.2664 ## alternative hypothesis: two.sided

# --- CALC BEST FIT runBestFit_Aqueous_BoxCox() -> rbf.a.bc # --- PLOT BEST FIT plotBestFit_Aqueous_BoxCox()

Page 21: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

21

# --- BAYESIAN BOOTSTRAP bootModel_Aqueous_BoxCox() -> bbm.a.bc # --- CALC MODEL CONF LIMITS runConfFit_Aqueous_BoxCox() -> rcf.a.bc # --- PLOT MODEL CONF LIMITS plotConfFit_Aqueous_BoxCox()

# --- PLOT BEST FIT ON ORIGINAL SCALE plotInvBestFit_Aqueous_BoxCox()

Page 22: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

22

# --- PLOT CONF FIT ON ORIGINAL SCALE plotInvConfFit_Aqueous_BoxCox()

# --- BCF SUMMARY TABLE summaryTable_Aqueous_BoxCox(digits = 5)

## Estimate Std.Error 2.5% 97.5% ## k1 375.51 45.75 285.84 465.18 ## k2 0.158 0.0198 0.1197 0.197 ## k2g 0.121 0.0198 0.0824 0.16 ## BCFK 2369.2 177.91 2020.5 2717.9 ## BCFKg 3098.4 295.31 2519.6 3677.2 ## thalfg 5.718 0.934 3.8875 7.549 ## BCFKgL 3331.6 317.54 2709.2 3954

# === END OF R SCRIPT ====

4.2 DIETARY EXPOSURE TEST RUN NOTEBOOK Similar to the aqueous test run described in the previous paragraph, the bcmfR package has three calculation modes for the dietary exposure test run as well (see also the Guidance Document, Section 4.5.3): untransformed, ln-transformed, and Box-Cox transformed. These transformations are applied to the major response data of interest: ‘cfish’, the concentration of chemical in the test organism (fish) during the depuration phase. Transformations influence the fit of the models, the uncertainty of the estimates and of further predictions. The rationale behind transformations in relation to the supposed error distribution is further discussed in the Guidance Document (Section 3.3 and 4.5.2).

The Dietary Exposure Test R-script is reproduced in Appendix 5.4. This text has to be copied (as plain ASCII) to a new script file in RStudio, i.e. create an R script file (under menu File/ New File/ R Script) and copy the text in the new window.

This file can be saved for later use in the working directory (see Appendix 5.5.2 to change what that directory is).

Similar as in the aquatic test run (see Section 4.1 above), to ensure that the desired test data are used as input, the script has to be altered around line 22 where the input file is defined:

# --- READ DIETARY TEST DATA

readTest_Dietary("TEST-Dietary-RHCB10-22.1ugXpergFood.csvy")

# --- SHOW TEST PARAMS

Page 23: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

23

TEST.Dietary.Param

Here the filename "TEST-Dietary-RHCB10-22.1ugXpergFood.csvy" should be replaced by the filename of the correct input file that contains the required test data (see Chapter 3 on how to compile these). The input file should be stored in the RStudio working directory (see Appendix 5.5.2 to change what that directory is).

By selecting the few lines indicated above and then clicking the ‘run icon’, it can be checked if the right data are read for further analysis11.

To obtain reproducible output, that is a computation that each time it is run on the same input file will generate the same output file, then, in RStudio, click the Compile Notebook button. There are three output document options (HTML, PDF, MS-Word), all showing similar output:

Similar to the previous Section on running the Aqueous Test case, the MS-Word output document is reproduced here to briefly describe the different steps and output (explanatory text that is not part of the output is outlined to the left)12.

The first part briefly describes the program and scripts that are run:

RUN-Dietary.R Mon Apr 11 13:23:13 2016

# === BEGIN OF R SCRIPT ==== # __________________________ # # RUN-Dietary.R # __________________________ # # --- bcmfR [0.3-2] R Script # === LOAD PROGRAM ==== # --- ATTACH PACKAGE library(bcmfR) # --- SHOW PROGRAM VERSION PROG.Version

## [1] "0.3-2"

Then input data are read and test data and parameters (including units) are shown:

11 In a similar way other parts of the script can be evaluated line by line or section by section when a line or

section of the script is selected and followed by clicking the ‘run icon’. In most cases, however, one will directly choose to generate an output file.

12 In generating output documents, the rio package aims to minimise the number of pages needed for output, which may result in figures appearing at a (slightly) different place in the document than expected.

Page 24: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

24

# === READ DATA ==== # --- READ DIETARY TEST DATA readTest_Dietary("TEST-Dietary-RHCB10-22.1ugXpergFood.csvy")

## time.data cfish.data ## 1 1 5.930 ## 2 1 5.050 ## 3 1 4.790 ## 4 3 3.790 ## 5 3 4.530 ## 6 3 2.250 ## 7 3 2.800 ## 8 3 4.900 ## 9 7 2.690 ## 10 7 2.300 ## 11 7 3.250 ## 12 7 2.410 ## 13 7 2.700 ## 14 14 1.450 ## 15 14 2.000 ## 16 14 2.980 ## 17 14 1.890 ## 18 14 1.800 ## 19 21 1.440 ## 20 21 1.330 ## 21 21 1.010 ## 22 21 1.110 ## 23 21 1.020 ## 24 28 0.611 ## 25 28 1.040 ## 26 28 0.573 ## 27 28 0.852 ## 28 28 1.150

# --- SHOW TEST PARAMS TEST.Dietary.Param

## value unit ## cfood 22.1000 ugX/gFood ## ingestion 0.0300 gFood/gFish/day ## tfeed 13.0000 day ## lipidfood 15.0000 percent ## lipidfish 4.6500 percent ## tdepur 0.0000 day ## tend 28.0000 day ## kgrowth 0.0373 1/day

The first model fitting uses untransformed data (see Guidance Document, Section 4.5.3.2 for further details). The fitted k1 (fitk1) and k2 (fitk2) are shown, as well as some further details of the fit:

# === UNTRANSFORMED FIT ==== # --- FIT BCF MODEL fitModel_Dietary()

## Nonlinear regression model ## model: cfish.data ~ runModel_Dietary(time.data, fitc0d, fitk2) ## data: datacfish ## fitc0d fitk2 ## 4.92724 0.07047 ## residual sum-of-squares: 10.8 ##

Page 25: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

25

## Number of iterations to convergence: 5 ## Achieved convergence tolerance: 2.219e-06

The model diagnostics show results from the Shapiro-Wilk normality test and the Runs test (see Guidance Document, Annex 2, section A2.1.3) . In addition a set of four model diagnostic plots is given for further inspection (see Guidance Document, Section 3.4.1 for further details):

# --- MODEL DIAGNOSTICS modelDiag_Dietary()

## ## ------ ## Shapiro-Wilk normality test ## ## data: stdres ## W = 0.95334, p-value = 0.24 ## ## ## ------

## ## Runs Test ## ## data: as.factor(run) ## Standard Normal = 0, p-value = 1 ## alternative hypothesis: two.sided

The next step results in a plot that enables visual inspection of the fit through the data points: # --- CALC BEST FIT runBestFit_Dietary() -> rbf.d.un # --- PLOT BEST FIT plotBestFit_Dietary()

Page 26: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

26

In a final step confidence limits are calculated and shown in the plot and a summary table is given that shows the different model parameters with their standard error and 95% confidence limits. These include the concentration in the fish at the start of the experiment (C0d), the depuration rate k2 (k2), the growth corrected depuration rate k2g (k2g), the i[tale rate constant from food (kf), the assimilation efficiency coefficient (alpha), the kinetic BMF (BMFK), the growth corrected kinetic BMF (BMFKg), the growth corrected half life t1/2g (i.e. time until the growth corrected concentration in fish is 50% of the initial concentration in fish; thalfg)13, and the kinetic BMF corrected for growth and lipid content (BMFKgL) (see Guidance Document, Sections 4.5.1 and 4.5.3.2 for further details):

# --- BAYESIAN BOOTSTRAP bootModel_Dietary() -> bbm.d.un # --- CALC MODEL CONF LIMITS runConfFit_Dietary() -> rcf.d.un # --- PLOT MODEL FIT AND CONF LIMITS plotConfFit_Dietary()

# --- BCF SUMMARY TABLE summaryTable_Dietary(digits = 5)

## Estimate Std.Error 2.5% 97.5% ## C0d 4.9272 0.29993 4.3394 5.5151 ## k2 0.070471 0.008513 0.053785 0.087157

13 The growth corrected half life t1/2g is given as output from the R-package, as it is indicated in OECD TG 305

as a required value for reporting.

Page 27: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

27

## k2g 0.033171 0.008513 0.016485 0.049857 ## kf 0.026189 0.0026 0.021092 0.031286 ## alpha 0.87297 0.086682 0.70307 1.0429 ## BMFK 0.37163 0.020211 0.33201 0.41124 ## BMFKg 0.78951 0.13689 0.52121 1.0578 ## thalfg 20.892 5.3619 10.382 31.401 ## BMFKgL 2.5468 0.44158 1.6813 3.4123

The second model fitting on ln-transformed data (see Guidance Document, Section 4.5.3 for further details), and output is given in a similar way as described above for the untransformed data:

# === LN-TRANSFORMED FIT ==== # --- FIT BCF MODEL fitModel_Dietary_Ln()

## Nonlinear regression model ## model: ln.cfish.data ~ log(runModel_Dietary(time.data, fitc0d, fitk2) + lnstarter) ## data: datacfish ## fitc0d fitk2 ## 4.52216 0.06251 ## residual sum-of-squares: 1.515 ## ## Number of iterations to convergence: 0 ## Achieved convergence tolerance: 3.783e-09

# --- MODEL DIAGNOSTICS modelDiag_Dietary_Ln()

## ## ------ ## Shapiro-Wilk normality test ##

Page 28: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

28

## data: stdres ## W = 0.98551, p-value = 0.9557 ## ## ## ------

## ## Runs Test ## ## data: as.factor(run) ## Standard Normal = -0.74677, p-value = 0.4552 ## alternative hypothesis: two.sided

# --- CALC BEST FIT runBestFit_Dietary_Ln() -> rbf.d.ln # --- PLOT BEST FIT plotBestFit_Dietary_Ln()

# --- BAYESIAN BOOTSTRAP bootModel_Dietary_Ln() -> bbm.d.ln # --- CALC MODEL CONF LIMITS runConfFit_Dietary_Ln() -> rcf.d.ln # --- PLOT MODEL CONF LIMITS plotConfFit_Dietary_Ln()

Page 29: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

29

To facilitate comparison with the previous fits with untransformed data (see Guidance Document, Section 4.5.3) plots are given that show the data on the original, linear scale:

# --- PLOT BEST FIT ON ORIGINAL SCALE plotInvBestFit_Dietary_Ln()

# --- PLOT CONF FIT ON ORIGINAL SCALE plotInvConfFit_Dietary_Ln()

# --- BCF SUMMARY TABLE summaryTable_Dietary_Ln(digits = 5)

## Estimate Std.Error 2.5% 97.5% ## C0d 4.5222 0.3506 3.835 5.2093 ## k2 0.062513 0.00477 0.053164 0.07186 ## k2g 0.025213 0.00477 0.015864 0.03456 ## kf 0.022993 0.002311 0.018464 0.02752 ## alpha 0.76643 0.077017 0.61547 0.91738 ## BMFK 0.36781 0.017471 0.33357 0.40205 ## BMFKg 0.91195 0.099939 0.71607 1.1078 ## thalfg 27.486 5.1998 17.295 37.678 ## BMFKgL 2.9418 0.32238 2.3099 3.5737

The final model fitting uses the Box-Cox optimisation procedure to find an optimum data transformation (see Guidance Document, Section 4.5.3.4 for further details), for which a Box-Cox plot is given, followed by the optimised lambda estimate:

Page 30: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

30

# === BC-TRANSFORMED FIT ==== # --- BOX-COX PLOT AND LAMBDA ESTIMATE modelTrans_BoxCox_Dietary() -> lambda.est

# --- SHOW LAMBDA FIT AND CONF LIMITS lambda.est

## fit conflo confup ## 0.0100000 -0.3951205 0.4054187

Based on this optimised lambda estimate, the data are transformed and the BCF model is fitted again in a similar way as shown above for the ln-transformed data, including plots that show the data on the original, linear scale:

# --- FIT BCF MODEL fitModel_Dietary_BoxCox(lambda = lambda.est["fit"])

## Nonlinear regression model ## model: bc.cfish.data ~ car::bcPower(runModel_Dietary(time.data, fitc0d, fitk2) + lnstarter, lambda) ## data: datacfish ## fitc0d fitk2 ## 4.52535 0.06255 ## residual sum-of-squares: 1.536 ## ## Number of iterations to convergence: 1 ## Achieved convergence tolerance: 1.314e-06

# --- MODEL DIAGNOSTICS modelDiag_Dietary_BoxCox()

Page 31: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

31

## ## ------ ## Shapiro-Wilk normality test ## ## data: stdres ## W = 0.98541, p-value = 0.9543 ## ## ## ------

## ## Runs Test ## ## data: as.factor(run) ## Standard Normal = -0.74677, p-value = 0.4552 ## alternative hypothesis: two.sided

# --- CALC BEST FIT runBestFit_Dietary_BoxCox() -> rbf.d.bc # --- PLOT BEST FIT plotBestFit_Dietary_BoxCox()

Page 32: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

32

# --- BAYESIAN BOOTSTRAP bootModel_Dietary_BoxCox() -> bbm.d.bc # --- CALC MODEL CONF LIMITS runConfFit_Dietary_BoxCox() -> rcf.d.bc # --- PLOT MODEL CONF LIMITS plotConfFit_Dietary_BoxCox()

# --- PLOT BEST FIT ON ORIGINAL SCALE plotInvBestFit_Dietary_BoxCox()

Page 33: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

33

# --- PLOT CONF FIT ON ORIGINAL SCALE plotInvConfFit_Dietary_BoxCox()

# --- BCF SUMMARY TABLE summaryTable_Dietary_BoxCox(digits = 5)

## Estimate Std.Error 2.5% 97.5% ## C0d 4.5253 0.34929 3.8407 5.21 ## k2 0.062546 0.004779 0.05318 0.07191 ## k2g 0.025246 0.004779 0.01588 0.03461 ## kf 0.023013 0.002305 0.018496 0.02753 ## alpha 0.76711 0.076827 0.61653 0.91769 ## BMFK 0.36794 0.017431 0.33378 0.40211 ## BMFKg 0.91157 0.1003 0.71498 1.1082 ## thalfg 27.45 5.1958 17.266 37.634 ## BMFKgL 2.9405 0.32355 2.3064 3.5747

# === END OF R SCRIPT ====

Page 34: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

34

5 APPENDIX

5.1 DESCRIPTION FILE R-packages come with a DESCRIPTION file that describes some of the background of the specific package, including a version number and a list of other R-packages that are needed. This information that will be visible on CRAN, once the package will be released.

The current DESCRIPTION file in the R-package bcmfR is reproduced here: Package: bcmfR

Type: Package

Title: Tools for Modeling Bioaccumulation Potential in Fish

Version: 0.3-2

Author: Tom Aldenberg [aut, cre]

Maintainer: Tom Aldenberg <[email protected]>

Description: Implements models for both aqueous and dietary experimental exposure

of chemicals to fish, as proposed in OECD Test Guideline 305. Estimation of

uptake and depuration rate constants, growth correction, kinetic BCF and BMF,

lipid correction, parameter and model confidence limits, and compilation of

OECD TG 305-targeted summary tables with standard errors and uncertainty

estimates.

License: GPL-3

LazyData: TRUE

Imports: car,

stringr,

lucid,

nlstools,

ggplot2,

ggthemes,

rio (>= 0.3.17)

5.2 BACKGROUND ON THE INPUT FILE FOR BCFMR.

5.2.1 YAML metadata part

YAML (YAML Ain’t Markup Language) is a human-friendly markup language to specify metadata, initialization files, markup specifications, etc. (see https://en.wikipedia.org/wiki/YAML for further details).

It is used for simple initializations, e.g. in RStudio itself, and increasingly found being used. Its main advantages are simplicity and readability, but this results in a few strict rules. To illustrate this, part of the Dietary exposure metadata section used in bcmfR is reproduced here:

---

# Dietary Exposure Fish Test

filename: Test-Dietary-RHCB10-22.1ugXpergFood.csvy

# type of experiment

type: Dietary Exposure Fish Test

guideline: OECD 305

# where data came from

Page 35: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

35

data source:

name: DM

origin: OECD Ring

comments:

# test chemical and biological species

chemical:

name: RHCB10

chemical info:

species:

name: Oncorhynchus?

biological info:

# food concentration and ingestion rate

cfood:

value: 22.10

unit: ugX/gFood

ingestion:

value: 0.03

unit: gFood/gFish/day

[not completely listed]

Starting from the beginning of these lines of text, the following rules can be identified:

• The initial triple dash (---) marks a YAML-file and indicates the beginning of the YAML metadata part. The end of the YAML metadata part is indicated by a second triple dash (---).

• Lines with that start with a hash-tag (#) are comments that are not read by the program, but provide additional information to improve readability.

• Where specific fields include specific sub-fields, the indentation is very critical. The sub-fields are indented by four spaces14. For example, the data source: field has three sub-fields (name:, origin:, comments:), each indented by four spaces.

• After every colon (:) a space is obligatory in a name-value pair (e.g. name: RHCB10).

In this way an easily readable file is acquired with a very limited set of special characters (e.g. no <, >, or single and double quotes needed), and very few limitations in names or values (these can contain, e.g. spaces, slashes, question marks, etc.).

Both fields and subfields may be empty and additional (sub) fields may be added as well (e.g. CAS no., life stage), including additional comments (preceded by #). This enables inclusion of additional information on the experiment done (e.g. name of the test chemical, name of the test species, etc.). The comments are not read on input, but additional fields are read (i.e. all lines not preceded by # are read).

The bcmfR package will not use the additional fields, but these may help in distinguishing different datasets. For example, in the current version of bcmfR, the field and subfield: species:

name: Oncorhynchus?

are read by the program, but not used. (This is not due to the question mark.)

The aqueous and dietary exposure example files that are supplied in Appendices 5.1 and 5.2, may be useful as a template for a new dataset. To adapt the files, any plain text editor (e.g. Notepad, or Notepad++15) can be used.

14 The exact number of spaces (in this case four) is not critical, but must match exactly. No TAB characters are

allowed.

Page 36: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

36

5.2.2 CSV data part

The actual measurements from the experiments will form the CSV data part of the .csvy file. Assuming these data are stored in MS-Excel in a separate sheet, they can be exported to a .csv file via the Save As command in MS-Excel (https://www.youtube.com/watch?v=aBijHzKyteU).

The idea behind .csvy files is to combine the YAML metadata header with the .csv data, which is shown for the same file used in Section 3.1:

[middle of the file]

lipidfish:

value: 4.65

unit: percent

# time span of depuration

tdepur:

value: 0.00

unit: day

tend:

value: 28.00

unit: day

# fish growth

kgrowth:

value: 0.0373

unit: 1/day

# measured timeseries

time:

name: Time

unit: day

cfish:

name: CFish

unit: ugX/gFish

---

Time,CFish

1.0,5.930

1.0,5.050

1.0,4.790

3.0,3.790

3.0,4.530

3.0,2.250

[incomplete]

15 Notepad++ (http://notepad-plus-plus.org/) provides possibilities to set specific language formatting (e.g. for

YAML, or R), or to automatically replace a ‘tab’ by 2 or more spaces (in Settings/Preferences/Tab Settings). It has no specific language settings for .csvy files.

Page 37: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

37

There is a second triple dash (---; see also explanation of the YAML rules in Section 3.1), followed by the experimental measurements in .csv form. Thus, when a .csv file was generated from a possibly larger spreadsheet, the .csv text can easily be copied in after the YAML header.

Note also that we announce the header names, as well as the units of the measured data (as part of the metadata). Now the rio package can read this file in one sweep and it stores the experimental data as ‘attributes’ of the measurement data frame in the R/RStudio session. In this way, the data and its metadata always stay together.

Clearly, the responsibility is with the user to combine the right experimental condition metadata with the right measurements, check values and units, and further ensure that the input file is correct.

As indicated in Section 3.1, the Appendices 5.1 and 5.2 list two example input files for test data and metadata for aqueous and dietary exposure, respectively.

5.3 AQUEOUS EXPOSURE TEST DATA FILE (.CSVY) This file can be found in the bcmfR package in the R-library directory of installed packages:

The bcmfR package has a subdirectory, called ‘extdata’, which contains the example test files. One can manually copy it to the intended working directory for further use.

(begin of file) ---

# Aqueous Exposure Fish Test

filename: Test-Aqueous-CRCase3-2.0ugXperLiter.csvy

# test experiment

type: aqueous exposure fish test

guideline: OECD 305

# where data came from

data source:

name: CR

origin:

comments:

# test chemical and biological species

chemical:

name: CRCase3

chemical info:

species:

name: Danio

biological info:

# aqueous exposure

cwater:

value: 2.00

Page 38: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

38

unit: ugX/L

# time events

tstart:

value: 0.00

unit: day

tdepur:

value: 14.00

unit: day

tend:

value: 35.00

unit: day

# fish parameters (both assumed)

kgrowth:

value: 0.0373

unit: 1/day

lipidfish:

value: 4.65

unit: percent

# measured timeseries

time:

name: Time

unit: day

cfish:

name: CFish

unit: ugX/kgW

---

Time,CFish

0.04,10.50

0.08,7.73

0.17,24.12

0.33,128.80

1.00,553.70

2.00,1105.47

4.00,2464.88

7.00,3025.53

9.00,3195.05

11.00,4485.04

14.00,4652.28

14.04,4167.07

14.08,5385.64

14.17,6692.33

14.33,4674.34

15.00,2329.99

16.00,3797.43

18.00,1328.29

21.00,1080.29

Page 39: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

39

29.00,438.57

35.00,128.83

(end of file)

This file is one of the two built-in example test data files that are also available in this release of bcmfR, as built in ‘external’ data. It can be used by invoking in the Console:

> aqua3 <- system.file("extdata", "TEST-Aqueous-CRCase3-2.0ugXperLiter.csvy", package = "bcmfR")

and then insert in the R Script the following to ensure it will be used as the data file. # --- READ AQUEOUS TEST DATA

readTest_Aqueous(aqua3)

5.4 DIETARY EXPOSURE TEST DATA FILE (.CSVY) This file can be found in the bcmfR package in the R-library directory of installed packages:

The bcmfR package has a subdirectory, called ‘extdata’, which contains the example test files. One can manually copy it to the intended working directory for further use.

(begin of file) ---

# Dietary Exposure Fish Test

filename: Test-Dietary-RHCB10-22.1ugXpergFood.csvy

# type of experiment

type: Dietary Exposure Fish Test

guideline: OECD 305

# where data came from

data source:

name: DM

origin: OECD Ring

comments:

# test chemical and biological species

chemical:

name: RHCB10

chemical info:

species:

name: Oncorhynchus?

biological info:

# food concentration and ingestion rate

cfood:

value: 22.10

Page 40: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

40

unit: ugX/gFood

ingestion:

value: 0.03

unit: gFood/gFish/day

# feeding period

tfeed:

value: 13.00

unit: day

# lipid fractions

lipidfood:

value: 15.00

unit: percent

lipidfish:

value: 4.65

unit: percent

# time span of depuration

tdepur:

value: 0.00

unit: day

tend:

value: 28.00

unit: day

# fish growth

kgrowth:

value: 0.0373

unit: 1/day

# measured timeseries

time:

name: Time

unit: day

cfish:

name: CFish

unit: ugX/gFish

---

Time,CFish

1.0,5.930

1.0,5.050

1.0,4.790

3.0,3.790

3.0,4.530

3.0,2.250

3.0,2.800

3.0,4.900

7.0,2.690

Page 41: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

41

7.0,2.300

7.0,3.250

7.0,2.410

7.0,2.700

14.0,1.450

14.0,2.000

14.0,2.980

14.0,1.890

14.0,1.800

21.0,1.440

21.0,1.330

21.0,1.010

21.0,1.110

21.0,1.020

28.0,0.611

28.0,1.040

28.0,0.573

28.0,0.852

28.0,1.150

(end of file)

This file is one of the two built-in example test data files that are also available in this release of bcmfR, as built in ‘external’ data. It can be used by invoking in the Console:

> diet10 <- system.file("extdata", " Test-Dietary-RHCB10-22.1ugXpergFood.csvy", package = "bcmfR")

and then insert in the R Script the following to ensure it will be used as the data file. # --- READ DIETARY TEST DATA

readTest_Dietary(diet10)

5.5 AQUEOUS EXPOSURE TEST R SCRIPT # === BEGIN OF R SCRIPT ====

# __________________________

#

# RUN-Aqueous.R

# __________________________

#

# --- bcmfR [0.3-2] R Script

# === LOAD PROGRAM ====

# --- ATTACH PACKAGE

library(bcmfR)

# --- SHOW PROGRAM VERSION

PROG.Version

# === READ DATA ====

Page 42: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

42

# --- READ AQUEOUS TEST DATA

readTest_Aqueous("TEST-Aqueous-CRCase3-2.0ugXperLiter.csvy")

# --- SHOW TEST PARAMS

TEST.Aqueous.Param

# === UNTRANSFORMED FIT ====

# --- FIT BCF MODEL

fitModel_Aqueous()

# --- MODEL DIAGNOSTICS

modelDiag_Aqueous()

# --- CALC BEST FIT

runBestFit_Aqueous() -> rbf.a.un

# --- PLOT BEST FIT

plotBestFit_Aqueous()

# --- BAYESIAN BOOTSTRAP

bootModel_Aqueous() -> bbm.a.un

# --- CALC MODEL CONF LIMITS

runConfFit_Aqueous() -> rcf.a.un

# --- PLOT MODEL FIT AND CONF LIMITS

plotConfFit_Aqueous()

# --- BCF SUMMARY TABLE

summaryTable_Aqueous(digits = 5)

# === LN-TRANSFORMED FIT ====

# --- FIT BCF MODEL

fitModel_Aqueous_Ln()

# --- MODEL DIAGNOSTICS

modelDiag_Aqueous_Ln()

# --- CALC BEST FIT

runBestFit_Aqueous_Ln() -> rbf.a.ln

# --- PLOT BEST FIT

plotBestFit_Aqueous_Ln()

Page 43: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

43

# --- BAYESIAN BOOTSTRAP

bootModel_Aqueous_Ln() -> bbm.a.ln

# --- CALC MODEL CONF LIMITS

runConfFit_Aqueous_Ln() -> rcf.a.ln

# --- PLOT MODEL CONF LIMITS

plotConfFit_Aqueous_Ln()

# --- PLOT BEST FIT ON ORIGINAL SCALE

plotInvBestFit_Aqueous_Ln()

# --- PLOT CONF FIT ON ORIGINAL SCALE

plotInvConfFit_Aqueous_Ln()

# --- BCF SUMMARY TABLE

summaryTable_Aqueous_Ln(digits = 5)

# === BC-TRANSFORMED FIT ====

# --- BOX-COX PLOT AND LAMBDA ESTIMATE

modelTrans_BoxCox_Aqueous() -> lambda.est

# --- SHOW LAMBDA FIT AND CONF LIMITS

lambda.est

# --- FIT BCF MODEL

fitModel_Aqueous_BoxCox(lambda = lambda.est["fit"])

# --- MODEL DIAGNOSTICS

modelDiag_Aqueous_BoxCox()

# --- CALC BEST FIT

runBestFit_Aqueous_BoxCox() -> rbf.a.bc

# --- PLOT BEST FIT

plotBestFit_Aqueous_BoxCox()

# --- BAYESIAN BOOTSTRAP

bootModel_Aqueous_BoxCox() -> bbm.a.bc

# --- CALC MODEL CONF LIMITS

runConfFit_Aqueous_BoxCox() -> rcf.a.bc

# --- PLOT MODEL CONF LIMITS

plotConfFit_Aqueous_BoxCox()

# --- PLOT BEST FIT ON ORIGINAL SCALE

Page 44: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

44

plotInvBestFit_Aqueous_BoxCox()

# --- PLOT CONF FIT ON ORIGINAL SCALE

plotInvConfFit_Aqueous_BoxCox()

# --- BCF SUMMARY TABLE

summaryTable_Aqueous_BoxCox(digits = 5)

# === END OF R SCRIPT ====

5.6 DIETARY EXPOSURE TEST R SCRIPT # === BEGIN OF R SCRIPT ====

# __________________________

#

# RUN-Dietary.R

# __________________________

#

# --- bcmfR [0.3-2] R Script

# === LOAD PROGRAM ====

# --- ATTACH PACKAGE

library(bcmfR)

# --- SHOW PROGRAM VERSION

PROG.Version

# === READ DATA ====

# --- READ DIETARY TEST DATA

readTest_Dietary("TEST-Dietary-RHCB10-22.1ugXpergFood.csvy")

# --- SHOW TEST PARAMS

TEST.Dietary.Param

# === UNTRANSFORMED FIT ====

# --- FIT BCF MODEL

fitModel_Dietary()

# --- MODEL DIAGNOSTICS

modelDiag_Dietary()

# --- CALC BEST FIT

Page 45: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

45

runBestFit_Dietary() -> rbf.d.un

# --- PLOT BEST FIT

plotBestFit_Dietary()

# --- BAYESIAN BOOTSTRAP

bootModel_Dietary() -> bbm.d.un

# --- CALC MODEL CONF LIMITS

runConfFit_Dietary() -> rcf.d.un

# --- PLOT MODEL FIT AND CONF LIMITS

plotConfFit_Dietary()

# --- BCF SUMMARY TABLE

summaryTable_Dietary(digits = 5)

# === LN-TRANSFORMED FIT ====

# --- FIT BCF MODEL

fitModel_Dietary_Ln()

# --- MODEL DIAGNOSTICS

modelDiag_Dietary_Ln()

# --- CALC BEST FIT

runBestFit_Dietary_Ln() -> rbf.d.ln

# --- PLOT BEST FIT

plotBestFit_Dietary_Ln()

# --- BAYESIAN BOOTSTRAP

bootModel_Dietary_Ln() -> bbm.d.ln

# --- CALC MODEL CONF LIMITS

runConfFit_Dietary_Ln() -> rcf.d.ln

# --- PLOT MODEL CONF LIMITS

plotConfFit_Dietary_Ln()

# --- PLOT BEST FIT ON ORIGINAL SCALE

plotInvBestFit_Dietary_Ln()

# --- PLOT CONF FIT ON ORIGINAL SCALE

plotInvConfFit_Dietary_Ln()

# --- BCF SUMMARY TABLE

summaryTable_Dietary_Ln(digits = 5)

Page 46: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

46

# === BC-TRANSFORMED FIT ====

# --- BOX-COX PLOT AND LAMBDA ESTIMATE

modelTrans_BoxCox_Dietary() -> lambda.est

# --- SHOW LAMBDA FIT AND CONF LIMITS

lambda.est

# --- FIT BCF MODEL

fitModel_Dietary_BoxCox(lambda = lambda.est["fit"])

# --- MODEL DIAGNOSTICS

modelDiag_Dietary_BoxCox()

# --- CALC BEST FIT

runBestFit_Dietary_BoxCox() -> rbf.d.bc

# --- PLOT BEST FIT

plotBestFit_Dietary_BoxCox()

# --- BAYESIAN BOOTSTRAP

bootModel_Dietary_BoxCox() -> bbm.d.bc

# --- CALC MODEL CONF LIMITS

runConfFit_Dietary_BoxCox() -> rcf.d.bc

# --- PLOT MODEL CONF LIMITS

plotConfFit_Dietary_BoxCox()

# --- PLOT BEST FIT ON ORIGINAL SCALE

plotInvBestFit_Dietary_BoxCox()

# --- PLOT CONF FIT ON ORIGINAL SCALE

plotInvConfFit_Dietary_BoxCox()

# --- BCF SUMMARY TABLE

summaryTable_Dietary_BoxCox(digits = 5)

# === END OF R SCRIPT ====

5.7 PERSONALISATION OF R-SETTINGS

5.7.1 Change configuration after installing R

By default the program R is installed in the Program Files folder in a separate folder R that contains a folder that also indicates the version installed (e.g. R-3.3.1).

Page 47: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

47

In this directory, there are several folders: bin, doc, etc, include, library, and so forth.

The etc folder contains a file: console. Edit this file with a text editor, e.g. Notepad++ and change MDI (Multiple Document Interface) to MDI = no, that is: SDI (Single Document Interface).

SDI is more suitable for operating GUI16-dependent R-programs.

In the file Rprofile.site, you might want to change the default paper size (= letter) to A4. And you may set a local CRAN site to install packages:

5.7.2 Change working directory in RStudio

Files needed for or generated from a session in RStudio are stored in the RStudio working directory. A specific directory can be chosen under the menu item Session/Set Working Directory:

16 GUI: Graphical User Interface.

Page 48: OECD-TG305 R-Package bcmfR R-Package bcmf… · 1 Introduction ... 2 Potential future updates of the R-package . ... but as the software is open source and continuously

48

5.7.3 Installing development versions of packages in RStudio

In some cases development versions of packages may need to be installed, which may not be available in CRAN. If this is the case devtools should be activated (see figure below) and the url for the development version should be known.

As an example, the latest development version of rio can be installed from https://github.com/leeper.

To install this version, type in the Console: > install_github("leeper/rio")