Error in Ops.units when using dsm

374 views
Skip to first unread message

olga30dec

unread,
Jun 15, 2021, 7:25:17 AM6/15/21
to distance-sampling
Dear all,

I am preparing data to be used with dsm package as described in http://examples.distancesampling.org/dsm-data-formatting/dsm-data-formatting.html

Running this code:
dsm.xy <- dsm(formula = count~s(X,Y), 
              ddf.obj = detfc.hr.cos, 
              segment.data = segdata, 
              observation.data = obsdata, 
              engine = "gam",
              convert.units = conversion.factor, 
              family = quasipoisson(link = "log"),
              group = FALSE,
              method="REML")

Gives me this error: 
# Error in Ops.units(dat[, seglength.name], 0) : 
#   both operands of the expression should be "units" objects 

I understand this might be coming from units or sf package. 
Any help how to solve this would be greatly appreciated.

> head(obsdata)
  object   Sample.Label size  distance
2      2   RtD.2013-1-1    1 295.44233
3      3  RtD.2013-46-1    1  10.46719
4      4   RtD.2013-1-4    1  20.52121
5      5   RtD.2013-1-4    1  85.50504
7      7   RtD.2013-1-5    1  34.72964
9      9 RtD.2013-103-9    1  91.92533

> head(segdata)
    Transect       Effort Sample.Label         X        Y
1          0 501.6446 [m] RtD.2013-0-1 -6.073213 53.24845
1.1        0 501.6452 [m] RtD.2013-0-2 -6.080279 53.25002
1.2        0 501.6459 [m] RtD.2013-0-3 -6.087346 53.25159
2          1 593.2994 [m] RtD.2013-1-1 -6.086590 53.25311
2.1        1 593.2982 [m] RtD.2013-1-2 -6.078010 53.25456
2.2        1 593.2970 [m] RtD.2013-1-3 -6.069429 53.25602


> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 10 (buster)

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.8.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.8.0

locale:
 [1] LC_CTYPE=en_IE.UTF-8       LC_NUMERIC=C               LC_TIME=en_IE.UTF-8        LC_COLLATE=en_IE.UTF-8    
 [5] LC_MONETARY=en_IE.UTF-8    LC_MESSAGES=en_IE.UTF-8    LC_PAPER=en_IE.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_IE.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] sf_1.0-0            ggplot2_3.3.3       Distance_1.0.2      dsm_2.3.1           numDeriv_2016.8-1.1 mrds_2.2.4         
[7] mgcv_1.8-35         nlme_3.1-152       

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6         compiler_4.1.0     pillar_1.6.1       class_7.3-19       tools_4.1.0        statmod_1.4.36    
 [7] lifecycle_1.0.0    tibble_3.1.2       gtable_0.3.0       lattice_0.20-44    pkgconfig_2.0.3    rlang_0.4.11      
[13] Matrix_1.3-3       DBI_1.1.1          parallel_4.1.0     e1071_1.7-7        s2_1.0.5           withr_2.4.2       
[19] dplyr_1.0.6        generics_0.1.0     vctrs_0.3.8        classInt_0.4-3     grid_4.1.0         tidyselect_1.1.1  
[25] glue_1.4.2         R6_2.5.0           fansi_0.5.0        Rsolnp_1.16        farver_2.1.0       purrr_0.3.4       
[31] magrittr_2.0.1     scales_1.1.1       ellipsis_0.3.2     units_0.7-2        splines_4.1.0      assertthat_0.2.1  
[37] colorspace_2.0-1   KernSmooth_2.23-20 utf8_1.2.1         optimx_2020-4.2    proxy_0.4-26       wk_0.4.1          
[43] munsell_0.5.0      truncnorm_1.0-8    crayon_1.4.1  




Falk Grossmann

unread,
Jun 15, 2021, 7:31:09 AM6/15/21
to olga30dec, distance-sampling
Hi Olga,

Have you tried to remove the units attribute from the two data frames before calling dsm?

obsdata$distance  <- drop_units(obsdata$distance)

and

segdata$Effort  <- drop_units(segdata$Effort)


Rgrds,

DC

--
You received this message because you are subscribed to the Google Groups "distance-sampling" group.
To unsubscribe from this group and stop receiving emails from it, send an email to distance-sampl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/distance-sampling/26677fba-164c-4f0a-9af9-dcaee921803bn%40googlegroups.com.

olga30dec

unread,
Jun 15, 2021, 7:42:10 AM6/15/21
to distance-sampling
Thanks for your quick reply, that solved the issue!
Reply all
Reply to author
Forward
0 new messages