Skip to content

Commit

Permalink
Merge branch 'nonoceanic' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Neves-P committed Jun 27, 2022
2 parents 4707a6f + 2e9740b commit b43454a
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 2 deletions.
4 changes: 3 additions & 1 deletion R/get_available_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ get_available_models <- function() {
"rr_mu_dd_0lac", "rr_k_0lac", "rr_laa_di_0lac",
"rr_laa_dd_0lac", "rr_lac_di_0laa",
"rr_lac_dd_0laa", "rr_mu_di_0laa", "rr_mu_dd_0laa",
"rr_k_0laa"
"rr_k_0laa", "nonoceanic_cr_dd", "nonoceanic_cr_di",
"nonoceanic_cr_dd_0laa", "nonoceanic_cr_di_0laa",
"nonoceanic_cr_di_0lac", "nonoceanic_cr_dd_0lac"
)
available_models
}
8 changes: 8 additions & 0 deletions R/setup_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ setup_model <- function(model,
gam <- stats::runif(1, min = 1e-5, max = 0.1)
laa <- stats::runif(1, min = 0.1, max = 4)
sd <- stats::runif(1, min = 0.1, max = 1)
prob_init_presence <- stats::runif(1, min = 0, max = 0.9)
} else {
lac <- stats::runif(1, min = 0, max = 0.1)
mu <- stats::runif(1, min = 0, max = 0.1)
k <- stats::runif(1, min = 100, max = 200)
gam <- stats::runif(1, min = 1e-5, max = 0.1)
laa <- stats::runif(1, min = 0, max = 0.1)
sd <- stats::runif(1, min = 0.1, max = 1)
prob_init_presence <- stats::runif(1, min = 0, max = 0.1)
}

# define default DAISIE model (CR DD)
Expand Down Expand Up @@ -96,6 +98,12 @@ setup_model <- function(model,
}
}

# change to non-oceanic model
if (grepl("nonoceanic", model)) {
idparsopt <- c(idparsopt, prob_init_presence = 6)
initparsopt <- c(initparsopt, prob_init_presence = prob_init_presence)
}

out <- list(
ddmodel = ddmodel,
idparsopt = idparsopt,
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test-get_available_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ test_that("Correct models are returned", {
"rr_mu_dd_0lac", "rr_k_0lac", "rr_laa_di_0lac",
"rr_laa_dd_0lac", "rr_lac_di_0laa",
"rr_lac_dd_0laa", "rr_mu_di_0laa", "rr_mu_dd_0laa",
"rr_k_0laa"
"rr_k_0laa", "nonoceanic_cr_dd", "nonoceanic_cr_di",
"nonoceanic_cr_dd_0laa", "nonoceanic_cr_di_0laa",
"nonoceanic_cr_di_0lac", "nonoceanic_cr_dd_0lac"
)

expect_equal(obtained_output, expected_output)
Expand Down
145 changes: 145 additions & 0 deletions tests/testthat/test-setup_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,148 @@ test_that("setup_model is correct for rr_laa_dd", {
)
expect_equal(model_arguments, expected_arguments)
})

test_that("setup_model is correct for nonoceanic_cr_dd", {
set.seed(1)
model <- "nonoceanic_cr_dd"
model_arguments <- setup_model(
model = model
)
expected_arguments <- list(
ddmodel = 11,
idparsopt = c(
lac = 1, mu = 2, k = 3, gam = 4, laa = 5, prob_init_presence = 6
),
parsfix = NULL,
idparsfix = NULL,
idparsnoshift = 6:10,
initparsopt = c(
lac = 0.5310173262842,
mu = 0.74424779927358,
k = 157.28533633518964,
gam = 0.09082169692158,
laa = 0.88655953104608,
prob_init_presence = 0.85020774174482
),
cs_version = 1
)
expect_equal(model_arguments, expected_arguments)
})

test_that("setup_model is correct for nonoceanic_cr_di", {
set.seed(1)
model <- "nonoceanic_cr_di"
model_arguments <- setup_model(
model = model
)
expected_arguments <- list(
ddmodel = 0,
idparsopt = c(lac = 1, mu = 2, gam = 4, laa = 5, prob_init_presence = 6),
parsfix = Inf,
idparsfix = 3,
idparsnoshift = 6:10,
initparsopt = c(
lac = 0.5310173262842,
mu = 0.7442477992736,
gam = 0.0908216969216,
laa = 0.8865595310461,
prob_init_presence = 0.85020774174482
),
cs_version = 1
)
expect_equal(model_arguments, expected_arguments)
})

test_that("setup_model is correct for nonoceanic_cr_dd_0laa", {
set.seed(1)
model <- "nonoceanic_cr_dd_0laa"
model_arguments <- setup_model(
model = model
)
expected_arguments <- list(
ddmodel = 11,
idparsopt = c(lac = 1, mu = 2, k = 3, gam = 4, prob_init_presence = 6),
parsfix = 0,
idparsfix = 5,
idparsnoshift = 6:10,
initparsopt = c(
lac = 0.5310173262842,
mu = 0.74424779927358,
k = 157.28533633518964,
gam = 0.0908216969216,
prob_init_presence = 0.85020774174482
),
cs_version = 1
)
expect_equal(model_arguments, expected_arguments)
})

test_that("setup_model is correct for nonoceanic_cr_di_0laa", {
set.seed(1)
model <- "nonoceanic_cr_di_0laa"
model_arguments <- setup_model(
model = model
)
expected_arguments <- list(
ddmodel = 0,
idparsopt = c(lac = 1, mu = 2, gam = 4, prob_init_presence = 6),
parsfix = c(Inf, 0),
idparsfix = c(3, 5),
idparsnoshift = 6:10,
initparsopt = c(
lac = 0.5310173262842,
mu = 0.7442477992736,
gam = 0.0908216969216,
prob_init_presence = 0.85020774174482
),
cs_version = 1
)
expect_equal(model_arguments, expected_arguments)
})

test_that("setup_model is correct for nonoceanic_cr_dd_0lac", {
set.seed(1)
model <- "nonoceanic_cr_dd_0lac"
model_arguments <- setup_model(
model = model
)
expected_arguments <- list(
ddmodel = 11,
idparsopt = c(mu = 2, k = 3, gam = 4, laa = 5, prob_init_presence = 6),
parsfix = 0,
idparsfix = 1,
idparsnoshift = 6:10,
initparsopt = c(
mu = 0.74424779927358,
k = 157.28533633518964,
gam = 0.09082169692158,
laa = 0.88655953104608,
prob_init_presence = 0.85020774174482
),
cs_version = 1
)
expect_equal(model_arguments, expected_arguments)
})

test_that("setup_model is correct for nonoceanic_cr_di_0lac", {
set.seed(1)
model <- "nonoceanic_cr_di_0lac"
model_arguments <- setup_model(
model = model
)
expected_arguments <- list(
ddmodel = 0,
idparsopt = c(mu = 2, gam = 4, laa = 5, prob_init_presence = 6),
parsfix = c(0, Inf),
idparsfix = c(1, 3),
idparsnoshift = 6:10,
initparsopt = c(
mu = 0.7442477992736,
gam = 0.0908216969216,
laa = 0.8865595310461,
prob_init_presence = 0.85020774174482
),
cs_version = 1
)
expect_equal(model_arguments, expected_arguments)
})
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit b43454a

Please sign in to comment.