dplyr dependency error message when using dht2

185 views
Skip to first unread message

vaughn...@gmail.com

unread,
Nov 7, 2023, 2:14:09 PM11/7/23
to distance-sampling
Hello, 
I came across the below error message while attempting to run a multi-species distance sampling model using dht2() function. 

Is there any workaround I can do on my end for this?  

Kind regards,
Vaughn 

> bird.ests <- dht2(ddf=hn0.all.birds, + flatfile= GCbirds, + strat_formula = ~ species, + convert_units = unit_conversion, + stratification = "object") Error in `$<-`: ! Assigned data `diag(dm$variance)` must be compatible with existing data. Existing data has 17 rows. Assigned data has 16 rows. Only vectors of size 1 are recycled. Caused by error in `vectbl_recycle_rhs_rows()`: ! Can't recycle input of size 16 to size 17. Run `rlang::last_trace()` to see where the error occurred.
Warning message: Returning more (or less) than 1 row per `summarise()` group was deprecated in dplyr 1.1.0. ℹ Please use `reframe()` instead. ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()` always returns an ungrouped data frame and adjust accordingly. ℹ The deprecated feature was likely used in the Distance package. Please report the issue at <https://github.com/DistanceDevelopment/Distance/issues>.


Eric Rexstad

unread,
Nov 8, 2023, 2:45:22 AM11/8/23
to vaughn...@gmail.com, distance-sampling
Greetings Vaughn

We have rectified this dependency in a commit to the Distance​ package in March 2023:


From: distance...@googlegroups.com <distance...@googlegroups.com> on behalf of vaughn...@gmail.com <vaughn...@gmail.com>
Sent: 07 November 2023 19:14
To: distance-sampling <distance...@googlegroups.com>
Subject: [distance-sampling] dplyr dependency error message when using dht2
 
--
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/a3697b7c-821e-41f5-9dc4-1aa32fba3446n%40googlegroups.com.

Eric Rexstad

unread,
Nov 8, 2023, 2:49:44 AM11/8/23
to vaughn...@gmail.com, distance-sampling
Sorry Vaughn, hit the send button inadvertently.

We made that change this past March
Simple distance sampling analysis. Contribute to DistanceDevelopment/Distance development by creating an account on GitHub.
This revision is reflected in the CRAN release 1.0.8 of the Distance​ package in July of this year.


Can you check that you are using version 1.0.8 of the Distance​ package?



From: distance...@googlegroups.com <distance...@googlegroups.com> on behalf of vaughn...@gmail.com <vaughn...@gmail.com>
Sent: 07 November 2023 19:14
To: distance-sampling <distance...@googlegroups.com>
Subject: [distance-sampling] dplyr dependency error message when using dht2
 

Vaughn Bodden

unread,
Nov 8, 2023, 11:27:42 AM11/8/23
to Eric Rexstad, distance-sampling
Thanks for the quick response, I updated my R packages and the dependency error has gone away,

I am still getting the other error though and i'm not sure what might be causing it. This code is mostly taken from https://examples.distancesampling.org/Distance-spec-covar/species-covariate-distill.html and had worked previously. 

Any ideas?

#base model for all species
> hn0.all.birds <- ds(data = GCbirds,
+                     key="hn", 
+                     adjustment = NULL,
+                     convert_units = unit_conversion,
+                     truncation = truncate, 
+                     cutpoints = cuts,
+                     transect = "point",
+                     formula= ~ species)
data already has distend and distbegin columns, removing them and appling binning as specified by cutpoints.
Fitting half-normal key function
AIC= 19026.929
> #Species specific density/ abundance estimates using dht2 function 
> bird.ests <- dht2(ddf=hn0.all.birds, 
+                   flatfile= GCbirds,
+                   strat_formula = ~ species, # this is required to get species-level estimates
+                   convert_units = unit_conversion,
+                   stratification = "object") 

> rlang::last_trace()
<error/tibble_error_assign_incompatible_size>

Error in `$<-`:
! Assigned data `diag(dm$variance)` must be compatible with existing data.
 Existing data has 12 rows.
 Assigned data has 11 rows.

 Only vectors of size 1 are recycled.
Caused by error in `vectbl_recycle_rhs_rows()`:
! Can't recycle input of size 11 to size 12.
---
Backtrace:
       1. ├─Distance::dht2(...)
  2. └─base::eval.parent(mc)
  3. └─base::eval(expr, p)
  4. └─base::eval(expr, p)
  5. └─Distance::dht2(...)
  6.   └─base::lapply(ddf, varNhat, data = res)
  7.     └─Distance (local) FUN(X[[i]], ...)
  8. base::`$<-`(`*tmp*`, "df_var", value = `<dbl>`)
  9.       └─tibble:::`$<-.tbl_df`(`*tmp*`, "df_var", value = `<dbl>`)
 10.         └─tibble:::tbl_subassign(...)
 11.           └─tibble:::vectbl_recycle_rhs_rows(value, fast_nrow(xo), i_arg = NULL, value_arg, call)
>

Eric Rexstad

unread,
Nov 8, 2023, 11:45:14 AM11/8/23
to Vaughn Bodden, distance-sampling
OK Vaughn, one step forward...

Your new problem seems to be messier. The cryptic error message seems to be complaining about the diagonal of the variance-covariance matrix.  I'm guessing you have either 11 or 12 species for which you are trying to produce abundance estimates.

This will likely require substantial ferreting around in the data. Is there a species that exists in the data, but falls away when this level of truncation is employed? Those are the vague, unhelpful thoughts that come to mind looking at the screenshot you provided. I could have a poke at it if you're willing to send along your data off-list.

I'm intrigued as to why this worked previously and not now. Share any thoughts about that you might have.

From: Vaughn Bodden <vaughn...@gmail.com>
Sent: 08 November 2023 16:27
To: Eric Rexstad <Eric.R...@st-andrews.ac.uk>
Cc: distance-sampling <distance...@googlegroups.com>
Subject: Re: [distance-sampling] dplyr dependency error message when using dht2
 

vaughn...@gmail.com

unread,
Nov 9, 2023, 12:31:57 PM11/9/23
to distance-sampling
Hi all 

Many thanks to Eric for assisting me off-list with this issue.

the error message above occurred when running a multi-species model but having blank entries for transect visits with no species detected. The ds() model worked fine but when I used the the dht2 function to get estimates for individual species it did not recognize the correct number of species in the dataset. 

We resolved this issue by manually inputting NA's into the species column.
E.g.
GCbirds$species <- ifelse(GCbirds$species=="", NA, GCbirds$species)

Vaughn 
Reply all
Reply to author
Forward
0 new messages