tests/testthat/test-model_abs_exp.R

context("model_abs_exp")

test_that("`model_abs_exp` gives the same likelihood as the one calculated in R under different parametrizations of shape parameter", {
  n_tests <- 30 # number of test simulations
  for (ii in 1:n_tests){
    # simulate parameters and data
    sim_res <- test_sim(random = c("a", "b", "s"), kernel = "exp", reparam_s = "positive")
    nll_tmb <- calc_tmb_nll(sim_res)
    expect_equal(sim_res$nll_r, nll_tmb)
    # Unconstrained s
    sim_res <- test_sim(random = c("a", "b", "s"), kernel = "exp", reparam_s = "unconstrained")
    nll_tmb <- calc_tmb_nll(sim_res)
    expect_equal(sim_res$nll_r, nll_tmb)
    # Negative s
    sim_res <- test_sim(random = c("a", "b", "s"), kernel = "exp", reparam_s = "negative")
    nll_tmb <- calc_tmb_nll(sim_res)
    expect_equal(sim_res$nll_r, nll_tmb)
  }
})

Try the SpatialGEV package in your browser

Any scripts or data that you put into this service are public.

SpatialGEV documentation built on June 22, 2024, 9:24 a.m.