Skip to content

Commit c04fc20

Browse files
Model fit (#358)
* started new model design function * started fishset model design function * started format data function * working on formal data function, but need to figure out create_distance_matrix * working on updating create_dist_matrix * cleaned up code in create_distance_matrix but still need to run tests and make output consistent * refactored create_distance_matrix * added unit tests for create_dist_matrix and updated documentaiton * updated model design section for creating distance matrix * added 'long format data' to data types for unserialize_table * format_model_deisgn completed but need some minor changes * finished format_model_data() and added unit tests * finished fishset_design function * added unit tests for fishset_design * clean up comments for testing * fixed issues with unit tests * commented out modeling code in vignette for now * mostly completed the fishset_fit() function * added sql table save to fishset_fit * added unit tests for fishset_fit * added RTMB to DESCRIPTION file * remove NULL default for alt_name * fixed mismatch in data class types * added code to check class of unique ID * added a 'native' print function for the fishset_fit function * addressing PR review comments * fix unit tests for format_model_data * fix merge conflict in globals.r * clean up more conflicts * added error check for unique obs id in format_model_data * minor updates * updated unit tests * removed a bunch of old modeling functions * delete a bunch of old modeling functions * addressed PR comments, cleaned up some R CMD warnings
1 parent 88893a8 commit c04fc20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+830
-5119
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Imports:
7272
readxl,
7373
rlang,
7474
RSQLite,
75+
RTMB,
7576
scales,
7677
servr,
7778
sf (>= 1.0-0),

NAMESPACE

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
S3method(print,fishset_fit)
34
export(ID_var)
45
export(aboutUI)
56
export(add_prompter)
@@ -36,13 +37,10 @@ export(create_dist_between_for_gui)
3637
export(create_dist_matrix)
3738
export(create_duration)
3839
export(create_expectations)
39-
export(create_logit_input)
4040
export(create_mid_haul)
41-
export(create_model_input)
4241
export(create_proj_settings)
4342
export(create_seasonal_ID)
4443
export(create_var_num)
45-
export(cross_validation)
4644
export(current_db_table)
4745
export(current_log)
4846
export(current_out)
@@ -63,7 +61,6 @@ export(delete_meta)
6361
export(delete_models)
6462
export(density_plot)
6563
export(deparse_name)
66-
export(discretefish_subroutine)
6764
export(dms_to_dd)
6865
export(dms_to_pdms)
6966
export(dummy_matrix)
@@ -75,16 +72,12 @@ export(empty_vars)
7572
export(empty_vars_filter)
7673
export(epm_lognormal)
7774
export(epm_normal)
78-
export(epm_predict)
7975
export(epm_weibull)
8076
export(erase_project)
8177
export(exp_catch_names)
8278
export(expand_data)
8379
export(expected_catch_list)
84-
export(explore_startparams)
85-
export(explore_startparams_discrete)
8680
export(filter_dat)
87-
export(filter_outsample)
8881
export(filter_summary)
8982
export(filter_table)
9083
export(find_catch)
@@ -104,6 +97,7 @@ export(find_project)
10497
export(find_value)
10598
export(fishset_compare)
10699
export(fishset_design)
100+
export(fishset_fit)
107101
export(fishset_tables)
108102
export(fishset_theme)
109103
export(fishset_viridis)
@@ -112,7 +106,6 @@ export(fleet_assign)
112106
export(fleet_table)
113107
export(format_grid)
114108
export(format_model_data)
115-
export(format_outsample_coefs)
116109
export(freq_table)
117110
export(function_summary)
118111
export(get_closure_scenario)
@@ -161,13 +154,9 @@ export(log_func_model)
161154
export(log_rerun)
162155
export(log_rerun_gui)
163156
export(log_reset)
164-
export(logit_c)
165157
export(logit_correction)
166-
export(logit_predict)
167-
export(logit_zonal)
168158
export(lonlat_to_centroid)
169159
export(main_tables)
170-
export(make_model_design)
171160
export(make_spat_area)
172161
export(map_kernel)
173162
export(map_plot)
@@ -196,9 +185,7 @@ export(meta_list)
196185
export(meta_log_call)
197186
export(meta_tables)
198187
export(metadata_gui)
199-
export(mixed_logit_predict)
200188
export(model_design_list)
201-
export(model_design_outsample)
202189
export(model_error_summary)
203190
export(model_fit)
204191
export(model_fit_summary)
@@ -239,7 +226,6 @@ export(policy_metrics)
239226
export(polyval)
240227
export(pred_prob_outputs)
241228
export(predict_map)
242-
export(predict_outsample)
243229
export(predict_probability)
244230
export(pretty_lab)
245231
export(pretty_tab)
@@ -351,7 +337,6 @@ importFrom(DBI,dbExistsTable)
351337
importFrom(DBI,dbGetQuery)
352338
importFrom(DBI,dbListFields)
353339
importFrom(DBI,dbListTables)
354-
importFrom(DBI,dbReadTable)
355340
importFrom(DBI,dbRemoveTable)
356341
importFrom(DBI,dbWriteTable)
357342
importFrom(DT,DTOutput)
@@ -365,6 +350,10 @@ importFrom(Formula,Formula)
365350
importFrom(Formula,model.part)
366351
importFrom(RCurl,getURL)
367352
importFrom(RSQLite,SQLite)
353+
importFrom(RTMB,MakeADFun)
354+
importFrom(RTMB,REPORT)
355+
importFrom(RTMB,getAll)
356+
importFrom(RTMB,sdreport)
368357
importFrom(Rcpp,sourceCpp)
369358
importFrom(data.table,":=")
370359
importFrom(data.table,.GRP)
@@ -564,6 +553,7 @@ importFrom(stats,as.formula)
564553
importFrom(stats,ave)
565554
importFrom(stats,coef)
566555
importFrom(stats,complete.cases)
556+
importFrom(stats,cov2cor)
567557
importFrom(stats,dbinom)
568558
importFrom(stats,density)
569559
importFrom(stats,dexp)
@@ -578,7 +568,8 @@ importFrom(stats,median)
578568
importFrom(stats,model.matrix)
579569
importFrom(stats,na.omit)
580570
importFrom(stats,na.pass)
581-
importFrom(stats,optim)
571+
importFrom(stats,nlminb)
572+
importFrom(stats,pchisq)
582573
importFrom(stats,pnorm)
583574
importFrom(stats,predict)
584575
importFrom(stats,quantile)

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: 2 additions & 2 deletions
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
@@ -251,7 +251,7 @@ create_dist_matrix <-
251251
if (is.null(o_var)) o_var <- occasion_var
252252

253253
return(list(dist_matrix = dist_matrix,
254-
alt_choice_units = units,
254+
dist_units = units,
255255
alt_choice_type = "distance",
256256
occasion = occasion,
257257
occasion_var = o_var,

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/create_logit_input.R

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)