Skip to content
Merged
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Description: Animal abundance estimation via conventional, multiple covariate
fitting is performed via maximum likelihood. Also included are diagnostics
and plotting for fitted detection functions. Abundance estimation is via a
Horvitz-Thompson-like estimator.
Version: 3.0.0.9001
Version: 3.0.0.9004
URL: https://github.com/DistanceDevelopment/mrds/
BugReports: https://github.com/DistanceDevelopment/mrds/issues
Depends:
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Bug Fixes

* Fixed formatting issue in flnl.grad help
* Now displays a warning if the user tries to fit a detection function with covariates using MCDS.exe which is not either a half-normal or a hazard rate model. (Issue #113)
* Fixed so that the MCDS.exe does not try to fit a negative exponential in place of a gamme key function. (Issue #113)

# mrds 3.0.0

Expand Down
15 changes: 15 additions & 0 deletions R/ddf.ds.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,21 @@ ddf.ds <-function(dsmodel, mrmodel = NULL,
if(control$optimizer == "MCDS" && system.file("MCDS.exe", package="mrds") == ""){
stop("You have chosen to use the MCDS.exe optimizer but it cannot be found!", call. = FALSE)
}

# Validate options are suitable for MCDS
if(control$optimizer %in% c("MCDS","both") && system.file("MCDS.exe", package="mrds") != ""){
MCDS.options.valid <- validate.MCDS.options(model)
# If NULL there are no issues
if(!is.null(MCDS.options.valid)){
R.opt.message <- ifelse(control$optimizer == "MCDS",
"The R optimizer will be used instead.",
"Only the R optimizer will be used.")
# Otherwise there are issues so use the R optimizer
warning(paste(MCDS.options.valid, R.opt.message, sep = " "),
immediate. = TRUE, call. = FALSE)
control$optimizer <- "R"
}
}

# run MCDS.exe if it's there
if(control$optimizer %in% c("MCDS","both") && system.file("MCDS.exe", package="mrds")!=""){
Expand Down
28 changes: 27 additions & 1 deletion R/mcds_tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ create.command.file <- function(dsmodel=call(), data,
}else if(mod.vals$key == "unif"){
cat("UNIFORM", file=command.file.name, append=TRUE)
}else{
cat("NEXPON", file=command.file.name, append=TRUE)
stop("Unrecognised key function for the detection function in MCDS.exe", call. = FALSE)
}

adj.pres <- FALSE
Expand Down Expand Up @@ -639,3 +639,29 @@ create.data.file <- function(data, dsmodel, data.file){
cluster = cluster)
return(output)
}


validate.MCDS.options <- function(model){
# Validates the options are suitable for MCDS

# Extract values from the formula
mod_paste <- paste(model)
mod.vals <- try(eval(parse(text=mod_paste[2:length(mod_paste)])))

# Check if the user is trying to fit a gamma model
if(mod.vals$key == "gamma"){
return("MCDS.exe cannot fit a gamma detection function model.")
}

# Check if there are covariates
if(mod.vals$formula != ~1){
# if so only HN and HR permitted
if(!mod.vals$key %in% c("hn", "hr")){
return("MCDS.exe can only fit covariates with the half-normal and hazard rate key functions.")
}
}

# If no issue return NULL
return(NULL)
}

Loading