From a3e2d2f4e829edb5d29e219dbd67261b3df94889 Mon Sep 17 00:00:00 2001 From: Andrea-Havron-NOAA Date: Thu, 20 Jun 2024 14:45:14 -0500 Subject: [PATCH] add osa and simulation tests --- tests/testthat/test-single-nll.R | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-single-nll.R b/tests/testthat/test-single-nll.R index b896040..6e9d256 100644 --- a/tests/testthat/test-single-nll.R +++ b/tests/testthat/test-single-nll.R @@ -88,13 +88,35 @@ test_that("test single nll",{ expect_equal( log(.1) > ci[[3]][1] & log(.1) < ci[[3]][2], TRUE) }) +#Test osa +osa.fg <- TMB::oneStepPredict(obj, observation.name = "y", method = "fullGaussian") +osa.cdf <- TMB::oneStepPredict(obj, observation.name = "y", + data.term.indicator = "keep", method = "cdf") +exp.value <- (opt$par[2] * (1.0 - exp(-exp(opt$par[1]) * (ages - a_min)))) +pear.resid <- (length.data-exp.value)/ exp(opt$par[3]) + +test_that("test osa", { + expect_equal(pear.resid, osa.fg$residual) + # cdf not working + # expect_equal(pear.resid, osa.cdf$residual) +}) + +#test simulation +set.seed(11) +r.sim <- rnorm(length(exp.value), exp.value, exp(opt$par[3])) +set.seed(11) +tmb.sim <- obj$simulate()$normal_observed_value +test_that("test simulation", { + expect_equal(r.sim, tmb.sim, tolerance = 1e-4)}) + + #access output from Rcpp object vonB$finalize(opt$par) DataLL$finalize(opt$par) #print optimzed values from RCPP test_that("test rcpp output", { expect_equal(unname(opt$par[1]), vonB$logk$value) - expect_equal(unname(opt$par[2]), vonB$l_inf$value) + expect_equal(unname(opt$par[2]), vonB$l_inf$value) }) # currently fails due to bug in finalize functions