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_inverse.predict.R | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'tests/testthat/test_inverse.predict.R') diff --git a/tests/testthat/test_inverse.predict.R b/tests/testthat/test_inverse.predict.R index 61484dc..a4e1bfd 100644 --- a/tests/testthat/test_inverse.predict.R +++ b/tests/testthat/test_inverse.predict.R @@ -23,20 +23,23 @@ test_that("Inverse predictions for unweighted regressions are stable", { }) 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) + 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) + + m3.means <- lm(y ~ x, w = weights, data = massart97ex3.means) + + p3.1 <- inverse.predict(m3.means, 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) + p3.2 <- inverse.predict(m3.means, 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) -- cgit v1.2.1