Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 78 additions & 102 deletions MCDS-dot-exe-Report.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,53 @@ editor_options:
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
source("Support.R")
library(kableExtra)
library(Distance)
library(gt)
library(kableExtra)

knitr::opts_chunk$set(echo = TRUE)
re_eval <- FALSE

source("Support.R")
```

## Things outstanding in mrds

In addition to the notes throughout this document the following also
needs further work or investigations:

- Issue 83 in mrds relating to factor ordering differences between
mrds and MCDS
- **FIXED** Issue 83 in mrds relating to factor ordering differences
between mrds and MCDS
(<https://github.com/DistanceDevelopment/mrds/issues/83>)

- Reading in and processing the warnings and / or errors in the log
- **Now seems to spot and display warnings and errors from MCDS** Reading in and processing the warnings and / or errors in the log
file generated by MCDS - What do we do about cases where mcds.exe
fits with negative pdf? E.g.
<https://github.com/DistanceDevelopment/Distance/issues/160>

- Do the monotonicity constraints get passed to MCDS correctly?
- Do the monotonicity constraints get passed to MCDS correctly? **YES**

- Check the passing of parameter starting values to MCDS - also
potential issues here regarding factor ordering!
- Check the passing of parameter starting values to MCDS - also
potential issues here regarding factor ordering! **Now passing parameter start values - no problems with factor ordering as this is dealt with by the reordering of the factor names passed to MCDS**

- Check the passing of parameter bound to MCDS - again potential for
factor ordering issues. Note this can only be done via mrds NOT via
Distance.
- **Made errors into non fatal warnings and messages**

- Check the passing of parameter bound to MCDS. Note this can only be done via mrds NOT via
Distance. Low priority - not done

- Could do with more tests of the case of uniform only models to check that abundance estimates are correctly calculated.

\newpage

## Capercaillie Data

Things that might want further investigation:
Various warnings and errors that want further investigation:
```{r warn_capercaillie, eval = re_eval}
# MCDS warning - does this want removed?
# ** Warning: One or more cluster sizes are coded as -1. Distance assumes -1 to mean a cluster of undetermined size. These observations are used for estimating detection probability and encounter rate, but not cluster size. **

```

- When the R optimiser is selected both the lnl_R and lnl_MCDS values
appear to be the same in all cases. (After moving on to other
datasets this is not found to be the case.)

```{r capercaillie, eval = re_eval}
data("capercaillie")
Expand Down Expand Up @@ -88,13 +94,40 @@ Things that might want further investigation:
- Nhat for the hn herm 1 model is \~14% higher for the MCDS optimised
model than the R optimised model

- Why is the lnl_R value for the hr poly 2 model negative?
- Why is the lnl_R value for the hr poly 2 model negative? This has now changed!

Various warnings and errors that want further investigation:
```{r warn_cuecount, eval = re_eval}
# Fitting hazard-rate key function with simple polynomial(4,6) adjustments
# ** Warning: One or more cluster sizes are coded as -1. Distance assumes -1 to mean a cluster of undetermined size. These observations are used for estimating detection probability and encounter rate, but not cluster size. **
# Warning: Detection function is not strictly monotonic!Warning: Detection function is less than 0 at some distancesWarning: Detection function is not strictly monotonic!
# Warning: Detection function is less than 0 at some distancesAIC= -0.103
# Fitting half-normal key function with Hermite(4,6) adjustments
# ** Warning: One or more cluster sizes are coded as -1. Distance assumes -1 to mean a cluster of undetermined size. These observations are used for estimating detection probability and encounter rate, but not cluster size. **
# ** Warning: convergence failure **
# Warning in check.mono(result, n.pts = control$mono.points) :
# Detection function is not strictly monotonic!
# Warning in check.mono(result, n.pts = control$mono.points) :
# Detection function is not strictly monotonic!
# AIC= -1.752
# Warning in mrds::check.mono(model, n.pts = 20) :
# Detection function is not strictly monotonic!
# No survey area information supplied, only estimating detection function.
#
# Fitting half-normal key function with Hermite(4,6) adjustments
# ** Warning: One or more cluster sizes are coded as -1. Distance assumes -1 to mean a cluster of undetermined size. These observations are used for estimating detection probability and encounter rate, but not cluster size. **
# ** Warning: convergence failure **
# Warning in check.mono(result, n.pts = control$mono.points) :
# Detection function is not strictly monotonic!
# AIC= 1.966
# No survey area information supplied, only estimating detection function.
```

```{r cuecounting, eval = re_eval}
data("CueCountingExample")

model.compare <- test.models(CueCountingExample,
truncation = max(CueCountingExample$distance),
truncation = max(CueCountingExample$distance, na.rm = TRUE),
transect = "point")

save(model.compare, file = "results/cue_counting.ROBJ")
Expand All @@ -119,22 +152,22 @@ knitr::kable(model.compare,

Things that might want further investigation:

- Unhelpful error "Error in array(x, c(length(x), 1L), if
(!is.null(names(x))) list(names(x), : 'data' must be of a vector
type, was 'NULL' Error in t(partial) %\*% vcov : requires
numeric/complex matrix/vector arguments"

- What should happen when you have a uniform with no adjustments???
Shouldn't P always be 1?

- p_MCDS is 1 for a few of these models and when it is, it is
estimating Nhat much lower than the R optimiser.

```{r warn_ducknest}
# Fitting half-normal key function with Hermite(4,6) adjustments
# Warning: First partial hessian is singular and second-partial hessian is NULL, no hessian
# AIC= 932.07
# No hessian, possible numerical problems; only estimating detection function.
```

```{r ducknest, eval = re_eval}
data("ducknest")

model.compare <- test.models(ducknest,
truncation = max(ducknest$distance),
truncation = max(ducknest$distance, na.rm = TRUE),
transect = "line")

save(model.compare, file = "results/ducknest.ROBJ")
Expand All @@ -157,11 +190,20 @@ knitr::kable(model.compare,

## DuikerCameraTraps

Things that might want further investigation: - - Unhelpful error "Error
in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), :
'data' must be of a vector type, was 'NULL' Error in t(partial) %\*%
vcov : requires numeric/complex matrix/vector arguments" - Some of the
Nhat values look to differ by around 20% between the two optimisers
Things that might want further investigation:
- Nhat values look to differ by around 20% between the two optimisers


```{r warn_duiker}
# Fitting half-normal key function with Hermite(4,6) adjustments
# Warning: First partial hessian is singular; using second-partial hessian
# Warning: First partial hessian is singular; using second-partial hessian
# AIC= 25014.184
# Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), :
# 'data' must be of a vector type, was 'NULL'
# Error in t(partial) %*% vcov :
# requires numeric/complex matrix/vector arguments
```

```{r duiker, eval = re_eval}
data("DuikerCameraTraps")
Expand Down Expand Up @@ -199,7 +241,7 @@ truncation distance specified; using largest observed distance"?
data("LTExercise")

model.compare <- test.models(LTExercise,
truncation = max(LTExercise$distance),
truncation = max(LTExercise$distance, na.rm = TRUE),
transect = "line")

save(model.compare, file = "results/LTExercise.ROBJ")
Expand Down Expand Up @@ -230,7 +272,7 @@ truncation distance specified; using largest observed distance"?
data("PTExercise")

model.compare <- test.models(PTExercise,
truncation = max(PTExercise$distance),
truncation = max(PTExercise$distance, na.rm = TRUE),
transect = "point")

save(model.compare, file = "results/PTExercise.ROBJ")
Expand Down Expand Up @@ -404,22 +446,6 @@ knitr::kable(model.compare,

## Wren line transect

Some errors:

```{r errors_wrenlt}
# Fitting half-normal key function with Hermite(4,6) adjustments
# AIC= 1417.081
# Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), :
# 'data' must be of a vector type, was 'NULL'
# Error in t(partial) %*% vcov :
# requires numeric/complex matrix/vector arguments
# Fitting half-normal key function with Hermite(4,6) adjustments
# AIC= 1417.081
# Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), :
# 'data' must be of a vector type, was 'NULL'
# Error in t(partial) %*% vcov :
# requires numeric/complex matrix/vector arguments
```

```{r wren_lt, eval = re_eval}
data("wren_lt")
Expand Down Expand Up @@ -450,22 +476,6 @@ knitr::kable(model.compare,

Some errors / warnings:

```{r errors_wrensnapshot}
# Warning in check.mono(result, n.pts = control$mono.points) :
# Detection function is less than 0 at some distances
# AIC= 2e+24
# Warning in mrds::check.mono(model, n.pts = 20) :
# Detection function is less than 0 at some distances
# Some variance-covariance matrix elements were NA, possible numerical problems; only estimating detection function.
# ...
# Fitting half-normal key function with Hermite(4,6) adjustments
# AIC= 1069.234
# Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), :
# 'data' must be of a vector type, was 'NULL'
# Error in t(partial) %*% vcov :
# requires numeric/complex matrix/vector arguments
```

```{r wren_snapshot, eval = re_eval}
data("wren_snapshot")

Expand Down Expand Up @@ -493,6 +503,8 @@ knitr::kable(model.compare,

## dathr1

Some estimates of abundance differ significantly!

```{r dathr1, eval = re_eval}
load(file = "data/dathr1.RData")

Expand Down Expand Up @@ -549,26 +561,6 @@ knitr::kable(model.compare,

Some errors / warnings:

```{r errors_dathr3}
# Fitting half-normal key function with Hermite(4,6) adjustments
# Error in -lt$value : invalid argument to unary operator
# In addition: Warning message:
# In system(paste0(path.to.MCDS.dot.exe, " 0, ", test.file$command.file.name), :
# running command 'C:/Users/lhm/AppData/Local/R/win-library/4.2/mrds/MCDS.exe 0, C:\Users\lhm\AppData\Local\Temp\Rtmp8YZzC4\cmdtmp8e5c1a9825d0.txt' had status 3
# Error in if (lt$message == "FALSE CONVERGENCE") { :
# argument is of length zero
#
#
# All models failed to fit!
#
# Error in ds(dist.data, truncation = truncation, transect = transect, formula = ~1, :
# No models could be fitted.
# Fitting half-normal key function with Hermite(4,6) adjustments
# Error in -lt$value : invalid argument to unary operator
# In addition: Warning message:
# In system(paste0(path.to.MCDS.dot.exe, " 0, ", test.file$command.file.name), :
# running command 'C:/Users/lhm/AppData/Local/R/win-library/4.2/mrds/MCDS.exe 0, C:\Users\lhm\AppData\Local\Temp\Rtmp8YZzC4\cmdtmp8e5c16877002.txt' had status 3
```

```{r dathr3, eval = re_eval}
load(file = "data/dathr3.RData")
Expand Down Expand Up @@ -733,23 +725,12 @@ knitr::kable(model.compare,

```


\newpage

## ETP Dolphins

Some errors / warnings:

```{r errors_ETP}
# Fitting half-normal key function
# Error in -lt$value : invalid argument to unary operator
#
#
# All models failed to fit!
#
# Error in ds(dist.data, truncation = truncation, transect = transect, formula = models[[i]], :
# No models could be fitted.
```

```{r ETP_Dolphin, eval = re_eval}
data("ETP_Dolphin")
Expand All @@ -775,8 +756,6 @@ knitr::kable(model.compare,

```



\newpage

## Minke data
Expand Down Expand Up @@ -805,8 +784,7 @@ knitr::kable(model.compare,

```

## Cluster Exercise

## Cluster Exercise

```{r ClusterExercise, eval = re_eval}
data("ClusterExercise")
Expand All @@ -832,5 +810,3 @@ knitr::kable(model.compare,
kable_styling(latex_options = "HOLD_position")

```


Loading