From a37ba8f8898e4629dfc9d2558fc19a180551de2d Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 19 Jan 2018 16:01:47 +0100 Subject: Reweighting with two-component error model Static documentation except articles rebuilt by pkgdown --- tests/testthat/test_irls.R | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/testthat/test_irls.R (limited to 'tests') diff --git a/tests/testthat/test_irls.R b/tests/testthat/test_irls.R new file mode 100644 index 00000000..0b005182 --- /dev/null +++ b/tests/testthat/test_irls.R @@ -0,0 +1,46 @@ +# Copyright (C) 2018 Johannes Ranke +# Contact: jranke@uni-bremen.de + +# This file is part of the R package mkin + +# mkin is free software: you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. + +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. + +# You should have received a copy of the GNU General Public License along with +# this program. If not, see + +context("Iteratively reweighed least squares (IRLS) fitting") + + +m_synth_SFO_lin <- mkinmod(parent = mkinsub("SFO", "M1"), + M1 = mkinsub("SFO", "M2"), + M2 = mkinsub("SFO"), + use_of_ff = "max", quiet = TRUE) + +m_synth_DFOP_par <- mkinmod(parent = mkinsub("DFOP", c("M1", "M2")), + M1 = mkinsub("SFO"), + M2 = mkinsub("SFO"), + use_of_ff = "max", quiet = TRUE) + +SFO_lin_a <- synthetic_data_for_UBA_2014[[1]]$data + +DFOP_par_c <- synthetic_data_for_UBA_2014[[12]]$data + +test_that("Reweighting method 'obs' works", { + fit_irls_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, reweight.method = "obs", quiet = TRUE) + parms_1 <- round(fit_irls_1$bparms.optim, c(1, 4, 4, 4, 4, 4)) + expect_equivalent(parms_1, c(102.1, 0.7389, 0.2982, 0.0203, 0.7677, 0.7246)) +}) + +test_that("Reweighting method 'tc' works", { + fit_irls_2 <- mkinfit(m_synth_DFOP_par, DFOP_par_c, reweight.method = "tc", quiet = TRUE) + parms_2 <- signif(fit_irls_2$bparms.optim, 3) + expect_equivalent(parms_2, c(99.3, 0.041, 0.00962, 0.597, 0.393, 0.298, 0.0203, 0.707)) +}) -- cgit v1.2.1