aboutsummaryrefslogtreecommitdiff
path: root/tests/testthat/test_tests.R
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2019-10-31 01:55:01 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2019-10-31 01:59:05 +0100
commit7091d3738e7e55acb20edb88772b228f6f5b6c98 (patch)
treeb6e31700074605c702662e5238162c57de330453 /tests/testthat/test_tests.R
parent5e4ea59a41e00b05ea6664c08c7922e892e8ab77 (diff)
Add likelihood ratio test and other methods, fixes
The likelihood ratio test method is lrtest, in addition, methods for update and residuals were added.
Diffstat (limited to 'tests/testthat/test_tests.R')
-rw-r--r--tests/testthat/test_tests.R27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/testthat/test_tests.R b/tests/testthat/test_tests.R
new file mode 100644
index 00000000..523edc4a
--- /dev/null
+++ b/tests/testthat/test_tests.R
@@ -0,0 +1,27 @@
+context("Hypothesis tests")
+
+test_that("The likelihood ratio test works", {
+
+ expect_error(lrtest(fit_tc_1, f_tc_2), "not been fitted to the same data")
+
+ res <- lrtest(fit_nw_1, fit_tc_1)
+ expect_equal(res[["2", "Pr(>Chisq)"]], 0.9999998)
+
+})
+
+test_that("We can conveniently fix parameters using 'fixed_parms'", {
+ f_k2_fixed <- mkinfit("DFOP", FOCUS_2006_C, fixed_parms = c(k2 = 0.05), quiet = TRUE)
+ expect_equivalent(f_k2_fixed$bparms.ode["k2"], 0.05)
+})
+
+test_that("Updating fitted models works", {
+ f_dfop_const <- mkinfit("DFOP", FOCUS_2006_C, quiet = TRUE)
+ f_dfop_tc <- update(f_dfop_const, error_model = "tc")
+
+ f_soil_1_nw <- update(f_soil_1_tc, error_model = "const")
+ f_soil_1_nw_A2 <- update(f_soil_1_nw, fixed_parms = c(k_A2 = 0))
+ test_nw_tc <- lrtest(f_soil_1_nw, f_soil_1_tc)
+ expect_equivalent(test_nw_tc[["2", "Pr(>Chisq)"]], 2.113e-6)
+ test_nw_A2 <- lrtest(f_soil_1_nw, f_soil_1_nw_A2)
+ expect_equivalent(test_nw_A2[["2", "Pr(>Chisq)"]], 0.9999468)
+})

Contact - Imprint