DistanceDevelopment / Distance

Simple distance sampling analysis
GNU General Public License v3.0
9 stars 8 forks source link

Uniform key function with adjustments throws error in mcds.exe branch #164

Closed lenthomas closed 1 year ago

lenthomas commented 1 year ago

mrds 2.2.8.9005; Distance 1.0.7.9001; R 4.2.3 mcds.exe present

Fitting uniform + 1 cosine causes an error:

DuikerCameraTraps <- read.csv(file="https://datadryad.org/stash/downloads/file_stream/73221", 
                              header=TRUE, sep="\t")
DuikerCameraTraps$Area <- DuikerCameraTraps$Area / (1000*1000)
library(Distance)
conversion <- convert_units("meter", NULL, "square kilometer")
trunc.list <- list(left=2, right=15)
mybreaks <- c(seq(2, 8, 1), 10, 12, 15)
uni1 <- ds(DuikerCameraTraps, transect = "point", key="unif", adjustment = "cos",
           nadj=1,
           cutpoints = mybreaks, truncation = trunc.list)

Get

Fitting uniform key function with cosine(1) adjustments
Error in setinitial.ds(ddfobj, width = meta.data$width, initial, point,  : 
  Length of initial values for scale incorrect
In addition: Warning messages:
1: In create_bins(data, cutpoints) :
  Some distances were outside bins and have been removed.
2: In system(paste0(path_to_MCDS_dot_exe, " 0, ", test_file$command.file.name),  :
  running command 'C:/Users/lt5/AppData/Local/R/win-library/4.2/mrds/MCDS.exe 0, C:\Users\lt5\AppData\Local\Temp\RtmpesO9ML\cmdtmp5858621528ca.txt' had status 1
AIC= 44092.515

When I try with skipping R I get

uni1 <- ds(DuikerCameraTraps, transect = "point", key="unif", adjustment = "cos",
           nadj=1,
           cutpoints = mybreaks, truncation = trunc.list, skip_R = TRUE)
Fitting uniform key function with cosine(1) adjustments
Error in setinitial.ds(ddfobj, width = meta.data$width, initial, point,  : 
  Length of initial values for scale incorrect
In addition: Warning messages:
1: In create_bins(data, cutpoints) :
  Some distances were outside bins and have been removed.
2: In system(paste0(path_to_MCDS_dot_exe, " 0, ", test_file$command.file.name),  :
  running command 'C:/Users/lt5/AppData/Local/R/win-library/4.2/mrds/MCDS.exe 0, C:\Users\lt5\AppData\Local\Temp\RtmpesO9ML\cmdtmp5858130310f0.txt' had status 1
Error in if (lt$message == "FALSE CONVERGENCE") { : 
  argument is of length zero

All models failed to fit!

Error in ds(DuikerCameraTraps, transect = "point", key = "unif", adjustment = "cos",  : 
  No models could be fitted.

but it works if skip_mcds = TRUE so it looks like an mcds.exe initialization problem.

LHMarshall commented 1 year ago

@lenthomas I cannot replicate this bug - nor do I get warnings about distances outside of bins, has this dataset changed?

DuikerCameraTraps <- read.csv(file="https://datadryad.org/stash/downloads/file_stream/73221", 
                              header=TRUE, sep="\t")
DuikerCameraTraps$Area <- DuikerCameraTraps$Area / (1000*1000)
library(Distance)
conversion <- convert_units("meter", NULL, "square kilometer")
trunc.list <- list(left=2, right=15)
mybreaks <- c(seq(2, 8, 1), 10, 12, 15)

uni1 <- ds(DuikerCameraTraps, transect = "point", key="unif", adjustment = "cos",
           nadj=1,cutpoints = mybreaks, truncation = trunc.list)

summary(uni1)
#AIC         :  44092.51 
#Optimisation:  mrds (nlminb) 
#              estimate          se
# cos, order 1 0.9428326 0.004394167

uni1 <- ds(DuikerCameraTraps, transect = "point", key="unif", adjustment = "cos",
           nadj=1,cutpoints = mybreaks, truncation = trunc.list, optimizer = "MCDS")

summary(uni1)
#AIC         :  44092.51 
#Optimisation:  MCDS.exe
#              estimate         se
# cos, order 1 0.9428032 0.00439516

image

lenthomas commented 1 year ago

Yes, I agree - I'll close this issue, thanks.