Skip to content

Commit 7a068f1

Browse files
committed
addressed PR comments, cleaned up some R CMD warnings
1 parent a91cd66 commit 7a068f1

28 files changed

+101
-42
lines changed

R/check_exp.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ check_exp <- function(ec, ec_names) {
22
#' Prepare expected catch matrix
33
#'
44
#' Checks that specified expected catch matrices exists and is formatted correctly
5-
#' when \code{\link{make_model_design}} is called.
5+
#' when \code{make_model_design} is called.
66
#'
77
#' @param ec Expected catch list created by \code{\link{create_expectations}}.
88
#' @param ec_names The names of the expected catch matrices to include in the
99
#' model and how they are used (i.e. used together or separately). See the
10-
#' \code{expectcatchmodels} argument in \code{\link{make_model_design}}.
10+
#' \code{expectcatchmodels} argument in \code{make_model_design}.
1111
#' @returns Returns a list containing the filtered expected catch list and specified
1212
#' matrices to include in model.
1313
#' @details Checks that \code{ec_names} is specified properly by identifying

R/create_alternative_choice.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,25 @@
8181
#' @details Defines the alternative fishing choices. These choices are used to develop
8282
#' the matrix of distances between observed and alternative fishing choices (where
8383
#' they could have fished but did not). The distance matrix is calculated by the
84-
#' [make_model_design()] function. `occasion` defines the observed fishing
84+
#' [format_model_data()] function. `occasion` defines the observed fishing
8585
#' location and `alt_var` the alternative fishing location. `occasion_var`
8686
#' identifies an ID column or set of lon-lat variables needed to create the
8787
#' distance matrix.
8888
#'
8989
#' Parts of the alternative choice list are pulled by [create_expectations()],
90-
#' [make_model_design()], and the model run [discretefish_subroutine()])
90+
#' [format_model_data()], and the model run [fishset_fit()])
9191
#' functions. These output include choices of which variable to use for catch and
9292
#' which zones to include in analyses based on a minimum number of hauls per trip
9393
#' within a zone. Note that if the alternative choice list is modified, the
94-
#' [create_expectations()] and [make_model_design()] functions
94+
#' [create_expectations()] and [format_model_data()] functions
9595
#' should also be updated before rerunning models.
9696
#'
9797
#' @return Function saves a list of alternative choice matrices to the FishSET
9898
#' database as `projectAlternativeChoice`. The list includes
9999
#' the alternative choice list from the user-defined choices. Multiple alternative
100100
#' choice cases can be added to the list by specifying unique names. The list is
101101
#' automatically saved to the FishSET database and is called in
102-
#' `make_model_design`.
102+
#' `format_model_data`.
103103

104104
create_alternative_choice <- function(dat,
105105
project,

R/create_dist_matrix.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#' @importFrom stats setNames
2929
#' @export
3030
#' @keywords internal
31-
#' @details Function is called by \code{\link{make_model_design}} to generate the
31+
#' @details Function is called by \code{\link{format_model_data}} to generate the
3232
#' distance matrix. Alternative fishing options come from the Alternative Choice
3333
#' list, generated from the \code{\link{create_alternative_choice}} function.
3434
#' @return

R/create_expectations.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' Create expected catch/expected revenue matrix
22
#'
33
#' Create expected catch or expected revenue matrix. The matrix is required for
4-
#' the \code{\link{logit_c}} model. Multiple matrices (with unique names) can be saved in a
4+
#' the conditional logit model. Multiple matrices (with unique names) can be saved in a
55
#' project.
66
#'
77
#' @param dat Primary data containing information on hauls or trips. Table in FishSET
@@ -55,11 +55,11 @@
5555
#' as \code{projectExpectedCatch}. The list includes
5656
#' the expected catch matrix from the user-defined choices. Multiple expected catch cases
5757
#' can be added to the list by specifying unique names. The list is automatically saved to
58-
#' the FishSET database and is called in \code{\link{make_model_design}}. The expected catch
58+
#' the FishSET database and is called in \code{\link{format_model_data}}. The expected catch
5959
#' output does not need to be loaded when defining or running the model.
6060
#' @details Function creates an expectation of catch or revenue for alternative
6161
#' fishing zones (zones where they could have fished but did not). The output is
62-
#' saved to the FishSET database and called by the \code{\link{make_model_design}}
62+
#' saved to the FishSET database and called by the \code{\link{format_model_data}}
6363
#' function. \code{\link{create_alternative_choice}} must be called first as observed
6464
#' catch and zone inclusion requirements are defined there.\cr
6565
#' The primary choices are whether to treat data as a fleet or to group the data

R/epm_lognormal.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ epm_lognormal <- function(starts3, dat, otherdat, alts, project, expname, mod.na
3030
#' @param expname Expected catch table (optional)
3131
#' @param mod.name Name of model run for model result output table
3232
#' @return ld: negative log likelihood
33-
#' @details This function is called in \code{\link{discretefish_subroutine}} when running an EPM model with
33+
#' @details This function is called in \code{discretefish_subroutine} when running an EPM model with
3434
#' a log-normal catch function.
3535
#' @export
3636

R/epm_normal.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ epm_normal <- function(starts3, dat, otherdat, alts, project, expname, mod.name)
2929
#' @param expname Expected catch table (optional)
3030
#' @param mod.name Name of model run for model result output table
3131
#' @return ld: negative log likelihood
32-
#' @details This function is called in \code{\link{discretefish_subroutine}} when running an EPM model with
32+
#' @details This function is called in \code{discretefish_subroutine} when running an EPM model with
3333
#' a normal catch function.
3434
#' @export
3535

R/epm_weibull.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ epm_weibull <- function(starts3, dat, otherdat, alts, project, expname, mod.name
3030
#' @param expname Expected catch table (optional)
3131
#' @param mod.name Name of model run for model result output table
3232
#' @return ld: negative log likelihood
33-
#' @details This function is called in \code{\link{discretefish_subroutine}} when running an EPM model with
33+
#' @details This function is called in \code{discretefish_subroutine} when running an EPM model with
3434
#' a Weibull catch function.
3535
#' @export
3636

R/fishset_fit.R

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,30 @@
3636
#' \item{diagnostics}{A list containing the Hessian, gradients, eigenvalues, and
3737
#' condition number.}
3838
#' }
39+
#'
40+
#' @examples
41+
#' \dontrun{
42+
#' # 1. Standard fit using default settings
43+
#' # This uses the design object named "clogit_design" saved in "MyProject"
44+
#' fit_result <- fishset_fit(
45+
#' project = "MyProject",
46+
#' model_name = "clogit_design"
47+
#' )
48+
#'
49+
#' # 2. Advanced fit with custom optimization settings and start values
50+
#' # 'control' and 'start_values' are passed via the '...' argument
51+
#' fit_custom <- fishset_fit(
52+
#' project = "MyProject",
53+
#' model_name = "clogit_design",
54+
#' fit_name = "clogit_custom_fit",
55+
#'
56+
#' # Pass control list to nlminb (e.g., increase max iterations, turn on tracing)
57+
#' control = list(eval.max = 5000, iter.max = 5000, trace = 1),
58+
#'
59+
#' # Pass initial start values for the parameters (e.g., for 2 predictors)
60+
#' start_values = c(0.5, -0.2)
61+
#' )
62+
#' }
3963
#'
4064
#' @seealso \code{\link{fishset_design}} for creating the input design object.
4165
#'
@@ -62,7 +86,16 @@ fishset_fit <- function(project,
6286

6387
design <- full_design_list[[model_name]]
6488

65-
if (is_empty(fit_name)) fit_name <- paste0(model_name, "_fit")
89+
# Load model fit list and check fit_name input
90+
full_fit_list <- unserialize_table(paste0(project, "ModelFit"), project)
91+
92+
if (is_empty(fit_name)) {
93+
fit_name <- paste0(model_name, "_fit")
94+
}
95+
96+
if (fit_name %in% names(full_fit_list)) {
97+
stop(paste0("Model fit '", fit_name, "' already exists. Enter a new fit_name."))
98+
}
6699

67100
# Extract "..." arguments -----------------------------------------------------------------------
68101
dots <- list(...)
@@ -298,6 +331,7 @@ fishset_fit <- function(project,
298331
class(result) <- "fishset_fit"
299332

300333
# Save to database ------------------------------------------------------------------------------
334+
# Check if fit_name exists
301335
fishset_db <- DBI::dbConnect(RSQLite::SQLite(), locdatabase(project = project))
302336
on.exit(DBI::dbDisconnect(fishset_db), add = TRUE)
303337

@@ -389,6 +423,6 @@ print.fishset_fit <- function(x, digits = 4, ...) {
389423
p_val_str <- format.pval(x$LR_p_value, eps = 0.001)
390424
cat("LR Test: Chi2 =", fmt(x$LR_stat, 2), ", p =", p_val_str, sig_star, "\n")
391425
}
392-
426+
393427
invisible(x)
394428
}

R/format_grid.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' Change the format of a gridded dataset from wide to long (or vice versa)
44
#' and remove any unmatched area/zones from `grid`. This is a necessary step
5-
#' for including gridded variables in the conditional logit ([logit_c()]) model.
5+
#' for including gridded variables in the conditional logit model.
66
#'
77
#' @param grid Gridded dataset to format.
88
#' @param dat Primary data containing information on hauls or trips. Table in

R/model_prediction.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#' @importFrom yaml read_yaml
1919
#' @importFrom DBI dbConnect dbDisconnect dbGetQuery
2020
#' @importFrom RSQLite SQLite
21-
#' @details Calls \code{\link{logit_predict}}, \code{\link{epm_predict}}, and
21+
#' @details Calls \code{logit_predict}, \code{epm_predict}, and
2222
#' \code{\link{predict_probability}}. Closure scenarios and TAC must be define using
2323
#' \code{\link{zone_closure}} function before function can be run.
2424
#' @export

0 commit comments

Comments
 (0)