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. --- docs/articles/chemCal.html | 117 ++++++++++++++++++++++----------------------- 1 file changed, 58 insertions(+), 59 deletions(-) (limited to 'docs/articles/chemCal.html') 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} +

@@ -216,5 +213,7 @@ s_{\hat{x_s}} = \frac{1}{b_1} \sqrt{\frac{{s_s}^2}{w_s m} + + + -- cgit v1.2.1