From f4fcef8228ebd5a1a73bc6edc47b5efa259c2e20 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 23 Mar 2022 10:32:36 +0100 Subject: Use 'investr' conditionally in tests, updates Most prominently, a README was added, giving a nice overview for the people visiting the github page, the package page on CRAN, or the online docs at pkgdown.jrwb.de. The maintainer e-mail address was also updated. --- DESCRIPTION | 6 +- GNUmakefile | 9 +- NEWS.md | 3 + README.html | 1011 ++++++++++++-------- README.md | 141 ++- README.rmd | 103 ++ build.log | 2 +- check.log | 20 +- docs/404.html | 117 +-- docs/articles/chemCal.html | 117 ++- .../figure-html/unnamed-chunk-1-1.png | Bin 72545 -> 72561 bytes .../figure-html/unnamed-chunk-2-1.png | Bin 44457 -> 44458 bytes docs/articles/index.html | 109 +-- docs/authors.html | 138 +-- docs/index.html | 159 ++- docs/news/index.html | 161 +--- docs/pkgdown.css | 83 +- docs/pkgdown.js | 4 +- docs/pkgdown.yml | 4 +- docs/reference/calplot.lm-1.png | Bin 71915 -> 71932 bytes docs/reference/calplot.lm.html | 218 ++--- docs/reference/din32645-1.png | Bin 70087 -> 70080 bytes docs/reference/din32645.html | 206 ++-- docs/reference/figures/README-calplot-1.png | Bin 0 -> 39449 bytes docs/reference/index.html | 172 +--- docs/reference/inverse.predict.html | 350 +++---- docs/reference/lod.html | 236 ++--- docs/reference/loq.html | 249 ++--- docs/reference/massart97ex1.html | 123 +-- docs/reference/massart97ex3.html | 276 +++--- docs/reference/rl95_cadmium.html | 119 +-- docs/reference/rl95_toluene.html | 121 +-- docs/reference/utstats14.html | 125 +-- docs/sitemap.xml | 57 ++ man/figures/README-calplot-1.png | Bin 0 -> 39449 bytes test.log | 18 +- tests/testthat/test_compare_investr.R | 10 +- vignettes/chemCal.Rmd | 2 +- 38 files changed, 2037 insertions(+), 2432 deletions(-) create mode 100644 README.rmd create mode 100644 docs/reference/figures/README-calplot-1.png create mode 100644 docs/sitemap.xml create mode 100644 man/figures/README-calplot-1.png diff --git a/DESCRIPTION b/DESCRIPTION index 799a81e..cbf3c38 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,9 +1,9 @@ Package: chemCal -Version: 0.2.2 -Date: 2021-04-15 +Version: 0.2.3 +Date: 2022-03-31 Title: Calibration Functions for Analytical Chemistry Authors@R: c(person("Johannes", "Ranke", role = c("aut", "cre", "cph"), - email = "jranke@uni-bremen.de", + email = "johannes.ranke@jrwb.de", comment = c(ORCID = "0000-0003-4371-6538"))) Suggests: MASS, knitr, testthat, investr, covr, rmarkdown Description: Simple functions for plotting linear diff --git a/GNUmakefile b/GNUmakefile index 9eee6b9..b7404b6 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -18,7 +18,7 @@ pkgfiles = \ man/* \ NAMESPACE \ NEWS.md \ - README.html \ + README.md \ R/* \ tests/* \ tests/testthat* @@ -30,8 +30,9 @@ $(TGZ): $(pkgfiles) vignettes build: $(TGZ) -README.html: README.md - "$(RBIN)/Rscript" -e "rmarkdown::render('README.md', output_format = 'html_document')" +README.html: README.rmd + "$(RBIN)/Rscript" -e "rmarkdown::render('README.rmd', clean = FALSE)" + mv README.knit.md README.md install: build "$(RBIN)/R" CMD INSTALL $(TGZ) @@ -56,7 +57,7 @@ winbuilder: build curl -T $(TGZ) ftp://anonymous@win-builder.r-project.org/R-devel/ test: install - NOT_CRAN=true "$(RBIN)/Rscript" -e 'devtools::test()' 2>&1 | tee test.log + NOT_CRAN=true "$(RBIN)/Rscript" -e 'options(cli.dynamic = TRUE); devtools::test()' 2>&1 | tee test.log sed -i -e "s/\r.*\r//" test.log clean: diff --git a/NEWS.md b/NEWS.md index e4419b6..5e86e24 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +# chemCal 0.2.3 + +- Make the use of the 'investr' package conditional in testthat tests, update maintainer e-mail address # chemCal 0.2.2 diff --git a/README.html b/README.html index b1e366b..47ce3a1 100644 --- a/README.html +++ b/README.html @@ -1,420 +1,677 @@ - + - + + - + - - - -README.utf8 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - + -
- - - - - - - -
-

chemCal - Calibration functions for analytical chemistry

+

chemCal - Calibration functions for analytical chemistry

-

Build Status codecov

-

Static documentation of this R package can be found at https://pkgdown.jrwb.de/chemCal

-
- - - - -
- - - - - - - - - - - +

Build Status codecov

+ + +

Overview

+

chemCal is an R package providing some basic functions for conveniently working with linear calibration curves with one explanatory variable.

+

Installation

+

From within R, get the official chemCal release using

+
install.packages("chemCal")
+

Usage

+

chemCal works with univariate linear models of class lm. Working with one of the datasets coming with chemCal, we can produce a calibration plot using the calplot function:

+

Plotting a calibration

+
library(chemCal)
+m0 <- lm(y ~ x, data = massart97ex3)
+calplot(m0)
+

+

LOD and LOQ

+

If you use unweighted regression, as in the above example, we can calculate a Limit Of Detection (LOD) from the calibration data.

+
lod(m0)
+#> $x
+#> [1] 5.407085
+#> 
+#> $y
+#> [1] 13.63911
+

This is the minimum detectable value (German: Erfassungsgrenze), i.e. the value where the probability that the signal is not detected although the analyte is present is below a specified error tolerance beta (default is 0.05 following the IUPAC recommendation).

+

You can also calculate the decision limit (German: Nachweisgrenze), i.e. the value that is significantly different from the blank signal with an error tolerance alpha (default is 0.05, again following IUPAC recommendations) by setting beta to 0.5.

+
lod(m0, beta = 0.5)
+#> $x
+#> [1] 2.720388
+#> 
+#> $y
+#> [1] 8.314841
+

Furthermore, you can calculate the Limit Of Quantification (LOQ), being defined as the value where the relative error of the quantification given the calibration model reaches a prespecified value (default is 1/3).

+
loq(m0)
+#> $x
+#> [1] 9.627349
+#> 
+#> $y
+#> [1] 22.00246
+

Confidence intervals for measured values

+

Finally, you can get a confidence interval for the values measured using the calibration curve, i.e. for the inverse predictions using the function inverse.predict.

+
inverse.predict(m0, 90)
+#> $Prediction
+#> [1] 43.93983
+#> 
+#> $`Standard Error`
+#> [1] 1.576985
+#> 
+#> $Confidence
+#> [1] 3.230307
+#> 
+#> $`Confidence Limits`
+#> [1] 40.70952 47.17014
+

If you have replicate measurements of the same sample, you can also give a vector of numbers.

+
inverse.predict(m0, c(91, 89, 87, 93, 90))
+#> $Prediction
+#> [1] 43.93983
+#> 
+#> $`Standard Error`
+#> [1] 0.796884
+#> 
+#> $Confidence
+#> [1] 1.632343
+#> 
+#> $`Confidence Limits`
+#> [1] 42.30749 45.57217
+

Reference

+

You can use the R help system to view documentation, or you can have a look at the online documentation.

diff --git a/README.md b/README.md index c60a2f8..2ad063e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,143 @@ +--- +output: github_document +--- + + + + + # chemCal - Calibration functions for analytical chemistry [![](https://www.r-pkg.org/badges/version/chemCal)](https://cran.r-project.org/package=chemCal) -[![Build Status](https://travis-ci.com/jranke/chemCal.svg?branch=master)](https://travis-ci.com/jranke/chemCal) -[![codecov](https://codecov.io/github/jranke/chemCal/branch/master/graphs/badge.svg)](https://codecov.io/github/jranke/chemCal) +[![Build Status](https://travis-ci.com/jranke/chemCal.svg?branch=master)](https://app.travis-ci.com/github/jranke/chemCal) +[![codecov](https://codecov.io/github/jranke/chemCal/branch/master/graphs/badge.svg)](https://codecov.io/github/jranke/chemCal) -Static documentation of this R package can be found at -https://pkgdown.jrwb.de/chemCal +## Overview + +chemCal is an R package providing some basic functions for conveniently working +with linear calibration curves with one explanatory variable. + +## Installation + +From within [R][r-project], get the official chemCal release using + + +```r +install.packages("chemCal") +``` + +## Usage + +chemCal works with univariate linear models of class `lm`. Working with one of +the datasets coming with chemCal, we can produce a calibration plot using the +`calplot` function: + +### Plotting a calibration + + +```r +library(chemCal) +m0 <- lm(y ~ x, data = massart97ex3) +calplot(m0) +``` + +![](man/figures/README-calplot-1.png) + +### LOD and LOQ + +If you use unweighted regression, as in the above example, we can calculate a +Limit Of Detection (LOD) from the calibration data. + + +```r +lod(m0) +#> $x +#> [1] 5.407085 +#> +#> $y +#> [1] 13.63911 +``` +This is the minimum detectable value (German: Erfassungsgrenze), i.e. the +value where the probability that the signal is not detected although the +analyte is present is below a specified error tolerance beta (default is 0.05 +following the IUPAC recommendation). + +You can also calculate the decision limit (German: Nachweisgrenze), i.e. +the value that is significantly different from the blank signal +with an error tolerance alpha (default is 0.05, again following +IUPAC recommendations) by setting beta to 0.5. + + +```r +lod(m0, beta = 0.5) +#> $x +#> [1] 2.720388 +#> +#> $y +#> [1] 8.314841 +``` + +Furthermore, you can calculate the Limit Of Quantification (LOQ), being +defined as the value where the relative error of the quantification given the +calibration model reaches a prespecified value (default is 1/3). + + +```r +loq(m0) +#> $x +#> [1] 9.627349 +#> +#> $y +#> [1] 22.00246 +``` + +### Confidence intervals for measured values + +Finally, you can get a confidence interval for the values +measured using the calibration curve, i.e. for the inverse +predictions using the function `inverse.predict`. + + +```r +inverse.predict(m0, 90) +#> $Prediction +#> [1] 43.93983 +#> +#> $`Standard Error` +#> [1] 1.576985 +#> +#> $Confidence +#> [1] 3.230307 +#> +#> $`Confidence Limits` +#> [1] 40.70952 47.17014 +``` + +If you have replicate measurements of the same sample, +you can also give a vector of numbers. + + +```r +inverse.predict(m0, c(91, 89, 87, 93, 90)) +#> $Prediction +#> [1] 43.93983 +#> +#> $`Standard Error` +#> [1] 0.796884 +#> +#> $Confidence +#> [1] 1.632343 +#> +#> $`Confidence Limits` +#> [1] 42.30749 45.57217 +``` + +## Reference + +You can use the R help system to view documentation, or you can +have a look at the [online documentation][pd-site]. + +[r-project]: https://r-project.org +[pd-site]: https://pkgdown.jrwb.de/chemCal diff --git a/README.rmd b/README.rmd new file mode 100644 index 0000000..6b027f4 --- /dev/null +++ b/README.rmd @@ -0,0 +1,103 @@ +--- +output: github_document +--- + + + +```{r, echo = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.path = "man/figures/README-" +) +``` + +# chemCal - Calibration functions for analytical chemistry + + +[![](https://www.r-pkg.org/badges/version/chemCal)](https://cran.r-project.org/package=chemCal) +[![Build Status](https://travis-ci.com/jranke/chemCal.svg?branch=master)](https://app.travis-ci.com/github/jranke/chemCal) +[![codecov](https://codecov.io/github/jranke/chemCal/branch/master/graphs/badge.svg)](https://codecov.io/github/jranke/chemCal) + + +## Overview + +chemCal is an R package providing some basic functions for conveniently working +with linear calibration curves with one explanatory variable. + +## Installation + +From within [R][r-project], get the official chemCal release using + +```{r, eval = FALSE} +install.packages("chemCal") +``` + +## Usage + +chemCal works with univariate linear models of class `lm`. Working with one of +the datasets coming with chemCal, we can produce a calibration plot using the +`calplot` function: + +### Plotting a calibration + +```{r calplot} +library(chemCal) +m0 <- lm(y ~ x, data = massart97ex3) +calplot(m0) +``` + +### LOD and LOQ + +If you use unweighted regression, as in the above example, we can calculate a +Limit Of Detection (LOD) from the calibration data. + +```{r} +lod(m0) +``` +This is the minimum detectable value (German: Erfassungsgrenze), i.e. the +value where the probability that the signal is not detected although the +analyte is present is below a specified error tolerance beta (default is 0.05 +following the IUPAC recommendation). + +You can also calculate the decision limit (German: Nachweisgrenze), i.e. +the value that is significantly different from the blank signal +with an error tolerance alpha (default is 0.05, again following +IUPAC recommendations) by setting beta to 0.5. + +```{r} +lod(m0, beta = 0.5) +``` + +Furthermore, you can calculate the Limit Of Quantification (LOQ), being +defined as the value where the relative error of the quantification given the +calibration model reaches a prespecified value (default is 1/3). + +```{r} +loq(m0) +``` + +### Confidence intervals for measured values + +Finally, you can get a confidence interval for the values +measured using the calibration curve, i.e. for the inverse +predictions using the function `inverse.predict`. + +```{r} +inverse.predict(m0, 90) +``` + +If you have replicate measurements of the same sample, +you can also give a vector of numbers. + +```{r} +inverse.predict(m0, c(91, 89, 87, 93, 90)) +``` + +## Reference + +You can use the R help system to view documentation, or you can +have a look at the [online documentation][pd-site]. + +[r-project]: https://r-project.org +[pd-site]: https://pkgdown.jrwb.de/chemCal diff --git a/build.log b/build.log index 62f6318..2fe8e6c 100644 --- a/build.log +++ b/build.log @@ -6,5 +6,5 @@ * checking for LF line-endings in source and make files and shell scripts * checking for empty or unneeded directories * re-saving image files -* building ‘chemCal_0.2.2.tar.gz’ +* building ‘chemCal_0.2.3.tar.gz’ diff --git a/check.log b/check.log index 75ef8dc..60e9e39 100644 --- a/check.log +++ b/check.log @@ -1,13 +1,18 @@ * using log directory ‘/home/jranke/git/chemCal/chemCal.Rcheck’ -* using R version 4.0.5 (2021-03-31) +* using R version 4.1.3 (2022-03-10) * using platform: x86_64-pc-linux-gnu (64-bit) * using session charset: UTF-8 * using option ‘--as-cran’ * checking for file ‘chemCal/DESCRIPTION’ ... OK -* this is package ‘chemCal’ version ‘0.2.2’ +* this is package ‘chemCal’ version ‘0.2.3’ * package encoding: UTF-8 -* checking CRAN incoming feasibility ... Note_to_CRAN_maintainers -Maintainer: ‘Johannes Ranke ’ +* checking CRAN incoming feasibility ... NOTE +Maintainer: ‘Johannes Ranke ’ + +New maintainer: + Johannes Ranke +Old maintainer(s): + Johannes Ranke * checking package namespace information ... OK * checking package dependencies ... OK * checking if this is a source package ... OK @@ -52,6 +57,7 @@ Maintainer: ‘Johannes Ranke ’ * checking for unstated dependencies in examples ... OK * checking contents of ‘data’ directory ... OK * checking data for non-ASCII characters ... OK +* checking LazyData ... OK * checking data for ASCII and uncompressed saves ... OK * checking installed files from ‘inst/doc’ ... OK * checking files in ‘vignettes’ ... OK @@ -68,5 +74,9 @@ Maintainer: ‘Johannes Ranke ’ * checking for detritus in the temp directory ... OK * DONE -Status: OK +Status: 1 NOTE +See + ‘/home/jranke/git/chemCal/chemCal.Rcheck/00check.log’ +for details. + diff --git a/docs/404.html b/docs/404.html index 2fb6573..9ea600b 100644 --- a/docs/404.html +++ b/docs/404.html @@ -1,66 +1,27 @@ - - - - + + + + - Page not found (404) • chemCal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - - - -
-
- + +
+ + + - - -
+
+
-
- +
+ + - - diff --git a/docs/articles/chemCal.html b/docs/articles/chemCal.html index 8d18c3a..4e145bf 100644 --- a/docs/articles/chemCal.html +++ b/docs/articles/chemCal.html @@ -19,6 +19,8 @@ + +
+
-
-

-Basic calibration functions

+
+

Basic calibration functions +

The chemCal package was first designed in the course of a lecture and lab course on “Analytics of Organic Trace Contaminants” at the University of Bremen from October to December 2004. In the fall 2005, an email exchange with Ron Wehrens led to the belief that it would be desirable to implement the inverse prediction method given in Massart et al. (1997) since it also covers the case of weighted regression. Studies of the IUPAC orange book and of DIN 32645 (equivalent to ISO 11843), publications by Currie (1997) and the Analytical Method Committee of the Royal Society of Chemistry (Analytical Methods Committee 1989) and a nice paper by Castells and Castillo (Castells and Castillo 2000) provided some further understanding of the matter.

-

At the moment, the package consists of four functions (calplot, lod, loq and inverse.predict), working on univariate linear models of class lm or rlm, plus several datasets for validation.

-

A bug report and the following e-mail exchange on the r-devel mailing list about prediction intervals from weighted regression entailed some further studies on this subject. However, I did not encounter any proof or explanation of the formula cited below yet, so I can’t really confirm that Massart’s method is correct.

+

At the moment, the package consists of four functions (calplot, lod, loq and inverse.predict), working on univariate linear models of class lm or rlm, plus several datasets for validation.

+

A bug report and the following e-mail exchange on the r-devel mailing list about prediction intervals from weighted regression entailed some further studies on this subject. However, I did not encounter any proof or explanation of the formula cited below yet, so I can’t really confirm that Massart’s method is correct.

In fact, in June 2018 I was made aware of the fact that the inverse prediction method implemented in chemCal version 0.1.37 and before did not take the variance of replicate calibration standards about their means into account, nor the number of replicates when calculating the degrees of freedom. Thanks to PhD student Anna Burniol Figols for reporting this issue!

As a consequence, I rewrote inverse.predict not to automatically work with the mean responses for each calibration standard any more. The example calculations from Massart et al. (1997) can still be reproduced when the regression model is calculated using the means of the calibration data as shown below.

-
-

-Usage

+
+

Usage +

When calibrating an analytical method, the first task is to generate a suitable model. If we want to use the chemCal functions, we have to restrict ourselves to univariate, possibly weighted, linear regression so far.

Once such a model has been created, the calibration can be graphically shown by using the calplot function:

-library(chemCal)
-m0 <- lm(y ~ x, data = massart97ex3)
-calplot(m0)
+library(chemCal) +m0 <- lm(y ~ x, data = massart97ex3) +calplot(m0)

As we can see, the scatter increases with increasing x. This is also illustrated by one of the diagnostic plots for linear models provided by R:

-plot(m0, which=3)
+plot(m0, which=3)

Therefore, in Example 8 in Massart et al. (1997), weighted regression is proposed which can be reproduced by the following code. Note that we are building the model on the mean values for each standard in order to be able to reproduce the results given in the book with the current version of chemCal.

-weights <- with(massart97ex3, {
-  yx <- split(y, x)
-  ybar <- sapply(yx, mean)
-  s <- round(sapply(yx, sd), digits = 2)
-  w <- round(1 / (s^2), digits = 3)
+weights <- with(massart97ex3, {
+  yx <- split(y, x)
+  ybar <- sapply(yx, mean)
+  s <- round(sapply(yx, sd), digits = 2)
+  w <- round(1 / (s^2), digits = 3)
 })
-massart97ex3.means <- aggregate(y ~ x, massart97ex3, mean)
+massart97ex3.means <- aggregate(y ~ x, massart97ex3, mean)
 
-m <- lm(y ~ x, w = weights, data = massart97ex3.means)
+m <- lm(y ~ x, w = weights, data = massart97ex3.means)

If we now want to predict a new x value from measured y values, we use the inverse.predict function:

 inverse.predict(m, 15, ws=1.67)
-
## $Prediction
-## [1] 5.865367
-## 
-## $`Standard Error`
-## [1] 0.8926109
-## 
-## $Confidence
-## [1] 2.478285
-## 
-## $`Confidence Limits`
-## [1] 3.387082 8.343652
+
## $Prediction
+## [1] 5.865367
+## 
+## $`Standard Error`
+## [1] 0.8926109
+## 
+## $Confidence
+## [1] 2.478285
+## 
+## $`Confidence Limits`
+## [1] 3.387082 8.343652
 inverse.predict(m, 90, ws = 0.145)
-
## $Prediction
-## [1] 44.06025
-## 
-## $`Standard Error`
-## [1] 2.829162
-## 
-## $Confidence
-## [1] 7.855012
-## 
-## $`Confidence Limits`
-## [1] 36.20523 51.91526
+
## $Prediction
+## [1] 44.06025
+## 
+## $`Standard Error`
+## [1] 2.829162
+## 
+## $Confidence
+## [1] 7.855012
+## 
+## $`Confidence Limits`
+## [1] 36.20523 51.91526

The weight ws assigned to the measured y value has to be given by the user in the case of weighted regression, or alternatively, the approximate variance var.s at this location.

-
-

-Background for inverse.predict -

+
+

Background for inverse.predict +

Equation 8.28 in Massart et al. (1997) gives a general equation for predicting the standard error \(s_{\hat{x_s}}\) for an \(x\) value predicted from measurements of \(y\) according to the linear calibration function \(y = b_0 + b_1 \cdot x\):

\[\begin{equation} s_{\hat{x_s}} = \frac{s_e}{b_1} \sqrt{\frac{1}{w_s m} + \frac{1}{\sum{w_i}} + @@ -203,11 +198,13 @@ s_{\hat{x_s}} = \frac{1}{b_1} \sqrt{\frac{{s_s}^2}{w_s m} +

-

Site built with pkgdown 1.6.1.

+

+

Site built with pkgdown 2.0.2.

@@ -216,5 +213,7 @@ s_{\hat{x_s}} = \frac{1}{b_1} \sqrt{\frac{{s_s}^2}{w_s m} + + + diff --git a/docs/articles/chemCal_files/figure-html/unnamed-chunk-1-1.png b/docs/articles/chemCal_files/figure-html/unnamed-chunk-1-1.png index fc76c68..51f854a 100644 Binary files a/docs/articles/chemCal_files/figure-html/unnamed-chunk-1-1.png and b/docs/articles/chemCal_files/figure-html/unnamed-chunk-1-1.png differ diff --git a/docs/articles/chemCal_files/figure-html/unnamed-chunk-2-1.png b/docs/articles/chemCal_files/figure-html/unnamed-chunk-2-1.png index 605137b..f30d115 100644 Binary files a/docs/articles/chemCal_files/figure-html/unnamed-chunk-2-1.png and b/docs/articles/chemCal_files/figure-html/unnamed-chunk-2-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html index 48a4eca..3e53fde 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -1,66 +1,12 @@ - - - - - - - -Articles • chemCal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Articles • chemCal + + - - - - -
-
- -
- -
+
+
Introduction to chemCal
+
+
-
- +
- - + + diff --git a/docs/authors.html b/docs/authors.html index 476cf5e..694eb5b 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -1,66 +1,12 @@ - - - - - - - -Authors • chemCal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Authors and Citation • chemCal - - + + - - - -
-
-
- -
+
- @@ -129,22 +81,20 @@ -
- +
- - + + diff --git a/docs/index.html b/docs/index.html index a724173..4019484 100644 --- a/docs/index.html +++ b/docs/index.html @@ -25,6 +25,8 @@ + +
-
- +
+ -

Static documentation of this R package can be found at https://pkgdown.jrwb.de/chemCal

+
+

Overview +

+

chemCal is an R package providing some basic functions for conveniently working with linear calibration curves with one explanatory variable.

+
+
+

Installation +

+

From within R, get the official chemCal release using

+
+install.packages("chemCal")
+
+
+

Usage +

+

chemCal works with univariate linear models of class lm. Working with one of the datasets coming with chemCal, we can produce a calibration plot using the calplot function:

+
+

Plotting a calibration +

+
+library(chemCal)
+m0 <- lm(y ~ x, data = massart97ex3)
+calplot(m0)
+

+
+
+

LOD and LOQ +

+

If you use unweighted regression, as in the above example, we can calculate a Limit Of Detection (LOD) from the calibration data.

+
+lod(m0)
+#> $x
+#> [1] 5.407085
+#> 
+#> $y
+#> [1] 13.63911
+

This is the minimum detectable value (German: Erfassungsgrenze), i.e. the value where the probability that the signal is not detected although the analyte is present is below a specified error tolerance beta (default is 0.05 following the IUPAC recommendation).

+

You can also calculate the decision limit (German: Nachweisgrenze), i.e. the value that is significantly different from the blank signal with an error tolerance alpha (default is 0.05, again following IUPAC recommendations) by setting beta to 0.5.

+
+lod(m0, beta = 0.5)
+#> $x
+#> [1] 2.720388
+#> 
+#> $y
+#> [1] 8.314841
+

Furthermore, you can calculate the Limit Of Quantification (LOQ), being defined as the value where the relative error of the quantification given the calibration model reaches a prespecified value (default is 1/3).

+
+loq(m0)
+#> $x
+#> [1] 9.627349
+#> 
+#> $y
+#> [1] 22.00246
+
+
+

Confidence intervals for measured values +

+

Finally, you can get a confidence interval for the values measured using the calibration curve, i.e. for the inverse predictions using the function inverse.predict.

+
+inverse.predict(m0, 90)
+#> $Prediction
+#> [1] 43.93983
+#> 
+#> $`Standard Error`
+#> [1] 1.576985
+#> 
+#> $Confidence
+#> [1] 3.230307
+#> 
+#> $`Confidence Limits`
+#> [1] 40.70952 47.17014
+

If you have replicate measurements of the same sample, you can also give a vector of numbers.

+
+inverse.predict(m0, c(91, 89, 87, 93, 90))
+#> $Prediction
+#> [1] 43.93983
+#> 
+#> $`Standard Error`
+#> [1] 0.796884
+#> 
+#> $Confidence
+#> [1] 1.632343
+#> 
+#> $`Confidence Limits`
+#> [1] 42.30749 45.57217
+
+
+
+

Reference +

+

You can use the R help system to view documentation, or you can have a look at the online documentation.

+
- - + + diff --git a/docs/reference/lod.html b/docs/reference/lod.html index 42fc533..a2d66ce 100644 --- a/docs/reference/lod.html +++ b/docs/reference/lod.html @@ -1,74 +1,19 @@ - - - - - - - -Estimate a limit of detection (LOD) — lod • chemCal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Estimate a limit of detection (LOD) — lod • chemCal - - - - - - - - - - - - - + + -
-
- -
- -
+
-
lod(object, ..., alpha = 0.05, beta = 0.05, method = "default", tol = "default")
+
+
lod(object, ..., alpha = 0.05, beta = 0.05, method = "default", tol = "default")
+
-

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - -
object

A univariate model object of class lm or - rlm +

+

Arguments

+
object
+

A univariate model object of class lm or + rlm with model formula y ~ x or y ~ x - 1, - optionally from a weighted regression.

...

Placeholder for further arguments that might be needed by - future implementations.

alpha

The error tolerance for the decision limit (critical value).

beta

The error tolerance beta for the detection limit.

method

The “default” method uses a prediction interval at the LOD + optionally from a weighted regression.

+
...
+

Placeholder for further arguments that might be needed by + future implementations.

+
alpha
+

The error tolerance for the decision limit (critical value).

+
beta
+

The error tolerance beta for the detection limit.

+
method
+

The “default” method uses a prediction interval at the LOD for the estimation of the LOD, which obviously requires iteration. This is described for example in Massart, p. 432 ff. - The “din” method uses the prediction interval at - x = 0 as an approximation.

tol

When the “default” method is used, the default tolerance + The “din” method uses the prediction interval at + x = 0 as an approximation.

+
tol
+

When the “default” method is used, the default tolerance for the LOD on the x scale is the value of the smallest non-zero standard - divided by 1000. Can be set to a numeric value to override this.

- -

Value

- + divided by 1000. Can be set to a numeric value to override this.

+
+
+

Value

A list containig the corresponding x and y values of the estimated limit of detection of a model used for calibration.

-

Note

- +
+
+

Note

- The default values for alpha and beta are the ones recommended by IUPAC. - The estimation of the LOD in terms of the analyte amount/concentration xD from the LOD in the signal domain SD is done by simply inverting the calibration function (i.e. assuming a known calibration function). - The calculation of a LOD from weighted calibration models requires - a weights argument for the internally used predict.lm + a weights argument for the internally used predict.lm function, which is currently not supported in R.

-

References

- +
+
+

References

Massart, L.M, Vandenginste, B.G.M., Buydens, L.M.C., De Jong, S., Lewi, P.J., Smeyers-Verbeke, J. (1997) Handbook of Chemometrics and Qualimetrics: Part A, Chapter 13.7.8

@@ -202,53 +124,55 @@

Currie, L. A. (1997) Nomenclature in evaluation of analytical methods including detection and quantification capabilities (IUPAC Recommendations 1995). Analytica Chimica Acta 391, 105 - 126.

-

See also

- -

Examples for din32645

- -

Examples

-
m <- lm(y ~ x, data = din32645) -lod(m) -
#> $x -#> [1] 0.08655484 -#> -#> $y -#> [1] 3317.154 -#>
-# The critical value (decision limit, German Nachweisgrenze) can be obtained -# by using beta = 0.5: -lod(m, alpha = 0.01, beta = 0.5) -
#> $x -#> [1] 0.0698127 -#> -#> $y -#> [1] 3155.393 -#>
+
+
+

See also

+

Examples for din32645

+
+ +
+

Examples

+
m <- lm(y ~ x, data = din32645)
+lod(m) 
+#> $x
+#> [1] 0.08655484
+#> 
+#> $y
+#> [1] 3317.154
+#> 
+
+# The critical value (decision limit, German Nachweisgrenze) can be obtained
+# by using beta = 0.5:
+lod(m, alpha = 0.01, beta = 0.5)
+#> $x
+#> [1] 0.0698127
+#> 
+#> $y
+#> [1] 3155.393
+#> 
+
+
+
-
- +
- - + + diff --git a/docs/reference/loq.html b/docs/reference/loq.html index 973b1ff..0960251 100644 --- a/docs/reference/loq.html +++ b/docs/reference/loq.html @@ -1,73 +1,18 @@ - - - - - - - -Estimate a limit of quantification (LOQ) — loq • chemCal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Estimate a limit of quantification (LOQ) — loq • chemCal - - - - - - - - - - - - - + + -
-
- -
- -
+
-
loq(object, ..., alpha = 0.05, k = 3, n = 1, w.loq = "auto",
-    var.loq = "auto", tol = "default")
+
+
loq(object, ..., alpha = 0.05, k = 3, n = 1, w.loq = "auto",
+    var.loq = "auto", tol = "default")
+
-

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
object

A univariate model object of class lm or - rlm +

+

Arguments

+
object
+

A univariate model object of class lm or + rlm with model formula y ~ x or y ~ x - 1, optionally from a weighted regression. If weights are specified in the model, either w.loq or var.loq have to - be specified.

alpha

The error tolerance for the prediction of x values in the calculation.

...

Placeholder for further arguments that might be needed by - future implementations.

k

The inverse of the maximum relative error tolerated at the - desired LOQ.

n

The number of replicate measurements for which the LOQ should be - specified.

w.loq

The weight that should be attributed to the LOQ. Defaults + be specified.

+
alpha
+

The error tolerance for the prediction of x values in the calculation.

+
...
+

Placeholder for further arguments that might be needed by + future implementations.

+
k
+

The inverse of the maximum relative error tolerated at the + desired LOQ.

+
n
+

The number of replicate measurements for which the LOQ should be + specified.

+
w.loq
+

The weight that should be attributed to the LOQ. Defaults to one for unweighted regression, and to the mean of the weights - for weighted regression. See massart97ex3 for + for weighted regression. See massart97ex3 for an example how to take advantage of knowledge about the - variance function.

var.loq

The approximate variance at the LOQ. The default value is - calculated from the model.

tol

The default tolerance for the LOQ on the x scale is the value of the + variance function.

+
var.loq
+

The approximate variance at the LOQ. The default value is + calculated from the model.

+
tol
+

The default tolerance for the LOQ on the x scale is the value of the smallest non-zero standard divided by 1000. Can be set to a - numeric value to override this.

- -

Value

- + numeric value to override this.

+
+
+

Value

The estimated limit of quantification for a model used for calibration.

-

Note

- +
+
+

Note

- IUPAC recommends to base the LOQ on the standard deviation of the signal where x = 0. - The calculation of a LOQ based on weighted regression is non-standard and therefore not tested. Feedback is welcome.

-

See also

- -

Examples for din32645

- -

Examples

-
m <- lm(y ~ x, data = massart97ex1) -loq(m) -
#> $x -#> [1] 13.97764 -#> -#> $y -#> [1] 30.6235 -#>
-# We can get better by using replicate measurements -loq(m, n = 3) -
#> $x -#> [1] 9.971963 -#> -#> $y -#> [1] 22.68539 -#>
+
+
+

See also

+

Examples for din32645

+
+ +
+

Examples

+
m <- lm(y ~ x, data = massart97ex1)
+loq(m)
+#> $x
+#> [1] 13.97764
+#> 
+#> $y
+#> [1] 30.6235
+#> 
+
+# We can get better by using replicate measurements
+loq(m, n = 3)
+#> $x
+#> [1] 9.971963
+#> 
+#> $y
+#> [1] 22.68539
+#> 
+
+
+
-
- +
- - + + diff --git a/docs/reference/massart97ex1.html b/docs/reference/massart97ex1.html index c82bf6f..e5dd85a 100644 --- a/docs/reference/massart97ex1.html +++ b/docs/reference/massart97ex1.html @@ -1,67 +1,12 @@ - - - - - - - -Calibration data from Massart et al. (1997), example 1 — massart97ex1 • chemCal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Calibration data from Massart et al. (1997), example 1 — massart97ex1 • chemCal - - - - + + -
-
- -
- -
+
-
data(massart97ex1)
- - -

Format

+
+
data(massart97ex1)
+
+
+

Format

A dataframe containing 6 observations of x and y data.

-

Source

- +
+
+

Source

Massart, L.M, Vandenginste, B.G.M., Buydens, L.M.C., De Jong, S., Lewi, P.J., Smeyers-Verbeke, J. (1997) Handbook of Chemometrics and Qualimetrics: Part A, Chapter 8.

+
+
-
- +
- - + + diff --git a/docs/reference/massart97ex3.html b/docs/reference/massart97ex3.html index 4cbf7ce..4196882 100644 --- a/docs/reference/massart97ex3.html +++ b/docs/reference/massart97ex3.html @@ -1,67 +1,12 @@ - - - - - - - -Calibration data from Massart et al. (1997), example 3 — massart97ex3 • chemCal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Calibration data from Massart et al. (1997), example 3 — massart97ex3 • chemCal - - - - + + -
-
- -
- -
+
-
massart97ex3
- - -

Format

+
+
massart97ex3
+
+
+

Format

A dataframe containing 6 levels of x values with 5 observations of y for each level.

-

Source

- +
+
+

Source

Massart, L.M, Vandenginste, B.G.M., Buydens, L.M.C., De Jong, S., Lewi, P.J., Smeyers-Verbeke, J. (1997) Handbook of Chemometrics and Qualimetrics: Part A, Chapter 8.

+
-

Examples

-
# For reproducing the results for replicate standard measurements in example 8, -# we need to do the calibration on the means when using chemCal > 0.2 -weights <- with(massart97ex3, { - yx <- split(y, x) - ybar <- sapply(yx, mean) - s <- round(sapply(yx, sd), digits = 2) - w <- round(1 / (s^2), digits = 3) -}) - -massart97ex3.means <- aggregate(y ~ x, massart97ex3, mean) - -m3.means <- lm(y ~ x, w = weights, data = massart97ex3.means) - -# The following concords with the book p. 200 -inverse.predict(m3.means, 15, ws = 1.67) # 5.9 +- 2.5 -
#> $Prediction -#> [1] 5.865367 -#> -#> $`Standard Error` -#> [1] 0.8926109 -#> -#> $Confidence -#> [1] 2.478285 -#> -#> $`Confidence Limits` -#> [1] 3.387082 8.343652 -#>
inverse.predict(m3.means, 90, ws = 0.145) # 44.1 +- 7.9 -
#> $Prediction -#> [1] 44.06025 -#> -#> $`Standard Error` -#> [1] 2.829162 -#> -#> $Confidence -#> [1] 7.855012 -#> -#> $`Confidence Limits` -#> [1] 36.20523 51.91526 -#>
-# The LOD is only calculated for models from unweighted regression -# with this version of chemCal -m0 <- lm(y ~ x, data = massart97ex3) -lod(m0) -
#> $x -#> [1] 5.407085 -#> -#> $y -#> [1] 13.63911 -#>
-# Limit of quantification from unweighted regression -loq(m0) -
#> $x -#> [1] 9.627349 -#> -#> $y -#> [1] 22.00246 -#>
-# For calculating the limit of quantification from a model from weighted -# regression, we need to supply weights, internally used for inverse.predict -# If we are not using a variance function, we can use the weight from -# the above example as a first approximation (x = 15 is close to our -# loq approx 14 from above). -loq(m3.means, w.loq = 1.67) -
#> $x -#> [1] 7.346195 -#> -#> $y -#> [1] 17.90777 -#>
# The weight for the loq should therefore be derived at x = 7.3 instead -# of 15, but the graphical procedure of Massart (p. 201) to derive the -# variances on which the weights are based is quite inaccurate anyway. -
+
+

Examples

+
# For reproducing the results for replicate standard measurements in example 8,
+# we need to do the calibration on the means when using chemCal > 0.2
+weights <- with(massart97ex3, {
+  yx <- split(y, x)
+  ybar <- sapply(yx, mean)
+  s <- round(sapply(yx, sd), digits = 2)
+  w <- round(1 / (s^2), digits = 3)
+})
+
+massart97ex3.means <- aggregate(y ~ x, massart97ex3, mean)
+
+m3.means <- lm(y ~ x, w = weights, data = massart97ex3.means)
+
+# The following concords with the book p. 200
+inverse.predict(m3.means, 15, ws = 1.67)  # 5.9 +- 2.5
+#> $Prediction
+#> [1] 5.865367
+#> 
+#> $`Standard Error`
+#> [1] 0.8926109
+#> 
+#> $Confidence
+#> [1] 2.478285
+#> 
+#> $`Confidence Limits`
+#> [1] 3.387082 8.343652
+#> 
+inverse.predict(m3.means, 90, ws = 0.145) # 44.1 +- 7.9
+#> $Prediction
+#> [1] 44.06025
+#> 
+#> $`Standard Error`
+#> [1] 2.829162
+#> 
+#> $Confidence
+#> [1] 7.855012
+#> 
+#> $`Confidence Limits`
+#> [1] 36.20523 51.91526
+#> 
+
+# The LOD is only calculated for models from unweighted regression
+# with this version of chemCal
+m0 <- lm(y ~ x, data = massart97ex3) 
+lod(m0)
+#> $x
+#> [1] 5.407085
+#> 
+#> $y
+#> [1] 13.63911
+#> 
+
+# Limit of quantification from unweighted regression
+loq(m0)
+#> $x
+#> [1] 9.627349
+#> 
+#> $y
+#> [1] 22.00246
+#> 
+
+# For calculating the limit of quantification from a model from weighted
+# regression, we need to supply weights, internally used for inverse.predict
+# If we are not using a variance function, we can use the weight from
+# the above example as a first approximation (x = 15 is close to our
+# loq approx 14 from above).
+loq(m3.means, w.loq = 1.67)
+#> $x
+#> [1] 7.346195
+#> 
+#> $y
+#> [1] 17.90777
+#> 
+# The weight for the loq should therefore be derived at x = 7.3 instead
+# of 15, but the graphical procedure of Massart (p. 201) to derive the 
+# variances on which the weights are based is quite inaccurate anyway. 
+
+
+
-
- +
- - + + diff --git a/docs/reference/rl95_cadmium.html b/docs/reference/rl95_cadmium.html index 3b311ec..da9294d 100644 --- a/docs/reference/rl95_cadmium.html +++ b/docs/reference/rl95_cadmium.html @@ -1,67 +1,12 @@ - - - - - - - -Cadmium concentrations measured by AAS as reported by Rocke and Lorenzato (1995) — rl95_cadmium • chemCal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Cadmium concentrations measured by AAS as reported by Rocke and Lorenzato (1995) — rl95_cadmium • chemCal - - - - + + -
-
- -
- -
+
- -

Format

- +
+

Format

A dataframe containing four replicate observations for each of the six calibration standards.

-

Source

- +
+
+

Source

Rocke, David M. und Lorenzato, Stefan (1995) A two-component model for measurement error in analytical chemistry. Technometrics 37(2), 176-184.

+
+
-
- +
- - + + diff --git a/docs/reference/rl95_toluene.html b/docs/reference/rl95_toluene.html index 6b2542b..fb071e1 100644 --- a/docs/reference/rl95_toluene.html +++ b/docs/reference/rl95_toluene.html @@ -1,69 +1,14 @@ - - - - - - - -Toluene amounts measured by GC/MS as reported by Rocke and Lorenzato (1995) — rl95_toluene • chemCal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Toluene amounts measured by GC/MS as reported by Rocke and Lorenzato (1995) — rl95_toluene • chemCal - - - - - - - - - - - - - + + -
-
- -
- -
+
- -

Format

- +
+

Format

A dataframe containing four replicate observations for each of the six calibration standards.

-

Source

- +
+
+

Source

Rocke, David M. und Lorenzato, Stefan (1995) A two-component model for measurement error in analytical chemistry. Technometrics 37(2), 176-184.

+
+
-
- +
- - + + diff --git a/docs/reference/utstats14.html b/docs/reference/utstats14.html index a2822fc..78d2604 100644 --- a/docs/reference/utstats14.html +++ b/docs/reference/utstats14.html @@ -1,68 +1,13 @@ - - - - - - - -Example data for calibration with replicates from University of Toronto — utstats14 • chemCal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Example data for calibration with replicates from University of Toronto — utstats14 • chemCal - - - - + + -
-
- -
- -
+
+
-
- +
- - + + diff --git a/docs/sitemap.xml b/docs/sitemap.xml new file mode 100644 index 0000000..5d588da --- /dev/null +++ b/docs/sitemap.xml @@ -0,0 +1,57 @@ + + + + /404.html + + + /articles/chemCal.html + + + /articles/index.html + + + /authors.html + + + /index.html + + + /news/index.html + + + /reference/calplot.lm.html + + + /reference/chemCal-package.html + + + /reference/din32645.html + + + /reference/index.html + + + /reference/inverse.predict.html + + + /reference/lod.html + + + /reference/loq.html + + + /reference/massart97ex1.html + + + /reference/massart97ex3.html + + + /reference/rl95_cadmium.html + + + /reference/rl95_toluene.html + + + /reference/utstats14.html + + diff --git a/man/figures/README-calplot-1.png b/man/figures/README-calplot-1.png new file mode 100644 index 0000000..b71d326 Binary files /dev/null and b/man/figures/README-calplot-1.png differ diff --git a/test.log b/test.log index 1da1e42..9209c63 100644 --- a/test.log +++ b/test.log @@ -1,13 +1,13 @@ -Loading chemCal -Testing chemCal -✔ | OK F W S | Context -✔ | 16 | Compare with investr::calibrate [0.2 s] -✔ | 5 | Known results for the dataset provided in DIN 32645 -✔ | 15 | Inverse predictions -✔ | 8 | LOD and LOQ -✔ | 10 | Known results for the example datasets provided by Massart (1997) +ℹ Loading chemCal +ℹ Testing chemCal +✔ | F W S OK | Context +✔ | 16 | Compare with investr::calibrate +✔ | 5 | Known results for the dataset provided in DIN 32645 +✔ | 15 | Inverse predictions +✔ | 8 | LOD and LOQ +✔ | 10 | Known results for the example datasets provided by Massart (1997) ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 0.4 s +Duration: 0.3 s [ FAIL 0 | WARN 0 | SKIP 0 | PASS 54 ] diff --git a/tests/testthat/test_compare_investr.R b/tests/testthat/test_compare_investr.R index 6191c89..2830679 100644 --- a/tests/testthat/test_compare_investr.R +++ b/tests/testthat/test_compare_investr.R @@ -1,12 +1,12 @@ -context("Compare with investr::calibrate") +if (requireNamespace("investr")) { -library(chemCal) -library(investr) +context("Compare with investr::calibrate") test_that("Unweighted regressions give same results as investr::calibrate using the Wald method", { + compare_investr <- function(object, y_sample) { pred_chemCal <- inverse.predict(object, y_sample) - pred_investr <- calibrate(object, y_sample, interval = "Wald") + pred_investr <- investr::calibrate(object, y_sample, interval = "Wald") expect_equivalent(pred_chemCal[["Prediction"]], pred_investr$estimate) expect_equivalent(pred_chemCal[["Standard Error"]], @@ -28,3 +28,5 @@ test_that("Unweighted regressions give same results as investr::calibrate using m_m3 <- lm(y ~ x, massart97ex3) compare_investr(m_m3, 15) }) + +} diff --git a/vignettes/chemCal.Rmd b/vignettes/chemCal.Rmd index de490f2..5896fac 100644 --- a/vignettes/chemCal.Rmd +++ b/vignettes/chemCal.Rmd @@ -35,7 +35,7 @@ At the moment, the package consists of four functions working on univariate linear models of class `lm` or `rlm`, plus several datasets for validation. -A [bug report](https://bugs.r-project.org/bugzilla/show_bug.cgi?id=8877) +A [bug report](https://bugs.r-project.org/show_bug.cgi?id=8877) and the following e-mail exchange on the r-devel mailing list about prediction intervals from weighted regression entailed some further studies on this subject. However, I did not encounter any proof or explanation of the -- cgit v1.2.1