diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2020-04-09 09:38:01 +0200 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2020-04-09 09:38:01 +0200 |
commit | 23461dddcc6a1858f1c9c9052512f22485d08842 (patch) | |
tree | ced422b471b42e9b4b2222168949ab10fa5634d9 /tests/testthat/test_nlme.R | |
parent | 636c585895aacaae95d739201e856252f24fec1b (diff) |
Try mkinerrplot for obs and tc on Travis again
Diffstat (limited to 'tests/testthat/test_nlme.R')
-rw-r--r-- | tests/testthat/test_nlme.R | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/testthat/test_nlme.R b/tests/testthat/test_nlme.R index 31db92e1..0d1fcd6d 100644 --- a/tests/testthat/test_nlme.R +++ b/tests/testthat/test_nlme.R @@ -64,3 +64,62 @@ test_that("nlme_function works correctly", { expect_silent(tmp <- update(m_nlme_mkin)) }) + +test_that("nlme_function works correctly in other cases", { + + dt50_in <- c(400, 800, 1200, 1600, 2000) + dt50_in_geomean <- geomean(dt50_in) + k_in <- log(2) / dt50_in + SFO <- mkinmod(parent = mkinsub("SFO")) + pred_sfo <- function(k) { + mkinpredict(SFO, + c(k_parent_sink = k), + c(parent = 100), + sampling_times) + } + ds_me_sfo <- mapply(pred_sfo, k_in, SIMPLIFY = FALSE) + add_err_5 <- function(i) { + add_err(ds_me_sfo[[i]], sdfunc = function(value) 5, n = 3, seed = i + 1) + } + ds_me_sfo_5 <- sapply(1:5, add_err_5) + names(ds_me_sfo_5) <- paste("Dataset", 1:15) + dimnames(ds_me_sfo_5) <- list(Subset = 1:3, DT50 = dt50_in) + + f_me_sfo_5 <- mmkin("SFO", ds_me_sfo_5) + + ds_me_sfo_5_grouped_mkin <- nlme_data(f_me_sfo_5) + ds_me_sfo_5_mean_dp <- mean_degparms(f_me_sfo_5) + me_sfo_function <- nlme_function(f_me_sfo_5) + + f_nlme_sfo_5_all_mkin <- nlme(value ~ me_sfo_function(name, time, + parent_0, log_k_parent_sink), + data = ds_me_sfo_5_grouped, + fixed = parent_0 + log_k_parent_sink ~ 1, + random = pdDiag(parent_0 + log_k_parent_sink ~ 1), + start = ds_me_sfo_5_mean_dp) + + f_nlme_sfo_5 <- nlme(value ~ SSasymp(time, 0, parent_0, log_k_parent_sink), + data = ds_me_sfo_5_grouped_mkin, + fixed = parent_0 + log_k_parent_sink ~ 1, + random = pdDiag(parent_0 + log_k_parent_sink ~ 1), + start = ds_me_sfo_5_mean_dp) + + expect_equal(f_nlme_sfo_5_all_mkin$coefficients, f_nlme_sfo_5$coefficients) + + # With less ideal starting values we get fits with lower AIC (not shown) + f_nlme_sfo_5_all_mkin_nostart <- nlme(value ~ me_sfo_function(name, time, + parent_0, log_k_parent_sink), + data = ds_me_sfo_5_grouped, + fixed = parent_0 + log_k_parent_sink ~ 1, + random = pdDiag(parent_0 + log_k_parent_sink ~ 1), + start = c(parent_0 = 100, log_k_parent_sink = log(0.1))) + + f_nlme_sfo_5_nostart <- nlme(value ~ SSasymp(time, 0, parent_0, log_k_parent_sink), + data = ds_me_sfo_5_grouped_mkin, + fixed = parent_0 + log_k_parent_sink ~ 1, + random = pdDiag(parent_0 + log_k_parent_sink ~ 1), + start = c(parent_0 = 100, log_k_parent_sink = log(0.1))) + + expect_equal(f_nlme_sfo_5_all_mkin_nostart$coefficients, f_nlme_sfo_5_nostart$coefficients) + +}) |