-
Notifications
You must be signed in to change notification settings - Fork 9
Description
There are two problems with predict.dsm() when response is "density":
See reprex below for examples.
-
predict(dsm_model)returns 0When
newdataandoff.setare both NULL in the call topredict.dsm(),off.setnever gets set properly before it is used in the code chunk at lines 78-87.Not that you need suggestions for how to fix it, but I feel bad just reporting bugs and not offering up any solutions, so
Changing line 27 to:
newdata <- object$data if(is.null(off.set)){ off.set <- 1 }fixes this problem.
-
predict(dsm_model, type = "lpmatrix")returns an error:Error in if (type == "response" & se.fit) {: argument is of length zeroI stumbled across this while trying to get
vis.concurvity()to work. This happens at line 80 in predict.dsm.R because se.fit is being tested when NULL. The simplest solution appears to be to change line 80 to:}else if(type=="response" & (!is.null(se.fit) && se.fit)){so that it's safe when type == "lpmatrix"
### Reprex follows
library(Distance)
#> Loading required package: mrds
#> This is mrds 2.2.0
#> Built: R 3.6.1; ; 2019-09-28 03:24:13 UTC; windows
#>
#> Attaching package: 'Distance'
#> The following object is masked from 'package:mrds':
#>
#> create.bins
library(dsm)
#> Loading required package: mgcv
#> Loading required package: nlme
#> This is mgcv 1.8-28. For overview type 'help("mgcv-package")'.
#> Loading required package: numDeriv
#> This is dsm 2.2.18
#> Built: R 3.6.1; ; 2019-10-16 15:41:41 UTC; windows
sessionInfo()
#> R version 3.6.1 (2019-07-05)
#> Platform: i386-w64-mingw32/i386 (32-bit)
#> Running under: Windows 10 x64 (build 17134)
#>
#> Matrix products: default
#>
#> locale:
#> [1] LC_COLLATE=English_United States.1252
#> [2] LC_CTYPE=English_United States.1252
#> [3] LC_MONETARY=English_United States.1252
#> [4] LC_NUMERIC=C
#> [5] LC_TIME=English_United States.1252
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] dsm_2.2.18 numDeriv_2016.8-1.1 mgcv_1.8-28
#> [4] nlme_3.1-140 Distance_0.9.8 mrds_2.2.0
#>
#> loaded via a namespace (and not attached):
#> [1] minqa_1.2.4 BB_2014.10-1 ggplot2_3.2.1
#> [4] tidyselect_0.2.5 lattice_0.20-38 dfoptim_2018.2-1
#> [7] Rcgmin_2013-2.21 pkgconfig_2.0.1 compiler_3.6.1
#> [10] stringr_1.4.0 parallel_3.6.1 Rcpp_1.0.2
#> [13] optimx_2013.8.7 plyr_1.8.4 highr_0.6
#> [16] tools_3.6.1 truncnorm_1.0-8 rmarkdown_1.16
#> [19] Rvmmin_2018-4.17 R6_2.2.2 purrr_0.3.2
#> [22] knitr_1.25 scales_0.5.0 svUnit_0.7-12
#> [25] assertthat_0.2.0 digest_0.6.15 evaluate_0.14
#> [28] gtable_0.2.0 setRNG_2013.9-1 Matrix_1.2-14
#> [31] stringi_1.1.7 optextras_2016-8.8 htmltools_0.4.0
#> [34] munsell_0.4.3 grid_3.6.1 glue_1.3.1
#> [37] colorspace_1.3-2 rlang_0.4.0 quadprog_1.5-5
#> [40] Rsolnp_1.16 magrittr_1.5 splines_3.6.1
#> [43] lazyeval_0.2.1 yaml_2.2.0 crayon_1.3.4
#> [46] xfun_0.9 dplyr_0.8.3 pillar_1.4.2
#> [49] statmod_1.4.32 tibble_2.1.3 ucminf_1.1-4
data(mexdolphins)
hr.model <- ds(distdata, max(distdata$distance), key = "hr", adjustment = NULL)
#> Fitting hazard-rate key function
#> Key only model: not constraining for monotonicity.
#> AIC= 841.253
#> No survey area information supplied, only estimating detection function.
# fit a simple smooth of x and y to densities
mod1 <- dsm(density~s(x,y)+s(depth), hr.model, segdata, obsdata)
predict(mod1)
#> numeric(0)
predict(mod1, type = "lpmatrix")
#> Error in if (type == "response" & se.fit) {: argument is of length zero