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 8c9dc1c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 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)
})
2 changes: 1 addition & 1 deletion man/IDS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ See the help files for these objects for guidance on how to organize the data.
}

\references{
Kery M, Royle JA, Hallman T, Robinson WD, Strebel N, Kellner KF. 2022.
Kery M, Royle JA, Hallman T, Robinson WD, Strebel N, Kellner KF. 2024.
Integrated distance sampling models for simple point counts. Ecology.
}
\author{Ken Kellner \email{contact@kenkellner.com}}
Expand Down
1 change: 1 addition & 0 deletions man/ranef-methods.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
\alias{ranef,unmarkedFitDailMadsen-method}
\alias{ranef,unmarkedFitGOccu-method}
\alias{ranef,unmarkedFitOccuCOP-method}
\alias{ranef,unmarkedFitIDS-method}
\title{ Methods for Function \code{ranef} in Package \pkg{unmarked} }
\description{
Estimate posterior distributions of the random variables (latent
Expand Down
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 8c9dc1c

Please sign in to comment.