aboutsummaryrefslogtreecommitdiff
path: root/tests/testthat/test_tests.R
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2020-03-27 11:47:48 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2020-03-27 11:47:48 +0100
commit20ece4e0bcbeceb90a940e04a858f4ffb6d6b5e4 (patch)
tree7595dbb6e129332a6ad0c273ecd3fbd92643e0d5 /tests/testthat/test_tests.R
parent731dd9450f08868140f90af7a305133ec9342994 (diff)
parent68eed166cbe10a5ee79f5b1139261dea98234b22 (diff)
Merge branch 'master' into mxkin
Diffstat (limited to 'tests/testthat/test_tests.R')
-rw-r--r--tests/testthat/test_tests.R23
1 files changed, 21 insertions, 2 deletions
diff --git a/tests/testthat/test_tests.R b/tests/testthat/test_tests.R
index 5a522f8e..ddf8e1a0 100644
--- a/tests/testthat/test_tests.R
+++ b/tests/testthat/test_tests.R
@@ -1,5 +1,21 @@
context("Hypothesis tests")
+test_that("The lack-of-fit test works and can be reproduced using nls", {
+
+ expect_error(loftest(f_1_mkin_trans), "Not defined for fits to data without replicates")
+
+ loftest_mkin <- loftest(f_2_mkin)
+
+ # This code is a slightly modified version of that given in Ritz and Streibig
+ # (2008) Nonlinear Regression using R, p. 64
+ Q <- as.numeric(- 2 * (logLik(f_2_nls) - logLik(f_2_anova)))
+ df.Q <- df.residual(f_2_nls) - df.residual(f_2_anova)
+ p_nls <- 1 - pchisq(Q, df.Q)
+
+ expect_equal(loftest_mkin[["2", "Pr(>Chisq)"]], p_nls, tolerance = 1e-5)
+
+})
+
test_that("The likelihood ratio test works", {
expect_error(lrtest(f_1_mkin_trans, f_2_mkin), "not been fitted to the same data")
@@ -25,7 +41,7 @@ test_that("Updating fitted models works", {
parent = mkinsub("DFOP", to = "A1"),
A1 = mkinsub("SFO", to = "A2"),
A2 = mkinsub("SFO"),
- use_of_ff = "max"
+ use_of_ff = "max", quiet = TRUE
)
f_soil_1_tc <- mkinfit(dfop_sfo_sfo,
@@ -41,6 +57,9 @@ test_that("Updating fitted models works", {
})
test_that("We can do a likelihood ratio test using an update specification", {
+ skip("This errors out if called by testthat while it works in a normal R session")
test_2_mkin_k2 <- lrtest(f_2_mkin, fixed_parms = c(k2 = 0))
- expect_equivalent(test_2_mkin_k2[["2", "Pr(>Chisq)"]], 1.139e-6, tolerance = 1e-8)
+ expect_equivalent(test_2_mkin_k2[["2", "Pr(>Chisq)"]], 4.851e-8, tolerance = 1e-8)
+ test_2_mkin_tc <- lrtest(f_2_mkin, error_model = "tc")
+ expect_equivalent(test_2_mkin_tc[["2", "Pr(>Chisq)"]], 7.302e-5, tolerance = 1e-7)
})

Contact - Imprint