diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2018-07-17 17:29:14 +0200 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2018-07-17 17:38:29 +0200 |
commit | 280d36230052de4f94e384648c1283031fbc9840 (patch) | |
tree | df0ba9e07386b593cc396b8b6976210d42ee1a46 /tests/testthat/test_massart.R | |
parent | e636c17f0d354a8e74546fc1469431dbe502dc76 (diff) |
Fix inverse predictions for replicate measurements
For details, see NEWS.md
Diffstat (limited to 'tests/testthat/test_massart.R')
-rw-r--r-- | tests/testthat/test_massart.R | 22 |
1 files changed, 12 insertions, 10 deletions
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) }) |