Skip to content

Commit

Permalink
add osa and simulation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea-Havron-NOAA committed Jun 20, 2024
1 parent c588069 commit a3e2d2f
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tests/testthat/test-single-nll.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a3e2d2f

Please sign in to comment.