Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kenkellner committed Jan 23, 2024
1 parent d5ed5f6 commit 3703403
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: unmarked
Version: 1.4.1.9001
Date: 2024-01-18
Date: 2024-01-23
Type: Package
Title: Models for Data from Unmarked Animals
Authors@R: c(
Expand Down
6 changes: 6 additions & 0 deletions R/IDS.R
Original file line number Diff line number Diff line change
Expand Up @@ -676,3 +676,9 @@ setMethod("nonparboot", "unmarkedFitIDS",
{
stop("Not currently supported for unmarkedFitIDS", call.=FALSE)
})

setMethod("ranef", "unmarkedFitIDS",
function(object, B = 0, keepOldSamples = TRUE, ...)
{
stop("Not currently supported for unmarkedFitIDS", call.=FALSE)
})
24 changes: 22 additions & 2 deletions tests/testthat/test_IDS.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ test_that("IDS can fit models with covariates", {
maxDistPC=0.5, maxDistOC=0.5,
unitsOut="kmsq")
set.seed(123)
(mod_sim <- IDS(lambdaformula = ~elev, detformulaDS = ~1,
mod_sim <- IDS(lambdaformula = ~elev, detformulaDS = ~1,
dataDS=sim_umf$ds, dataPC=sim_umf$pc,
availformula = ~1, durationDS=durs$ds, durationPC=durs$pc,
maxDistPC=0.5, maxDistOC=0.5,
unitsOut="kmsq"))
unitsOut="kmsq")

expect_equivalent(coef(mod_sim), c(3.0271179,-0.4858101,-2.5050244,-1.3729505), tol=1e-5)

Expand Down Expand Up @@ -60,6 +60,18 @@ test_that("IDS can fit models with covariates", {
plot(mod_sim)
hist(mod_sim)
dev.off()

expect_error(nonparboot(mod_sim))
expect_error(ranef(mod_sim))

# Separate detection models
mod_sep <- IDS(lambdaformula = ~elev, detformulaDS = ~1, detformulaPC = ~1,
dataDS=sim_umf$ds[1:100,], dataPC=sim_umf$pc[1:100,],
availformula = ~1, durationDS=durs$ds[1:100], durationPC=durs$pc[1:100],
maxDistPC=0.5, maxDistOC=0.5,
unitsOut="kmsq")
expect_equal(length(coef(mod_sim)), 4)
expect_equal(length(coef(mod_sep)), 5)
})

test_that("IDS can fit models with occupancy data", {
Expand Down Expand Up @@ -112,6 +124,14 @@ test_that("IDS can fit models with occupancy data", {
unitsOut="kmsq")
)

# Just occupancy data
mod_oc <- IDS(lambdaformula = ~elev, detformulaDS = ~1, detformulaOC = ~1,
dataDS=sim_umf$ds, dataOC=sim_umf$oc,
maxDistOC=0.5,
unitsOut="kmsq")

expect_equal(names(mod_oc), c("lam","ds","oc"))

})

test_that("IDS handles missing values", {
Expand Down

0 comments on commit 3703403

Please sign in to comment.