tmcd82070 / Rdistance

An R package for simple, regression-like, distance-based analyses
8 stars 3 forks source link

Name of dist column in detection data may cause issues in abundEstim #106

Closed jcarlis3 closed 1 year ago

jcarlis3 commented 1 year ago

A while back, the distance column in detectionData had to be named "dist", but now it's more flexible and pulled from the formula. But there's a check in abundEstim that still expects the column to be called "dist".

I had a distance column named something else, and got this warning when running abundEstim.

Warning message: Unknown or uninitialised column: 'dist'.

I figured this line near the top of abundEstim was the culprit:

  if(any(is.na(detectionData$dist))) stop("Please remove rows for which detectionData$dist is NA.")

But I can't reproduce the warning even when making fake data with a different column name. I'm a bit confused. This runs great, no warnings or errors.

# Example data
# Sites
(sdf <- data.frame(siteID = c("A", "B"),
                   length = units::set_units(c(2, 2.5), "km")))

# Detections
d <- rnorm(n = 100, sd = 35)
d <- d[d > 0]
hist(d)
(ddf <- data.frame(siteID = sample(c("A", "B"),
                                   size = length(d),
                                   replace = TRUE),
                   groupsize = 1,
                   nonStandardDistName = units::set_units(d, "m")))

# Fit distance sampling model
dfuncFit <- dfuncEstim(nonStandardDistName ~ 1,
                       detectionData = ddf,
                       likelihood = "halfnorm")

abundFit <- abundEstim(dfuncFit,
                       detectionData = ddf,
                       siteData = sdf,
                       ci = NULL)
abundFit

Any idea what's going on here? I'm using v 2.2.0 from GitHub.

tmcd82070 commented 1 year ago

I think I rename the distance column to 'dist'. I think I rename "nonStandardDistName" to "dist". That's clunky I know.

I have no idea where that warning came from. I've had that weird warning in Rstudio and it keeps coming up even when it is clearly not happening. Did you restart Rstudio inbetween?

On Mon, Apr 10, 2023 at 4:35 PM Jason Carlisle @.***> wrote:

A while back, the distance column in detectionData had to be named "dist", but now it's more flexible and pulled from the formula. But there's a check in abundEstim that still expects the column to be called "dist".

I had a distance column named something else, and got this warning when running abundEstim.

Warning message: Unknown or uninitialised column: 'dist'.

I figured this line near the top of abundEstim was the culprit:

if(any(is.na(detectionData$dist))) stop("Please remove rows for which detectionData$dist is NA.")

But I can't reproduce the warning even when making fake data with a different column name. I'm a bit confused. This runs great, no warnings or errors.

Example data

Sites

(sdf <- data.frame(siteID = c("A", "B"), length = units::set_units(c(2, 2.5), "km")))

Detections

d <- rnorm(n = 100, sd = 35) d <- d[d > 0] hist(d) (ddf <- data.frame(siteID = sample(c("A", "B"), size = length(d), replace = TRUE), groupsize = 1, nonStandardDistName = units::set_units(d, "m")))

Fit distance sampling model

dfuncFit <- dfuncEstim(nonStandardDistName ~ 1, detectionData = ddf, likelihood = "halfnorm")

abundFit <- abundEstim(dfuncFit, detectionData = ddf, siteData = sdf, ci = NULL) abundFit

Any idea what's going on here? I'm using v 2.2.0 from GitHub.

— Reply to this email directly, view it on GitHub https://github.com/tmcd82070/Rdistance/issues/106, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABEZRTFSGYQ5B7ILFHIMWEDXASDLDANCNFSM6AAAAAAWZP3KVA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- [image: Logo] https://mcdonalddatasciences.com/ Trent McDonald, Ph.D. | President and Founder

McDonald Data Sciences, LLCClear, Concise, Cutting-edge Analyses w: mcdonalddatasciences.com http://mcdonalddatasciences.com/ p: 307.760.4721

jcarlis3 commented 1 year ago

Copy that. Yes, seems like RStudio may be causing that warning about the unknown column. A restart of RStudio didn't solve it, but I just renamed the input column "dist", and it went away. I think we can consider this closed.