rbchan / unmarked

R package for hierarchical models in ecological research
https://rbchan.github.io/unmarked/
37 stars 25 forks source link

pcountOpen example no longer works #184

Closed cschwarz-stat-sfu-ca closed 4 years ago

cschwarz-stat-sfu-ca commented 4 years ago

I've run into problem using predict() with pcountOpen with version 1.0.0 of unmarked. I'm trying to create a MWE using the example that is in the help file for pcountOpen, but this does not even run.

library(unmarked) sessionInfo(package="unmarked") R version 4.0.1 (2020-06-06) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Catalina 10.15.5

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages: character(0)

other attached packages: [1] unmarked_1.0.0

loaded via a namespace (and not attached): [1] MASS_7.3-51.6 compiler_4.0.1 plyr_1.8.6 graphics_4.0.1 parallel_4.0.1 tools_4.0.1 sp_1.4-2
[8] utils_4.0.1 yaml_2.2.1 grDevices_4.0.1 Rcpp_1.0.4.6 stats_4.0.1 raster_3.1-5 datasets_4.0.1
[15] codetools_0.2-16 grid_4.0.1 methods_4.0.1 base_4.0.1 lattice_0.20-41

set.seed(3) M <- 50 T <- 5 lambda <- 4 gamma <- 1.5 omega <- 0.8 p <- 0.7 y <- N <- matrix(NA, M, T) S <- G <- matrix(NA, M, T-1) N[,1] <- rpois(M, lambda) for(t in 1:(T-1)) {

  • S[,t] <- rbinom(M, N[,t], omega)
  • G[,t] <- rpois(M, gamma)
  • N[,t+1] <- S[,t] + G[,t]
  • } y[] <- rbinom(M*T, N, p)

Prepare data

umf <- unmarkedFramePCO(y = y, numPrimary=1) summary(umf) unmarkedFrame Object

50 sites Maximum number of observations per site: 5 Mean number of observations per site: 5 Number of primary survey periods: 1 Number of secondary survey periods: 5 Sites with at least one detection: 50

Tabulation of y observations: 0 1 2 3 4 5 6 7 8 9 13 12 17 56 63 37 28 16 14 5 1 1

Fit model and backtransform

m1 <- pcountOpen(~1, ~1, ~1, ~1, umf, K=20) # Typically, K should be higher Error in apply(Xgam.long.na, 1, any) : dim(X) must have a positive length

kenkellner commented 4 years ago

Hi,

The code you've pasted here isn't quite the same as the example, umf <- unmarkedFramePCO(y = y, numPrimary=1) should be umf <- unmarkedFramePCO(y = y, numPrimary=T)

where T=5. The scenario with only one primary period should probably be handled more cleanly (though not much point in using pcountOpen with one primary period).

Regarding the predict issues, we've fixed a bug related to this since the 1.0 release. Can you install the dev version from github and see if it addresses your issue?

See here

cschwarz-stat-sfu-ca commented 4 years ago

Doh.... bad eyesight ...sorry... I'll post my actual problem shortly as a new issue.

Thank Carl

On Sat, Jun 20, 2020 at 12:01 PM Ken Kellner notifications@github.com wrote:

Hi,

The code you've pasted here isn't quite the same as the example, umf <- unmarkedFramePCO(y = y, numPrimary=1) should be umf <- unmarkedFramePCO(y = y, numPrimary=T)

where T=5. The scenario with only one primary period should probably be handled more cleanly (though not much point in using pcountOpen with one primary period).

Regarding the predict issues, we've fixed a bug related to this since the 1.0 release. Can you install the dev version from github and see if it addresses your issue?

See f6d64fa https://github.com/rbchan/unmarked/commit/f6d64fa45f384fc1ebac44e261338254b9bf042f

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rbchan/unmarked/issues/184#issuecomment-647033782, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABXIXRRDZW3H4PNOT5HQ3Z3RXUBRHANCNFSM4ODPBK4Q .

cschwarz-stat-sfu-ca commented 4 years ago

My bad.. sorry.