# Copyright (C) 2018,2019 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("Error model 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("Error model 'const' works", { skip_on_cran() fit_const_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "const", quiet = TRUE) bpar_1 <- fit_const_1$bparms.optim # The reference used here is mkin 0.9.48.1 bpar_1_mkin_0.9 <- read.table(text = "parent_0 102.0000 k_parent 0.7390 k_M1 0.2990 k_M2 0.0202 f_parent_to_M1 0.7690 f_M1_to_M2 0.7230", col.names = c("parameter", "estimate")) expect_equivalent(signif(bpar_1, 3), bpar_1_mkin_0.9$estimate) }) test_that("Error model 'obs' works", { skip_on_cran() fit_obs_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "obs", quiet = TRUE) parms_2 <- round(fit_obs_1$bparms.optim, c(1, 4, 4, 4, 4, 4)) expect_equivalent(parms_2, c(102.1, 0.7389, 0.2982, 0.0203, 0.7677, 0.7246)) }) test_that("Error model 'tc' works", { skip_on_cran() fit_tc_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "tc", quiet = TRUE) parms_3 <- round(fit_tc_1$bparms.optim, c(1, 4, 4, 4, 4, 4)) expect_equivalent(parms_3, c(102.1, 0.7393, 0.2992, 0.0202, 0.7687, 0.7229)) }) test_that("The different error model fitting methods work for parent fits", { skip_on_cran() f_9_OLS <- mkinfit("SFO", experimental_data_for_UBA_2019[[9]]$data, quiet = TRUE) expect_equivalent(round(AIC(f_9_OLS), 2), 137.43) f_9_direct <- mkinfit("SFO", experimental_data_for_UBA_2019[[9]]$data, error_model = "tc", error_model_algorithm = "direct", quiet = TRUE) expect_equivalent(round(AIC(f_9_direct), 2), 134.94) f_9_twostep <- mkinfit("SFO", experimental_data_for_UBA_2019[[9]]$data, error_model = "tc", error_model_algorithm = "twostep", quiet = TRUE) expect_equivalent(round(AIC(f_9_twostep), 2), 134.94) f_9_threestep <- mkinfit("SFO", experimental_data_for_UBA_2019[[9]]$data, error_model = "tc", error_model_algorithm = "threestep", quiet = TRUE) expect_equivalent(round(AIC(f_9_threestep), 2), 139.43) f_9_fourstep <- mkinfit("SFO", experimental_data_for_UBA_2019[[9]]$data, error_model = "tc", error_model_algorithm = "fourstep", quiet = TRUE) expect_equivalent(round(AIC(f_9_fourstep), 2), 139.43) f_9_IRLS <- mkinfit("SFO", experimental_data_for_UBA_2019[[9]]$data, error_model = "tc", error_model_algorithm = "IRLS", quiet = TRUE) expect_equivalent(round(AIC(f_9_IRLS), 2), 139.43) f_9_d_3 <- mkinfit("SFO", experimental_data_for_UBA_2019[[9]]$data, error_model = "tc", error_model_algorithm = "d_3", quiet = TRUE) expect_equivalent(round(AIC(f_9_d_3), 2), 134.94) }) test_that("The default error model algorithm finds the best known AIC values for parent fits", { skip_on_cran() f_tc_exp_d_3 <- mmkin(c("SFO", "DFOP", "HS"), lapply(experimental_data_for_UBA_2019, function(x) x$data), error_model = "tc", error_model_algorithm = "d_3", quiet = TRUE) AIC_exp_d_3 <- lapply(f_tc_exp_d_3, AIC) AIC_exp_d_3 <- lapply(AIC_exp_d_3, round, 1) dim(AIC_exp_d_3) <- dim(f_tc_exp_d_3) dimnames(AIC_exp_d_3) <- dimnames(f_tc_exp_d_3) expect_known_output(AIC_exp_d_3, "AIC_exp_d_3.out") })