Error when fitting basic models

50 views
Skip to first unread message

Luke Vander Vennen

unread,
Sep 6, 2024, 3:10:50 AM9/6/24
to distance-sampling
Hi all, apologies if this is not the correct forum for this question. 
I keep bumping into what I think may be a bug. I'm getting an error when trying to fit any model using the ds() function, including a simple model taken directly from the "Line transect density estimation" example. I get this error when working in RStudio, but I can run the model without errors when working with R outside of RStudio. Has anyone else had this issue? I'm running R version 4.4.1, Distance 1.0.9, and a new download of RStudio. Code and error below, any insights are greatly appreciated.

library(Distance)
data(wren_lt)
conversion.factor <- convert_units("meter", "kilometer", "hectare")
wren.hn <- ds(data=wren_lt, key="hn", adjustment=NULL,
              convert_units=conversion.factor)

Fitting half-normal key function
Error in if (ddfobj$type == "logistic") { : argument is of length zero

All models failed to fit!

Error: No models could be fitted.

Eric Rexstad

unread,
Sep 6, 2024, 3:22:28 AM9/6/24
to Luke Vander Vennen, distance-sampling
Hi Luke.

Welcome to the forum. This is indeed the right place to submit such questions.

I lifted the code from your email and ran it in RStudio on my machine. It successfully fit the half normal without adjustments to the line transect wren data.  


I don't know why you say you can have success in fitting the model when not using RStudio. I've not heard that previously reported.

One thing I ask that you check is the version of the mrds package installed on your computer. The error message you show is actually generated by a function in the mrds package that is being called by the ds function.  The most recent version of the mrds package is 2.3.0. Can you double check that?

For info, I'm running RStudio 2024.08.0+341 "Cranberry Hibiscus" Release, but I've not had the error you report using previous RStudio versions.  My troubleshooting mind thinks the problem lives with your version of mrds.  Let us know what you discover.

From: distance...@googlegroups.com <distance...@googlegroups.com> on behalf of Luke Vander Vennen <lukevand...@gmail.com>
Sent: 06 September 2024 08:05
To: distance-sampling <distance...@googlegroups.com>
Subject: [distance-sampling] Error when fitting basic models
 
--
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/79ecce86-2a48-4962-82ec-044b507c5b34n%40googlegroups.com.

Luke Vander Vennen

unread,
Sep 6, 2024, 1:34:24 PM9/6/24
to Eric Rexstad, distance-sampling
Hi Eric, thanks very much for your response. 
I think I've figured it out. Every time I open RStudio I run a script to load a batch of packages that I use in my day to day work. One of these packages is formula.tools, which appears to have a conflict with the Distance package. The models seem to work fine if I do not load the formula.tools package. This also explains why the models were running properly in R and not in RStudio, as I wasn't loading all of those other packages when testing this error in R outside of RStudio. Phewf.

Many thanks,
Luke

Eric Rexstad

unread,
Sep 7, 2024, 2:49:15 AM9/7/24
to Luke Vander Vennen, distance-sampling
Luke

Thanks for troubleshooting your issue. I didn't know about a conflict with the formula.tools package. I'll have a look at that package.

Appreciate you reporting back to the list for the benefit of others who might encounter this issue.

Sent: 06 September 2024 18:34
To: Eric Rexstad <Eric.R...@st-andrews.ac.uk>
Cc: distance-sampling <distance...@googlegroups.com>
Subject: Re: [distance-sampling] Error when fitting basic models
 
Reply all
Reply to author
Forward
0 new messages