aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2018-07-05 18:44:22 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2018-07-05 18:44:22 +0200
commit9411139beee167c5339e96db448e5dbed19e06bc (patch)
tree1bba625b3a2288c1ede4eefe1c23d3bcfa0f9fcc /tests
parent801e95f1cc7bfcc8480f6f49b9da2331be71d1a9 (diff)
Maintenance in preparation of improvements
- Switch vignette to html - Switch tests to testthat - NEWS.md instead of ChangeLog - Remove names of y in lists returned by lod and loq
Diffstat (limited to 'tests')
-rw-r--r--tests/din32645.R7
-rw-r--r--tests/din32645.Rout.save48
-rw-r--r--tests/massart97.R25
-rw-r--r--tests/massart97.Rout.save128
-rw-r--r--tests/testthat.R4
-rw-r--r--tests/testthat/test_din32645.R33
-rw-r--r--tests/testthat/test_inverse.predict.R43
-rw-r--r--tests/testthat/test_lod_loq.R28
-rw-r--r--tests/testthat/test_massart.R40
9 files changed, 148 insertions, 208 deletions
diff --git a/tests/din32645.R b/tests/din32645.R
deleted file mode 100644
index e5ffed7..0000000
--- a/tests/din32645.R
+++ /dev/null
@@ -1,7 +0,0 @@
-require(chemCal)
-data(din32645)
-m <- lm(y ~ x, data = din32645)
-inverse.predict(m, 3500, alpha = 0.01)
-lod <- lod(m, alpha = 0.01, beta = 0.5)
-lod(m, alpha = 0.01, beta = 0.01)
-loq <- loq(m, alpha = 0.01)
diff --git a/tests/din32645.Rout.save b/tests/din32645.Rout.save
deleted file mode 100644
index 7c9e55d..0000000
--- a/tests/din32645.Rout.save
+++ /dev/null
@@ -1,48 +0,0 @@
-
-R version 3.1.0 (2014-04-10) -- "Spring Dance"
-Copyright (C) 2014 The R Foundation for Statistical Computing
-Platform: x86_64-pc-linux-gnu (64-bit)
-
-R is free software and comes with ABSOLUTELY NO WARRANTY.
-You are welcome to redistribute it under certain conditions.
-Type 'license()' or 'licence()' for distribution details.
-
-R is a collaborative project with many contributors.
-Type 'contributors()' for more information and
-'citation()' on how to cite R or R packages in publications.
-
-Type 'demo()' for some demos, 'help()' for on-line help, or
-'help.start()' for an HTML browser interface to help.
-Type 'q()' to quit R.
-
-> require(chemCal)
-Loading required package: chemCal
-> data(din32645)
-> m <- lm(y ~ x, data = din32645)
-> inverse.predict(m, 3500, alpha = 0.01)
-$Prediction
-[1] 0.1054792
-
-$`Standard Error`
-[1] 0.02215619
-
-$Confidence
-[1] 0.07434261
-
-$`Confidence Limits`
-[1] 0.03113656 0.17982178
-
-> lod <- lod(m, alpha = 0.01, beta = 0.5)
-> lod(m, alpha = 0.01, beta = 0.01)
-$x
-[1] 0.132909
-
-$y
- 1
-3765.025
-
-> loq <- loq(m, alpha = 0.01)
->
-> proc.time()
- user system elapsed
- 0.472 0.302 0.354
diff --git a/tests/massart97.R b/tests/massart97.R
deleted file mode 100644
index 00f837f..0000000
--- a/tests/massart97.R
+++ /dev/null
@@ -1,25 +0,0 @@
-require(chemCal)
-data(massart97ex1)
-m <- lm(y ~ x, data = massart97ex1)
-inverse.predict(m, 15) # 6.1 +- 4.9
-inverse.predict(m, 90) # 43.9 +- 4.9
-inverse.predict(m, rep(90,5)) # 43.9 +- 3.2
-
-data(massart97ex3)
-attach(massart97ex3)
-yx <- split(y, x)
-ybar <- sapply(yx, mean)
-s <- round(sapply(yx, sd), digits = 2)
-w <- round(1 / (s^2), digits = 3)
-weights <- w[factor(x)]
-m <- lm(y ~ x, w = weights)
-#calplot(m)
-
-inverse.predict(m, 15, ws = 1.67) # 5.9 +- 2.5
-inverse.predict(m, 90, ws = 0.145) # 44.1 +- 7.9
-
-m0 <- lm(y ~ x)
-lod(m0)
-
-loq(m0)
-loq(m, w.loq = 1.67)
diff --git a/tests/massart97.Rout.save b/tests/massart97.Rout.save
deleted file mode 100644
index ce99c30..0000000
--- a/tests/massart97.Rout.save
+++ /dev/null
@@ -1,128 +0,0 @@
-
-R version 3.1.0 (2014-04-10) -- "Spring Dance"
-Copyright (C) 2014 The R Foundation for Statistical Computing
-Platform: x86_64-pc-linux-gnu (64-bit)
-
-R is free software and comes with ABSOLUTELY NO WARRANTY.
-You are welcome to redistribute it under certain conditions.
-Type 'license()' or 'licence()' for distribution details.
-
-R is a collaborative project with many contributors.
-Type 'contributors()' for more information and
-'citation()' on how to cite R or R packages in publications.
-
-Type 'demo()' for some demos, 'help()' for on-line help, or
-'help.start()' for an HTML browser interface to help.
-Type 'q()' to quit R.
-
-> require(chemCal)
-Loading required package: chemCal
-> data(massart97ex1)
-> m <- lm(y ~ x, data = massart97ex1)
-> inverse.predict(m, 15) # 6.1 +- 4.9
-$Prediction
-[1] 6.09381
-
-$`Standard Error`
-[1] 1.767278
-
-$Confidence
-[1] 4.906751
-
-$`Confidence Limits`
-[1] 1.187059 11.000561
-
-> inverse.predict(m, 90) # 43.9 +- 4.9
-$Prediction
-[1] 43.93983
-
-$`Standard Error`
-[1] 1.767747
-
-$Confidence
-[1] 4.908053
-
-$`Confidence Limits`
-[1] 39.03178 48.84788
-
-> inverse.predict(m, rep(90,5)) # 43.9 +- 3.2
-$Prediction
-[1] 43.93983
-
-$`Standard Error`
-[1] 1.141204
-
-$Confidence
-[1] 3.168489
-
-$`Confidence Limits`
-[1] 40.77134 47.10832
-
->
-> data(massart97ex3)
-> attach(massart97ex3)
-> yx <- split(y, x)
-> ybar <- sapply(yx, mean)
-> s <- round(sapply(yx, sd), digits = 2)
-> w <- round(1 / (s^2), digits = 3)
-> weights <- w[factor(x)]
-> m <- lm(y ~ x, w = weights)
-> #calplot(m)
->
-> inverse.predict(m, 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(m, 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
-
->
-> m0 <- lm(y ~ x)
-> lod(m0)
-$x
-[1] 5.407085
-
-$y
- 1
-13.63911
-
->
-> loq(m0)
-$x
-[1] 13.97764
-
-$y
- 1
-30.6235
-
-> loq(m, w.loq = 1.67)
-$x
-[1] 7.346195
-
-$y
- 1
-17.90777
-
->
-> proc.time()
- user system elapsed
- 0.529 0.327 0.443
diff --git a/tests/testthat.R b/tests/testthat.R
new file mode 100644
index 0000000..6176830
--- /dev/null
+++ b/tests/testthat.R
@@ -0,0 +1,4 @@
+library(testthat)
+library(chemCal)
+
+test_check("chemCal")
diff --git a/tests/testthat/test_din32645.R b/tests/testthat/test_din32645.R
new file mode 100644
index 0000000..e6d2840
--- /dev/null
+++ b/tests/testthat/test_din32645.R
@@ -0,0 +1,33 @@
+context("Known results for the dataset provided in DIN 32645")
+
+require(chemCal)
+
+m <- lm(y ~ x, data = din32645)
+prediction <- inverse.predict(m, 3500, alpha = 0.01)
+
+test_that("We get correct confidence intervals", {
+ # Result collected from Procontrol 3.1 (isomehr GmbH)
+ expect_equal(round(prediction$Confidence, 5), 0.07434)
+})
+
+test_that("We get a correct critical value", {
+ crit <- lod(m, alpha = 0.01, beta = 0.5)
+ # DIN 32645 gives 0.07 for the critical value
+ # (decision limit, "Nachweisgrenze")
+ expect_equal(round(crit$x, 2), 0.07)
+ # According to Dintest test data, we should get 0.0698
+ expect_equal(round(crit$x, 4), 0.0698)
+})
+
+test_that("We get a correct smalles detectable value using the DIN method", {
+ lod.din <- lod(m, alpha = 0.01, beta = 0.01, method = "din")
+ # DIN 32645 gives 0.14 for the smallest detectable value ("Erfassungsgrenze")
+ expect_equal(round(lod.din$x, 2), 0.14)
+})
+
+test_that("We get a correct limit of quantification", {
+ loq.din <- loq(m, alpha = 0.01)
+ # The value cited for Procontrol 3.1 (0.2121) deviates
+ # at the last digit, so we only test for three digits
+ expect_equal(round(loq.din$x, 3), 0.212)
+})
diff --git a/tests/testthat/test_inverse.predict.R b/tests/testthat/test_inverse.predict.R
new file mode 100644
index 0000000..61484dc
--- /dev/null
+++ b/tests/testthat/test_inverse.predict.R
@@ -0,0 +1,43 @@
+context("Inverse predictions")
+
+library(chemCal)
+
+test_that("Inverse predictions for unweighted regressions are stable", {
+ m1 <- lm(y ~ x, data = massart97ex1)
+
+ # Known values from chemcal Version 0.1-37
+ p1.1 <- inverse.predict(m1, 15)
+ expect_equal(signif(p1.1$Prediction, 7), 6.09381)
+ expect_equal(signif(p1.1$`Standard Error`, 7), 1.767278)
+ expect_equal(signif(p1.1$Confidence, 7), 4.906751)
+
+ p1.2 <- inverse.predict(m1, 90)
+ expect_equal(signif(p1.2$Prediction, 7), 43.93983)
+ expect_equal(signif(p1.2$`Standard Error`, 7), 1.767747)
+ expect_equal(signif(p1.2$Confidence, 7), 4.908053)
+
+ p1.3 <- inverse.predict(m1, rep(90, 5))
+ expect_equal(signif(p1.3$Prediction, 7), 43.93983)
+ expect_equal(signif(p1.3$`Standard Error`, 7), 1.141204)
+ expect_equal(signif(p1.3$Confidence, 7), 3.168489)
+})
+
+test_that("Inverse predictions for weighted regressions are stable", {
+ attach(massart97ex3)
+ yx <- split(y, x)
+ ybar <- sapply(yx, mean)
+ s <- round(sapply(yx, sd), digits = 2)
+ w <- round(1 / (s^2), digits = 3)
+ weights <- w[factor(x)]
+ m3 <- lm(y ~ x, w = weights)
+
+ p3.1 <- inverse.predict(m3, 15, ws = 1.67)
+ expect_equal(signif(p3.1$Prediction, 7), 5.865367)
+ expect_equal(signif(p3.1$`Standard Error`, 7), 0.8926109)
+ expect_equal(signif(p3.1$Confidence, 7), 2.478285)
+
+ p3.2 <- inverse.predict(m3, 90, ws = 0.145)
+ expect_equal(signif(p3.2$Prediction, 7), 44.06025)
+ expect_equal(signif(p3.2$`Standard Error`, 7), 2.829162)
+ expect_equal(signif(p3.2$Confidence, 7), 7.855012)
+})
diff --git a/tests/testthat/test_lod_loq.R b/tests/testthat/test_lod_loq.R
new file mode 100644
index 0000000..6ba0ad0
--- /dev/null
+++ b/tests/testthat/test_lod_loq.R
@@ -0,0 +1,28 @@
+context("LOD and LOQ")
+
+library(chemCal)
+
+test_that("lod is stable across chemCal versions", {
+ m <- lm(y ~ x, data = din32645)
+ lod_1 <- lod(m)
+ expect_equal(signif(lod_1$x, 7), 0.08655484)
+ expect_equal(signif(lod_1$y, 7), 3317.154)
+
+ # Critical value (decision limit, Nachweisgrenze)
+ lod_2 <- lod(m, alpha = 0.01, beta = 0.5)
+ expect_equal(signif(lod_2$x, 7), 0.0698127)
+ expect_equal(signif(lod_2$y, 7), 3155.393)
+})
+
+test_that("loq is stable across chemCal versions", {
+ m2 <- lm(y ~ x, data = massart97ex3)
+ loq_1 <- loq(m2)
+ expect_equal(signif(loq_1$x, 7), 13.97764)
+ expect_equal(signif(loq_1$y, 7), 30.6235)
+
+ loq_2 <- loq(m2, n = 3)
+ expect_equal(signif(loq_2$x, 7), 9.971963)
+ expect_equal(signif(loq_2$y, 7), 22.68539)
+})
+
+
diff --git a/tests/testthat/test_massart.R b/tests/testthat/test_massart.R
new file mode 100644
index 0000000..791c2e7
--- /dev/null
+++ b/tests/testthat/test_massart.R
@@ -0,0 +1,40 @@
+context("Known results for the example datasets provided by Massart (1997)")
+
+require(chemCal)
+
+test_that("Inverse predictions for example 1 are correct",{
+ m1 <- lm(y ~ x, data = massart97ex1)
+
+ # Known values are from the book
+ p1.1 <- inverse.predict(m1, 15)
+ expect_equal(round(p1.1$Prediction, 1), 6.1)
+ expect_equal(round(p1.1$Confidence, 1), 4.9)
+
+ p1.2 <- inverse.predict(m1, 90)
+ expect_equal(round(p1.2$Prediction, 1), 43.9)
+ expect_equal(round(p1.2$Confidence, 1), 4.9)
+
+ p1.3 <- inverse.predict(m1, rep(90, 5))
+ expect_equal(round(p1.3$Prediction, 1), 43.9)
+ expect_equal(round(p1.3$Confidence, 1), 3.2)
+})
+
+
+test_that("Inverse predictions for example 3 are correct",{
+ attach(massart97ex3)
+ yx <- split(y, x)
+ ybar <- sapply(yx, mean)
+ s <- round(sapply(yx, sd), digits = 2)
+ w <- round(1 / (s^2), digits = 3)
+ weights <- w[factor(x)]
+ m3 <- lm(y ~ x, w = weights)
+
+ # Known values are from the book
+ p3.1 <- inverse.predict(m3, 15, ws = 1.67)
+ expect_equal(round(p3.1$Prediction, 1), 5.9)
+ expect_equal(round(p3.1$Confidence, 1), 2.5)
+
+ p3.2 <- inverse.predict(m3, 90, ws = 0.145)
+ expect_equal(round(p3.2$Prediction, 1), 44.1)
+ expect_equal(round(p3.2$Confidence, 1), 7.9)
+})

Contact - Imprint