aboutsummaryrefslogtreecommitdiff
path: root/tests/testthat/test_massart.R
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testthat/test_massart.R')
-rw-r--r--tests/testthat/test_massart.R22
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)
})

Contact - Imprint