From 280d36230052de4f94e384648c1283031fbc9840 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Tue, 17 Jul 2018 17:29:14 +0200 Subject: Fix inverse predictions for replicate measurements For details, see NEWS.md --- tests/testthat/test_massart.R | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'tests/testthat/test_massart.R') diff --git a/tests/testthat/test_massart.R b/tests/testthat/test_massart.R index 791c2e7..6e4ce75 100644 --- a/tests/testthat/test_massart.R +++ b/tests/testthat/test_massart.R @@ -19,22 +19,24 @@ test_that("Inverse predictions for example 1 are correct",{ expect_equal(round(p1.3$Confidence, 1), 3.2) }) +test_that("Inverse predictions for example data 3 are correct when regressing on means",{ + 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) + }) -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) + massart97ex3.means <- aggregate(y ~ x, massart97ex3, mean) + + m3.means <- lm(y ~ x, w = weights, data = massart97ex3.means) # Known values are from the book - p3.1 <- inverse.predict(m3, 15, ws = 1.67) + p3.1 <- inverse.predict(m3.means, 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) + p3.2 <- inverse.predict(m3.means, 90, ws = 0.145) expect_equal(round(p3.2$Prediction, 1), 44.1) expect_equal(round(p3.2$Confidence, 1), 7.9) }) -- cgit v1.2.1