From 8c9dc1c68af936c818cc39ec204e7998ce245c0d Mon Sep 17 00:00:00 2001 From: Ken Kellner Date: Tue, 23 Jan 2024 15:43:22 -0500 Subject: Add tests --- DESCRIPTION | 2 +- R/IDS.R | 6 ++++++ man/IDS.Rd | 2 +- man/ranef-methods.Rd | 1 + tests/testthat/test_IDS.R | 24 ++++++++++++++++++++++-- 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9db759d..c7e5799 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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( diff --git a/R/IDS.R b/R/IDS.R index 2517b70..38338b1 100644 --- a/R/IDS.R +++ b/R/IDS.R @@ -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) +}) diff --git a/man/IDS.Rd b/man/IDS.Rd index bef5b56..5ec3923 100644 --- a/man/IDS.Rd +++ b/man/IDS.Rd @@ -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}} diff --git a/man/ranef-methods.Rd b/man/ranef-methods.Rd index 1eb0704..66452d7 100644 --- a/man/ranef-methods.Rd +++ b/man/ranef-methods.Rd @@ -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 diff --git a/tests/testthat/test_IDS.R b/tests/testthat/test_IDS.R index 8d28322..61d348d 100644 --- a/tests/testthat/test_IDS.R +++ b/tests/testthat/test_IDS.R @@ -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) @@ -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", { @@ -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", { -- cgit v1.2.3