Skip to content

Commit

Permalink
occuRN ranef gets K automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
kenkellner committed Sep 18, 2024
1 parent 6572a2f commit dd14d5f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: unmarked
Version: 1.4.3.9002
Date: 2024-09-16
Version: 1.4.3.9003
Date: 2024-09-18
Type: Package
Title: Models for Data from Unmarked Animals
Authors@R: c(
Expand Down
9 changes: 7 additions & 2 deletions R/ranef.R
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,15 @@ setMethod("ranef_internal", "unmarkedFitOccuMulti", function(object, ...){


setMethod("ranef_internal", "unmarkedFitOccuRN", function(object, ...){
K <- list(...)$K
if(is.null(K)) {

if(methods::.hasSlot(object, "K")){
K <- object@K
} else {
K <- list(...)$K
if(is.null(K)) {
warning("You did not specify K, the maximum value of N, so it was set to 50")
K <- 50
}
}
lam <- predict(object, type="state", level=NULL, na.rm=FALSE)$Predicted # Too slow
R <- length(lam)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_occuRN.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test_that("occuRN can fit models",{
expect_equal(dim(res), dim(woodthrushUMF@y))
expect_equal(res[1,1], 0.73757, tol=1e-4)

r <- ranef(fm_C, K=10)
r <- ranef(fm_C)
expect_equal(dim(r@post), c(50,11,1))
expect_equal(bup(r)[1:4], c(5.1059,5.6125,3.2689,5.6125), tol=1e-4)

Expand Down Expand Up @@ -126,7 +126,7 @@ test_that("occuRN can handle NAs",{
expect_true(is.na(ft[1,1])) # missing obs cov
expect_true(all(!is.na(ft[2,]))) # missing site cov

r <- ranef(fm_na, K=30)
r <- ranef(fm_na)
expect_equal(nrow(r@post), numSites(fm_na@data))
expect_true(all(is.na(r@post[1:2,,1])))
})
Expand Down

0 comments on commit dd14d5f

Please sign in to comment.