Scallop Conditional Logit Model Example

Introduction

This is an example of a conditional logit model using the scallop data from the FishSET package.

Packages

library(FishSET)



Load Data

This analysis uses three of FishSET’s example datasets: the scallop dataframe which contains anonymized scallop data from the Northeast, scallop_ports which is a table of ports and their location, and tenMNSQR which is a spatial dataframe of Northeastern ten minute squares.

The scallop dataframe contains a random sample of 10,000 trips from vessels in the Limited Access Days-at-Sea fleet when they are declared into either an Access Area or Open area Days-at-Sea fishing trip.

Noise was added to fishing locations, landing quantities, and the value of catch. Permit, Operator, and trip identifiers were also anonymized.

data("scallop")
data('scallop_ports')
data("tenMNSQR")
scallop$LANDED_thousands<-scallop$LANDED_OBSCURED/1000
scallop$DOLLAR_2020_thousands<-scallop$DOLLAR_2020_OBSCURED/1000

vars_to_keep <- c('TRIPID', 'PERMIT.y', 'DATE_TRIP', 'DDLON', 'DDLAT', 'ZoneID', 
                  'LANDED_thousands', 'DOLLAR_2020_thousands', 'port_lon', 'port_lat',
                  'previous_port_lon', 'previous_port_lat')
scallop <- scallop[vars_to_keep]



Load each dataset into FishSET. Rescale the Landed weight to thousands of meat pounds and the Dollar value to thousands of Real dollars. Note: when running this chunk you may get a pop-up asking to identify the location for a new FishSET folder or an existing folder.

load_maindata(scallop, project = "scallopMod", over_write = TRUE)
## Table saved to database
## 
## ! Data saved to database as scallopModMainDataTable20250116 (raw) and scallopModMainDataTable (working). 
## Table is also in the working environment. !
load_port(dat = scallop_ports, port_name = "port_name", project = "scallopMod")
## Port table saved to database
load_spatial(spat = tenMNSQR, name = "TenMnSqr", project = "scallopMod")
## Writing layer `scallopModTenMnSqrSpatTable' to data source 
##   `/tmp/Rtmp0lMQPP/scallopMod/data/spat/scallopModTenMnSqrSpatTable.geojson' using driver `GeoJSON'
## Writing 5267 features with 9 fields and geometry type Polygon.
## Writing layer `scallopModTenMnSqrSpatTable20250116' to data source 
##   `/tmp/Rtmp0lMQPP/scallopMod/data/spat/scallopModTenMnSqrSpatTable20250116.geojson' using driver `GeoJSON'
## Writing 5267 features with 9 fields and geometry type Polygon.
## Spatial table saved to project folder as scallopModTenMnSqrSpatTable
scallopModTenMnSqrSpatTable <- table_view('scallopModTenMnSqrSpatTable', "scallopMod")
## Reading layer `scallopModTenMnSqrSpatTable' from data source 
##   `/tmp/Rtmp0lMQPP/scallopMod/data/spat/scallopModTenMnSqrSpatTable.geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 5267 features and 9 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: -77 ymin: 33 xmax: -64 ymax: 46.00139
## Geodetic CRS:  NAD83



QAQC

summary_stats() is a useful way to find NAs in the data.

summary_stats(scallopModMainDataTable, project = "scallopMod")
##              TRIPID        PERMIT.y            DDLON            DDLAT
## 1   Min.   :    6     Min.   :  1      Min.   :-76       Min.   :35  
## 2   Median :18836     Median :218      Median :-73       Median :40  
## 3   Mean   :19076     Mean   :236      Mean   :-72       Mean   :40  
## 4   Max.   :38503     Max.   :456      Max.   :-66       Max.   :43  
## 5           NA's: 0         NA's: 0          NA's: 0          NA's: 0
## 6 Unique Obs: 10000 Unique Obs: 130 Unique Obs: 2212 Unique Obs: 2039
## 7        No. 0's: 0      No. 0's: 0       No. 0's: 0       No. 0's: 0
##             ZoneID  LANDED_thousands DOLLAR_2020_thousands      port_lon
## 1 Min.   :     0    Min.   : 0.022         Min.   :  0.2   Min.   :-76  
## 2 Median :406712    Median :15.639         Median :146.7   Median :-71  
## 3 Mean   :400562    Mean   :14.822         Mean   :152.0   Mean   :-73  
## 4 Max.   :427066    Max.   :76.507         Max.   :721.7   Max.   :-71  
## 5          NA's: 0           NA's: 0               NA's: 0       NA's: 0
## 6  Unique Obs: 465 Unique Obs: 10000     Unique Obs: 10000 Unique Obs: 6
## 7       No. 0's: 1        No. 0's: 0            No. 0's: 0    No. 0's: 0
##        port_lat previous_port_lon previous_port_lat         DATE_TRIP
## 1  Min.   :37       Min.   :-77        Min.   :35   First: 2007-05-01
## 2  Median :42       Median :-71        Median :42                  NA
## 3  Mean   :40       Mean   :-73        Mean   :40                  NA
## 4  Max.   :42       Max.   :-70        Max.   :44                  NA
## 5       NA's: 0          NA's: 18          NA's: 18           NA's: 0
## 6 Unique Obs: 6    Unique Obs: 41    Unique Obs: 41  Unique Obs: 3544
## 7    No. 0's: 0       No. 0's: NA       No. 0's: NA      No. Empty: 0



Remove NAs by calling na_filter(). In this case, three variables which are important for modeling are being filtered: ZoneID, previous_port_lon, and previous_port_lat.

scallopModMainDataTable <- 
  na_filter(scallopModMainDataTable,
            project = "scallopMod", 
            x = c("ZoneID", "previous_port_lon", "previous_port_lat"),
            remove = TRUE)
## Warning: ZoneID do not contain NAs.
## The following columns contain NAs: previous_port_lon, previous_port_lat. Consider using na_filter to replace or remove NAs.
## The entire row will be removed from the dataframe.



Plot the number of observations by zone.

zone_summary(dat = scallopModMainDataTable, 
             spat = scallopModTenMnSqrSpatTable, 
             project = "scallopMod",
             zone.dat = "ZoneID",
             zone.spat = "TEN_ID",
             output = "tab_plot")
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## $table
## # A tibble: 465 × 2
##    ZoneID     n
##    <chr>  <int>
##  1 416965   265
##  2 387332   259
##  3 387331   226
##  4 387322   209
##  5 406932   194
##  6 387314   193
##  7 406926   192
##  8 387446   164
##  9 406915   151
## 10 387323   148
## # ℹ 455 more rows
## 
## $plot



Check for sparsity.

sparsetable(scallopModMainDataTable, 'scallopMod', 
            timevar = 'DATE_TRIP', 
            zonevar = 'ZoneID',
            var = 'LANDED_thousands')
##           387312 387446 397224 387331 397213 407262 397214 397346 426765 407254
## daily       0.98   0.95   1.00   0.94   0.97   0.98   0.99   0.98   1.00   0.98
## weekly      0.93   0.84   0.99   0.80   0.89   0.93   0.95   0.92   0.99   0.94
## biweekly    0.87   0.76   0.99   0.72   0.81   0.88   0.91   0.86   0.99   0.89
## monthly     0.76   0.65   0.97   0.62   0.69   0.79   0.84   0.76   0.97   0.82
## quarterly   0.54   0.46   0.94   0.46   0.44   0.56   0.60   0.50   0.92   0.60
## yearly      0.31   0.23   0.77   0.15   0.00   0.08   0.23   0.08   0.69   0.23
##           406611 406716 416714 407263 387445 407366 387425 397231 397336 387322
## daily       0.99   0.99   0.99   0.99   0.96   0.99   0.99   0.97   0.99   0.94
## weekly      0.96   0.96   0.96   0.94   0.85   0.95   0.94   0.90   0.96   0.82
## biweekly    0.95   0.93   0.93   0.90   0.76   0.91   0.91   0.84   0.92   0.71
## monthly     0.92   0.89   0.89   0.82   0.66   0.83   0.86   0.72   0.86   0.61
## quarterly   0.83   0.75   0.77   0.63   0.48   0.56   0.75   0.48   0.69   0.46
## yearly      0.54   0.46   0.38   0.31   0.23   0.15   0.54   0.15   0.46   0.31
##           387314 416966 397315 387321 397365 407264 387426 387455 397356 397345
## daily       0.95   0.96   0.97   0.98   0.98   0.99   0.97   0.96   0.98   0.99
## weekly      0.82   0.83   0.88   0.93   0.92   0.97   0.90   0.88   0.93   0.95
## biweekly    0.72   0.74   0.80   0.87   0.87   0.96   0.85   0.82   0.88   0.91
## monthly     0.60   0.58   0.67   0.78   0.80   0.91   0.76   0.74   0.79   0.82
## quarterly   0.46   0.31   0.38   0.54   0.56   0.79   0.58   0.52   0.62   0.58
## yearly      0.23   0.00   0.00   0.31   0.23   0.46   0.38   0.31   0.23   0.15
##           397355 406714 387436 426763 397314 406715 407245 377214 397316 407251
## daily       0.97   0.98   0.96   0.99   0.99   0.98   0.99   1.00   0.99   0.99
## weekly      0.91   0.94   0.85   0.97   0.95   0.95   0.97   1.00   0.95   0.96
## biweekly    0.86   0.89   0.79   0.94   0.92   0.92   0.95   1.00   0.92   0.93
## monthly     0.78   0.81   0.70   0.89   0.85   0.85   0.89   0.99   0.86   0.85
## quarterly   0.58   0.56   0.54   0.77   0.63   0.73   0.75   0.98   0.67   0.73
## yearly      0.23   0.15   0.31   0.46   0.38   0.31   0.38   0.92   0.31   0.31
##           397241 406916 397342 387324 397366 407326 387345 397262 357232 397364
## daily       0.98   0.96   1.00   0.98   0.99   1.00   1.00   1.00   1.00   0.97
## weekly      0.91   0.84   0.99   0.94   0.96   1.00   1.00   1.00   1.00   0.87
## biweekly    0.84   0.74   0.98   0.90   0.93   1.00   1.00   1.00   1.00   0.80
## monthly     0.73   0.58   0.95   0.81   0.86   0.99   0.99   0.99   0.99   0.67
## quarterly   0.50   0.27   0.88   0.65   0.75   0.98   0.98   0.98   0.98   0.44
## yearly      0.31   0.00   0.69   0.31   0.38   0.92   0.92   0.92   0.92   0.08
##           387435 397234 397232 387313 416965 417262 377366 407343 406811 406621
## daily       0.98   1.00   0.97   0.96   0.93   1.00   1.00   1.00   0.98   1.00
## weekly      0.92   1.00   0.91   0.83   0.76   1.00   1.00   0.99   0.89   1.00
## biweekly    0.88   0.99   0.84   0.76   0.64   0.99   1.00   0.99   0.83   0.99
## monthly     0.80   0.99   0.75   0.61   0.49   0.99   0.99   0.97   0.69   0.99
## quarterly   0.65   0.96   0.52   0.31   0.19   0.96   0.98   0.90   0.48   0.96
## yearly      0.38   0.85   0.15   0.00   0.00   0.85   0.92   0.62   0.00   0.85
##           387315 407246 387025 397325 407113 406814 406935 406926 397212 416954
## daily       0.98   1.00   1.00   0.98   0.99   1.00   0.98   0.96   0.99   0.99
## weekly      0.93   0.99   1.00   0.92   0.96   0.99   0.92   0.87   0.95   0.96
## biweekly    0.89   0.98   1.00   0.86   0.95   0.99   0.88   0.82   0.90   0.92
## monthly     0.82   0.95   0.99   0.77   0.90   0.97   0.78   0.72   0.82   0.84
## quarterly   0.62   0.88   0.98   0.48   0.79   0.94   0.63   0.63   0.62   0.62
## yearly      0.38   0.62   0.92   0.15   0.46   0.77   0.31   0.23   0.15   0.23
##           406945 406936 406925 416862 416852 416853 416964 406861 416854 416863
## daily       0.99   0.98   0.97   0.97   0.97   0.99   0.99   1.00   1.00   0.99
## weekly      0.95   0.93   0.90   0.92   0.92   0.97   0.97   1.00   0.99   0.98
## biweekly    0.93   0.88   0.86   0.88   0.87   0.95   0.95   0.99   0.99   0.96
## monthly     0.89   0.80   0.78   0.84   0.79   0.91   0.90   0.98   0.97   0.93
## quarterly   0.81   0.67   0.67   0.73   0.65   0.83   0.75   0.94   0.92   0.87
## yearly      0.62   0.31   0.15   0.46   0.38   0.69   0.38   0.77   0.69   0.77
##           406813 416864 407121 407336 416861 397363 406712 406915 416952 407362
## daily       1.00   1.00   0.99   1.00   0.97   0.98   0.99   0.95   1.00   1.00
## weekly      0.99   1.00   0.95   1.00   0.89   0.90   0.97   0.82   1.00   0.99
## biweekly    0.98   0.99   0.92   0.99   0.85   0.82   0.95   0.69   1.00   0.99
## monthly     0.97   0.99   0.84   0.99   0.78   0.68   0.91   0.52   0.99   0.97
## quarterly   0.90   0.98   0.67   0.96   0.62   0.42   0.79   0.17   0.98   0.90
## yearly      0.69   0.92   0.31   0.85   0.38   0.15   0.38   0.00   0.92   0.69
##           416724 407131 407261 416843 416955 387336 407244 416713 397362 377335
## daily       1.00   0.99   0.99   0.98   0.98   1.00   0.99   0.99   0.99   1.00
## weekly      1.00   0.96   0.95   0.94   0.92   0.99   0.96   0.97   0.95   1.00
## biweekly    1.00   0.93   0.91   0.90   0.87   0.99   0.92   0.96   0.91   0.99
## monthly     0.99   0.87   0.83   0.84   0.77   0.97   0.86   0.91   0.84   0.99
## quarterly   0.98   0.71   0.63   0.75   0.60   0.94   0.65   0.81   0.69   0.96
## yearly      0.92   0.31   0.23   0.46   0.23   0.77   0.31   0.46   0.46   0.85
##           406724 387311 426764 406721 406723 387353 416835 397223 397354 396814
## daily       0.99   0.99   0.98   1.00   0.98   1.00   1.00   0.99   0.98   1.00
## weekly      0.98   0.96   0.93   0.98   0.94   1.00   1.00   0.94   0.94   1.00
## biweekly    0.96   0.92   0.90   0.97   0.90   1.00   1.00   0.90   0.90   1.00
## monthly     0.93   0.84   0.84   0.94   0.85   0.99   0.99   0.83   0.84   0.99
## quarterly   0.85   0.63   0.63   0.83   0.69   0.98   0.98   0.63   0.62   0.98
## yearly      0.54   0.23   0.15   0.54   0.31   0.92   0.92   0.23   0.31   0.92
##           406826 406821 406623 416945 406722 406733 387334 416816 387416 397225
## daily       1.00   0.98   1.00   0.99   0.99   1.00   1.00   0.99   1.00   1.00
## weekly      0.98   0.94   1.00   0.96   0.96   0.98   0.98   0.98   0.99   1.00
## biweekly    0.96   0.89   1.00   0.94   0.92   0.97   0.96   0.96   0.98   1.00
## monthly     0.93   0.80   0.99   0.89   0.86   0.95   0.93   0.92   0.95   0.99
## quarterly   0.85   0.58   0.98   0.75   0.71   0.88   0.85   0.87   0.88   0.98
## yearly      0.54   0.15   0.92   0.38   0.23   0.69   0.46   0.54   0.62   0.92
##           397344 406831 397233 406815 416944 416933 397222 406713 407325 407241
## daily       0.99   0.99   1.00   1.00   0.98   0.99   0.99   0.99   1.00   0.99
## weekly      0.96   0.97   1.00   0.99   0.93   0.96   0.97   0.95   1.00   0.95
## biweekly    0.93   0.94   0.99   0.99   0.90   0.94   0.94   0.92   1.00   0.92
## monthly     0.86   0.88   0.99   0.98   0.83   0.88   0.89   0.85   0.99   0.86
## quarterly   0.73   0.67   0.96   0.94   0.67   0.73   0.77   0.69   0.98   0.69
## yearly      0.46   0.15   0.85   0.77   0.15   0.46   0.31   0.08   0.92   0.31
##           406832 387366 397352 397335 397251 387335 397211 416851 397361 387325
## daily       0.99   1.00   1.00   0.99   0.99   1.00   0.99   0.98   1.00   1.00
## weekly      0.98   1.00   0.98   0.94   0.97   0.99   0.96   0.95   0.98   0.98
## biweekly    0.96   1.00   0.97   0.90   0.96   0.99   0.93   0.92   0.96   0.97
## monthly     0.91   0.99   0.93   0.81   0.91   0.97   0.85   0.89   0.92   0.93
## quarterly   0.81   0.98   0.87   0.63   0.81   0.90   0.67   0.85   0.85   0.87
## yearly      0.46   0.92   0.69   0.38   0.54   0.69   0.23   0.69   0.54   0.62
##           397221 397343 406822 387333 407253 387323 387332 387341 407356 407236
## daily       0.99   0.99   0.99   0.96   0.99   0.96   0.93   0.98   0.99   1.00
## weekly      0.98   0.98   0.98   0.88   0.96   0.83   0.78   0.90   0.95   0.99
## biweekly    0.95   0.95   0.96   0.81   0.94   0.75   0.70   0.85   0.92   0.98
## monthly     0.91   0.89   0.93   0.74   0.89   0.63   0.57   0.76   0.84   0.95
## quarterly   0.77   0.77   0.83   0.56   0.73   0.42   0.40   0.58   0.63   0.87
## yearly      0.38   0.54   0.46   0.15   0.38   0.15   0.15   0.23   0.23   0.54
##           397353 407256 407265 416765 377452 397313 407365 407242 416721 397246
## daily       0.99   1.00   1.00   0.99   1.00   0.99   0.98   0.98   1.00   1.00
## weekly      0.96   0.99   1.00   0.98   0.99   0.98   0.93   0.92   0.99   1.00
## biweekly    0.94   0.98   0.99   0.97   0.97   0.96   0.88   0.87   0.99   1.00
## monthly     0.86   0.95   0.99   0.93   0.94   0.91   0.78   0.78   0.97   0.99
## quarterly   0.69   0.88   0.98   0.83   0.88   0.81   0.56   0.50   0.92   0.98
## yearly      0.31   0.54   0.85   0.46   0.69   0.54   0.31   0.08   0.85   0.92
##           387434 387342 377143 407243 407355 407234 407363 387145 407353 387465
## daily       1.00   0.98   1.00   0.99   0.99   1.00   0.99   1.00   1.00   0.96
## weekly      0.99   0.93   1.00   0.95   0.95   0.98   0.96   1.00   0.99   0.88
## biweekly    0.99   0.89   1.00   0.92   0.90   0.97   0.94   1.00   0.98   0.83
## monthly     0.97   0.82   0.99   0.84   0.82   0.94   0.91   0.99   0.95   0.77
## quarterly   0.90   0.67   0.98   0.62   0.63   0.85   0.83   0.98   0.87   0.62
## yearly      0.77   0.38   0.92   0.31   0.38   0.62   0.62   0.92   0.69   0.31
##           407354 397324 357445 417041 407361 416834 417061 416845 387456 397466
## daily       0.99   0.99   1.00   1.00   1.00   1.00   1.00   1.00   0.98   1.00
## weekly      0.97   0.98   1.00   1.00   1.00   0.99   0.99   0.99   0.92   1.00
## biweekly    0.94   0.96   1.00   1.00   0.99   0.98   0.99   0.98   0.87   0.99
## monthly     0.90   0.95   0.99   0.99   0.99   0.95   0.97   0.96   0.80   0.99
## quarterly   0.75   0.87   0.98   0.98   0.96   0.90   0.92   0.90   0.65   0.96
## yearly      0.46   0.69   0.92   0.92   0.85   0.69   0.77   0.77   0.38   0.85
##           397334 406812 416665 426762 417062 407252 396714 416943 397312 387464
## daily       0.99   0.99   1.00   1.00   1.00   0.99   1.00   1.00   1.00   0.99
## weekly      0.98   0.98   1.00   1.00   1.00   0.96   1.00   1.00   0.99   0.97
## biweekly    0.96   0.96   1.00   0.99   0.99   0.94   1.00   0.99   0.98   0.95
## monthly     0.91   0.93   0.99   0.99   0.99   0.86   0.99   0.98   0.95   0.90
## quarterly   0.77   0.87   0.98   0.96   0.94   0.65   0.98   0.94   0.90   0.79
## yearly      0.46   0.69   0.92   0.85   0.85   0.23   0.92   0.77   0.54   0.54
##           387424 407364 406834 406732 397311 406833 406914 407255 406711 397333
## daily       1.00   0.98   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## weekly      1.00   0.94   1.00   0.98   1.00   0.99   0.99   0.99   1.00   0.99
## biweekly    1.00   0.89   0.99   0.97   0.99   0.98   0.99   0.97   0.99   0.97
## monthly     0.99   0.83   0.98   0.93   0.99   0.95   0.97   0.95   0.98   0.95
## quarterly   0.98   0.69   0.94   0.85   0.96   0.90   0.92   0.87   0.96   0.87
## yearly      0.92   0.38   0.77   0.54   0.85   0.62   0.69   0.62   0.85   0.54
##           416764 387032 387226 407344 377435 387444 407231 377414 377424 377415
## daily       1.00   1.00   1.00   1.00   1.00   1.00   1.00   0.99   0.98   0.99
## weekly      1.00   0.99   1.00   1.00   1.00   1.00   1.00   0.97   0.94   0.97
## biweekly    1.00   0.99   0.99   0.99   0.99   0.99   1.00   0.93   0.90   0.94
## monthly     0.99   0.98   0.99   0.99   0.99   0.99   0.99   0.88   0.82   0.90
## quarterly   0.98   0.96   0.96   0.96   0.96   0.96   0.98   0.75   0.67   0.77
## yearly      0.92   0.85   0.85   0.85   0.85   0.85   0.92   0.54   0.31   0.54
##           347535 377413 377432 377443 377322 377231 387463 367536 377323 407345
## daily       1.00   1.00   0.99   0.99   1.00   1.00   1.00   1.00   1.00   0.99
## weekly      1.00   0.98   0.97   0.96   1.00   1.00   0.99   1.00   0.99   0.97
## biweekly    1.00   0.97   0.94   0.93   1.00   1.00   0.99   1.00   0.99   0.95
## monthly     0.99   0.95   0.89   0.88   0.99   0.99   0.97   0.99   0.97   0.89
## quarterly   0.98   0.88   0.79   0.73   0.98   0.98   0.94   0.98   0.92   0.79
## yearly      0.92   0.77   0.62   0.62   0.92   0.92   0.85   0.92   0.69   0.46
##           387231 397326 377433 407333 397351 397323 387351 377325 377021 416766
## daily       1.00   0.99   0.98   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## weekly      1.00   0.95   0.94   1.00   1.00   1.00   0.99   1.00   1.00   0.99
## biweekly    1.00   0.90   0.91   1.00   0.99   0.99   0.98   0.99   1.00   0.98
## monthly     0.99   0.82   0.86   0.99   0.98   0.98   0.96   0.99   0.99   0.97
## quarterly   0.98   0.60   0.77   0.98   0.96   0.94   0.94   0.96   0.98   0.90
## yearly      0.92   0.23   0.54   0.92   0.85   0.85   0.85   0.85   0.92   0.69
##           387354 416744 416756 416661 416662 407035 416651 416653 416652 416755
## daily       1.00   1.00   1.00   0.98   0.98   1.00   0.99   0.98   0.99   1.00
## weekly      1.00   1.00   0.99   0.94   0.94   1.00   0.97   0.94   0.97   1.00
## biweekly    0.99   0.99   0.99   0.91   0.92   1.00   0.96   0.93   0.94   0.99
## monthly     0.99   0.99   0.97   0.88   0.86   0.99   0.91   0.86   0.89   0.99
## quarterly   0.96   0.96   0.94   0.73   0.81   0.98   0.87   0.79   0.79   0.96
## yearly      0.85   0.85   0.77   0.38   0.54   0.92   0.54   0.54   0.54   0.85
##           416715 416643 416663 407335 416762 377453 377422 387452 416844 416826
## daily       1.00   0.99   0.99   1.00   1.00   1.00   1.00   1.00   0.99   1.00
## weekly      1.00   0.96   0.98   1.00   1.00   1.00   0.99   1.00   0.97   0.99
## biweekly    1.00   0.93   0.96   0.99   1.00   0.99   0.99   0.99   0.94   0.98
## monthly     0.99   0.88   0.93   0.99   0.99   0.98   0.97   0.98   0.88   0.97
## quarterly   0.98   0.81   0.85   0.96   0.98   0.96   0.92   0.96   0.73   0.90
## yearly      0.92   0.54   0.62   0.85   0.92   0.85   0.69   0.85   0.31   0.62
##           377321 387461 377444 387454 407346 377464 416722 407221 377416 407316
## daily       1.00   1.00   1.00   1.00   0.99   1.00   1.00   1.00   1.00   1.00
## weekly      1.00   1.00   1.00   1.00   0.97   1.00   1.00   1.00   1.00   1.00
## biweekly    1.00   1.00   0.99   0.99   0.94   0.99   0.99   0.99   0.99   0.99
## monthly     0.99   0.99   0.99   0.99   0.88   0.99   0.99   0.99   0.98   0.99
## quarterly   0.98   0.98   0.96   0.96   0.71   0.96   0.96   0.96   0.96   0.98
## yearly      0.92   0.92   0.85   0.85   0.46   0.85   0.85   0.85   0.85   0.92
##           377423 387414 387344 367322 387363 377434 377442 377425 387466 387432
## daily       0.99   1.00   1.00   1.00   1.00   1.00   0.99   1.00   0.99   1.00
## weekly      0.96   1.00   1.00   1.00   1.00   0.98   0.96   0.98   0.96   0.99
## biweekly    0.93   1.00   1.00   0.99   0.99   0.97   0.95   0.97   0.95   0.99
## monthly     0.91   0.99   0.99   0.99   0.98   0.95   0.92   0.95   0.90   0.97
## quarterly   0.83   0.98   0.98   0.96   0.94   0.90   0.88   0.88   0.81   0.94
## yearly      0.62   0.92   0.92   0.85   0.85   0.77   0.77   0.69   0.54   0.77
##           387233 416932 377312 397465 387352 417366 397463 347336 357516 387415
## daily       1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## weekly      1.00   0.98   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## biweekly    1.00   0.96   1.00   0.99   0.99   1.00   1.00   1.00   1.00   0.99
## monthly     0.99   0.92   0.99   0.99   0.99   0.99   0.99   0.99   0.99   0.99
## quarterly   0.98   0.77   0.98   0.96   0.96   0.98   0.98   0.98   0.98   0.96
## yearly      0.92   0.38   0.92   0.85   0.85   0.92   0.92   0.92   0.92   0.85
##           397261 416931 407032 406924 406816 407122 407021 397446 407226 407111
## daily       1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   0.99   1.00
## weekly      1.00   1.00   1.00   0.99   1.00   0.98   1.00   1.00   0.98   0.99
## biweekly    0.99   1.00   0.99   0.99   0.99   0.97   0.99   1.00   0.95   0.98
## monthly     0.99   0.99   0.99   0.97   0.98   0.95   0.99   0.99   0.92   0.96
## quarterly   0.96   0.98   0.98   0.92   0.94   0.88   0.98   0.98   0.79   0.92
## yearly      0.85   0.92   0.92   0.77   0.77   0.69   0.92   0.92   0.46   0.77
##           397331 407012 407216 407235 406965 407224 387252 417164 397322 377445
## daily       1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## weekly      1.00   1.00   1.00   0.99   0.98   1.00   1.00   0.99   1.00   1.00
## biweekly    1.00   1.00   0.99   0.98   0.97   1.00   1.00   0.98   0.99   1.00
## monthly     0.99   0.99   0.99   0.96   0.95   0.99   0.99   0.96   0.99   0.99
## quarterly   0.98   0.98   0.96   0.88   0.88   0.98   0.98   0.90   0.96   0.98
## yearly      0.92   0.92   0.85   0.62   0.62   0.92   0.92   0.69   0.85   0.92
##           397426 377465 357325 407352 377426 407225 407266 347415 397242 387326
## daily       1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   0.99   1.00
## weekly      1.00   1.00   1.00   0.99   1.00   0.98   1.00   1.00   0.96   1.00
## biweekly    0.99   1.00   1.00   0.99   1.00   0.97   0.99   1.00   0.92   0.99
## monthly     0.98   0.99   0.99   0.97   0.99   0.93   0.99   0.99   0.86   0.99
## quarterly   0.94   0.98   0.98   0.94   0.98   0.87   0.96   0.98   0.71   0.96
## yearly      0.77   0.92   0.92   0.85   0.92   0.69   0.85   0.92   0.46   0.85
##           416711 416833 416953 397464 416956 357313 386916 416641 416642 416746
## daily       1.00   1.00   1.00   1.00   0.99   1.00   1.00   1.00   0.99   1.00
## weekly      0.99   1.00   1.00   1.00   0.98   1.00   1.00   0.99   0.97   1.00
## biweekly    0.98   0.99   1.00   1.00   0.96   1.00   1.00   0.99   0.95   1.00
## monthly     0.97   0.99   0.99   0.99   0.91   0.99   0.99   0.97   0.92   0.99
## quarterly   0.94   0.96   0.96   0.98   0.81   0.98   0.98   0.92   0.83   0.98
## yearly      0.77   0.85   0.92   0.92   0.54   0.92   0.92   0.77   0.62   0.92
##           397321 377411 397263 407223 377364 387214 367444 377346 406766 417046
## daily       1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## weekly      1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## biweekly    1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## monthly     0.99   0.99   0.99   0.99   0.99   0.99   0.99   0.99   0.99   0.99
## quarterly   0.98   0.98   0.98   0.98   0.98   0.98   0.98   0.98   0.98   0.98
## yearly      0.92   0.92   0.92   0.92   0.92   0.92   0.92   0.92   0.92   0.92
##           416654 416963 416961 416742 406742 416825 396916 406862 406643 367216
## daily       0.99   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## weekly      0.98   1.00   1.00   1.00   1.00   0.99   1.00   1.00   1.00   1.00
## biweekly    0.96   0.99   0.99   1.00   0.99   0.99   1.00   0.99   1.00   1.00
## monthly     0.94   0.99   0.99   0.99   0.99   0.97   0.99   0.99   0.99   0.99
## quarterly   0.88   0.96   0.96   0.98   0.96   0.94   0.98   0.96   0.98   0.98
## yearly      0.69   0.85   0.85   0.92   0.85   0.77   0.92   0.85   0.92   0.92
##           357346 416866 406923 416664 417051 367614 427065 397456 416841 416934
## daily       1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   0.99
## weekly      1.00   1.00   1.00   1.00   1.00   1.00   0.99   1.00   1.00   0.97
## biweekly    1.00   1.00   1.00   1.00   1.00   0.99   0.98   1.00   1.00   0.95
## monthly     0.99   0.99   0.99   0.99   0.99   0.99   0.95   0.99   0.99   0.91
## quarterly   0.98   0.98   0.98   0.98   0.98   0.96   0.88   0.98   0.98   0.81
## yearly      0.92   0.92   0.92   0.92   0.92   0.85   0.54   0.92   0.92   0.69
##           416865 417031 416924 406765 416935 406764 406944 407112 416712 417042
## daily       1.00   1.00   1.00   1.00   1.00   1.00   0.98   0.99   1.00   1.00
## weekly      1.00   0.99   1.00   1.00   1.00   1.00   0.94   0.97   0.99   1.00
## biweekly    1.00   0.98   1.00   1.00   0.99   1.00   0.92   0.94   0.99   0.99
## monthly     0.99   0.97   0.99   0.99   0.99   0.99   0.89   0.90   0.97   0.99
## quarterly   0.98   0.92   0.98   0.98   0.96   0.98   0.85   0.79   0.92   0.96
## yearly      0.92   0.69   0.92   0.92   0.85   0.92   0.77   0.46   0.77   0.85
##           406835 406613 416644 416916 407466 407045 407011 407123 407233 407141
## daily       1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## weekly      0.99   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   0.99
## biweekly    0.99   0.99   1.00   1.00   1.00   1.00   1.00   1.00   1.00   0.99
## monthly     0.97   0.99   0.99   0.99   0.99   0.99   0.99   0.99   0.99   0.97
## quarterly   0.92   0.98   0.98   0.98   0.98   0.98   0.98   0.98   0.98   0.94
## yearly      0.69   0.92   0.92   0.92   0.92   0.92   0.92   0.92   0.92   0.77
##           417162 406966 407041 417145 407232 416831 406934 407133 416922 407132
## daily       1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## weekly      1.00   1.00   1.00   1.00   0.99   1.00   0.99   1.00   1.00   0.99
## biweekly    1.00   1.00   0.99   1.00   0.99   1.00   0.98   1.00   0.99   0.99
## monthly     0.99   0.99   0.99   0.99   0.97   0.99   0.96   0.99   0.99   0.97
## quarterly   0.98   0.98   0.96   0.98   0.90   0.98   0.92   0.98   0.96   0.92
## yearly      0.92   0.92   0.85   0.92   0.69   0.92   0.85   0.92   0.92   0.77
##           407163 416915 407151 387411 407013 407215 416824    0 347231 416942
## daily       1.00   1.00   1.00   1.00   1.00   1.00   1.00 1.00   1.00   1.00
## weekly      1.00   1.00   1.00   1.00   1.00   1.00   1.00 1.00   1.00   1.00
## biweekly    1.00   1.00   0.99   0.99   0.99   1.00   0.99 1.00   1.00   1.00
## monthly     0.99   0.99   0.99   0.98   0.99   0.99   0.99 0.99   0.99   0.99
## quarterly   0.98   0.98   0.98   0.94   0.96   0.98   0.96 0.98   0.98   0.98
## yearly      0.92   0.92   0.92   0.77   0.85   0.92   0.85 0.92   0.92   0.92
##           417146 416912 426752 407115 416761 406612 387655 406626 387241 407055
## daily       1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## weekly      1.00   1.00   1.00   0.99   1.00   1.00   1.00   1.00   1.00   1.00
## biweekly    1.00   0.99   1.00   0.97   0.99   0.99   1.00   1.00   0.99   0.99
## monthly     0.99   0.99   0.99   0.95   0.99   0.98   0.99   0.99   0.99   0.99
## quarterly   0.98   0.96   0.98   0.87   0.96   0.96   0.98   0.98   0.96   0.96
## yearly      0.92   0.92   0.92   0.77   0.85   0.85   0.92   0.92   0.85   0.92
##           407342 407015 427056 387422 387362 427034 387246 426915 427066 397332
## daily       1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## weekly      1.00   1.00   0.99   1.00   0.99   1.00   1.00   1.00   1.00   1.00
## biweekly    1.00   1.00   0.99   1.00   0.99   1.00   0.99   1.00   0.99   0.99
## monthly     0.99   0.99   0.97   0.99   0.97   0.99   0.99   0.99   0.99   0.99
## quarterly   0.98   0.98   0.96   0.98   0.96   0.98   0.96   0.98   0.96   0.96
## yearly      0.92   0.92   0.85   0.92   0.85   0.92   0.92   0.92   0.92   0.85
##           427045 377332 406731 387355 407142 387242 387361 387211 406734 407114
## daily       1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## weekly      0.99   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   0.99
## biweekly    0.99   1.00   1.00   0.99   0.99   0.99   1.00   1.00   0.99   0.99
## monthly     0.99   0.99   0.99   0.99   0.99   0.99   0.99   0.99   0.99   0.97
## quarterly   0.96   0.98   0.98   0.96   0.98   0.98   0.98   0.98   0.96   0.94
## yearly      0.85   0.92   0.92   0.85   0.92   0.92   0.92   0.92   0.85   0.85
##           377224 407134 417165 407116 417055 417161 417166 387462 427044 387225
## daily       1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## weekly      1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## biweekly    1.00   1.00   1.00   1.00   0.99   1.00   1.00   1.00   0.99   1.00
## monthly     0.99   0.99   0.99   0.99   0.99   0.99   0.99   0.99   0.99   0.99
## quarterly   0.98   0.98   0.98   0.98   0.96   0.98   0.98   0.98   0.98   0.98
## yearly      0.92   0.92   0.92   0.92   0.92   0.92   0.92   0.92   0.92   0.92
##           387365 387413 397265 406652 406932 387244 387212 416734 407135 357322
## daily       1.00   1.00   1.00   1.00   0.95   1.00   1.00   1.00   1.00   1.00
## weekly      1.00   1.00   1.00   1.00   0.90   1.00   1.00   1.00   1.00   1.00
## biweekly    0.99   1.00   1.00   1.00   0.87   1.00   1.00   1.00   1.00   1.00
## monthly     0.99   0.99   0.99   0.99   0.86   0.99   0.99   0.99   0.99   0.99
## quarterly   0.96   0.98   0.98   0.98   0.83   0.98   0.98   0.98   0.98   0.98
## yearly      0.92   0.92   0.92   0.92   0.77   0.92   0.92   0.92   0.92   0.92
##           387232 406852 406841 406933 406735 416842 406744 406943 426761 406942
## daily       1.00   1.00   1.00   0.98   1.00   0.99   1.00   0.98   1.00   0.98
## weekly      1.00   1.00   0.99   0.94   1.00   0.96   1.00   0.96   1.00   0.95
## biweekly    1.00   1.00   0.99   0.93   0.99   0.94   1.00   0.93   1.00   0.95
## monthly     0.99   0.99   0.99   0.92   0.99   0.92   0.99   0.90   0.99   0.92
## quarterly   0.98   0.98   0.96   0.87   0.96   0.87   0.98   0.88   0.98   0.88
## yearly      0.92   0.92   0.92   0.85   0.92   0.85   0.92   0.85   0.92   0.85
##           406931 406952 416856 406946 417154 406954 387122 406941 387236 426964
## daily       0.99   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00   1.00
## weekly      0.96   1.00   1.00   1.00   1.00   0.99   1.00   1.00   1.00   1.00
## biweekly    0.95   0.99   1.00   0.99   1.00   0.99   1.00   0.99   1.00   1.00
## monthly     0.94   0.98   0.99   0.99   0.99   0.97   0.99   0.99   0.99   0.99
## quarterly   0.92   0.96   0.98   0.96   0.98   0.96   0.98   0.96   0.98   0.98
## yearly      0.85   0.85   0.92   0.92   0.92   0.92   0.92   0.92   0.92   0.92
##           387433 406725 406955 417163 416962 All_zones
## daily       1.00   1.00   1.00   1.00   1.00         0
## weekly      1.00   1.00   1.00   1.00   1.00         0
## biweekly    1.00   1.00   1.00   1.00   1.00         0
## monthly     0.99   0.99   0.99   0.99   0.99         0
## quarterly   0.98   0.98   0.98   0.98   0.98         0
## yearly      0.92   0.92   0.92   0.92   0.92         0
sparsplot('scallopMod')
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'



Create Centroids

A centroid table is needed to create the distance matrix. It can be used as the choice occasion or the alternative choice. The simplest way to create a zonal centroid table is by passing it to create_centroid(), which saves the centroids to the FishSET database.

create_centroid(spat = scallopModTenMnSqrSpatTable,
                project = "scallopMod",
                spatID = "TEN_ID",
                type = "zonal centroid",
                output = "centroid table")
## Warning: st_centroid assumes attributes are constant over geometries
## Warning in st_centroid.sfc(st_geometry(x), of_largest_polygon =
## of_largest_polygon): st_centroid does not give correct centroids for
## longitude/latitude data
## Warning in find_centroid(spat = spatdat, project = project, spatID = spatID, :
## Duplicate centroids found for at least one zone. Using first centroid.
## Geographic centroid saved to fishSET database
## # A tibble: 4,537 × 3
##    ZoneID cent.lon cent.lat
##     <dbl>    <dbl>    <dbl>
##  1      0    -73.3     45.8
##  2 336411    -64.9     33.9
##  3 336412    -64.8     33.9
##  4 336413    -64.6     33.9
##  5 336414    -64.4     33.9
##  6 336415    -64.2     33.9
##  7 336416    -64.1     33.9
##  8 336421    -64.9     33.8
##  9 336422    -64.8     33.8
## 10 336423    -64.6     33.8
## # ℹ 4,527 more rows



Alternative Choice

For this example, the alternative choice list will use the longitude and latitude of the disembarking port (previous_port_lon and previous_port_lat) as the choice occasion and the zonal centroid of the fishing areas as the alternative. The minimum haul haul requirement is set to 90.

create_alternative_choice(dat = scallopModMainDataTable,
                          project = "scallopMod",
                          occasion = "lon-lat",
                          occasion_var = c("previous_port_lon", "previous_port_lat"),
                          alt_var = "zonal centroid",
                          zoneID = "ZoneID",
                          zone.cent.name = "scallopModZoneCentroid",
                          min.haul = 90
                          )
## Alternative choice list saved to FishSET database



The plot below visualizes zone frequency after accounting for the minimum haul requirement from the alternative choice list.

z_ind <- which(alt_choice_list('scallopMod')$dataZoneTrue == 1)

zOut <- 
  zone_summary(scallopModMainDataTable[z_ind, ], 
               spat = scallopModTenMnSqrSpatTable, 
               project = "scallopMod",
               zone.dat = "ZoneID",
               zone.spat = "TEN_ID",
               output = "tab_plot")
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
pretty_tab(zOut$tab)
ZoneID n
416965 265
387332 259
387331 226
387322 209
406932 194
387314 193
406926 192
387446 164
406915 151
387323 148
387436 146
387313 141
406925 140
406916 137
387445 134
416966 131
416862 121
387455 119
416861 119
387465 114
387333 109
397364 107
387426 96
397315 96
406933 96
397213 94
397232 91
zOut$plot



Expected Catch

This code chunk creates two different expected catch matrices: one using a window of seven days, lag of one and a window of 14 days, lag of two. They will be named user1 and user2 respectively.

# user1 expected catch matrix
create_expectations(dat = scallopModMainDataTable,
                    project = "scallopMod",
                    catch = "LANDED_thousands", 
                    temp.var = "DATE_TRIP",
                    temp.window = 7,
                    temp.lag = 1,
                    year.lag = 0,
                    temporal = 'daily',
                    empty.catch = NA,
                    empty.expectation = 1e-04,
                    default.exp = FALSE,
                    replace.output = TRUE)
## Expected catch/revenue matrix saved to FishSET database
# user2 expected catch matrix
create_expectations(dat = scallopModMainDataTable,
                    project = "scallopMod",
                    catch = "LANDED_thousands", 
                    temp.var = "DATE_TRIP",
                    temporal = "daily",
                    temp.window = 14,
                    temp.lag = 2,
                    empty.catch = NA,
                    empty.expectation = 1e-04,
                    default.exp = FALSE,
                    replace.output = FALSE)
## Expected catch/revenue matrix saved to FishSET database



The data must be checked for common data quality issues before it can be used in the modeling functions (i.e. make_model_design() and discretefish_subroutine()). check_model_data() saves a new version of the primary data with the suffix _final added to indicate that the table is in its “final” state and ready to be used for modeling.

check_model_data(scallopModMainDataTable, 
                 project = "scallopMod", 
                 uniqueID = "TRIPID",
                 latlon = c("DDLON","DDLAT"))



Model Design

The model design file below will run two conditional logit models, each using one of the expected catch matrices created earlier (this is specified by using 'individual' in the expectcatchmodels argument).

make_model_design(project = "scallopMod",
                  catchID = "LANDED_thousands",
                  likelihood = "logit_c",
                  initparams = c(0, 0),
                  vars1 = NULL,
                  vars2 = NULL,
                  mod.name = 'lz', 
                  expectcatchmodels = list('individual')
                  )
## Warning: CRS is not specfied, distance matrix will be created using WGS 84
## (4326).
## Model design file done



Run Models

Use discretefish_subroutine() to run all models in the model design file.

discretefish_subroutine(project = "scallopMod", explorestarts = FALSE)
## 3 initial parameter values should be specified
## initial  value 738821.932410 
## iter   2 value 229112.752008
## iter   3 value 223507.942423
## iter   4 value 223495.056492
## iter   5 value 26422.629995
## iter   6 value 23855.971079
## iter   7 value 13939.282354
## iter   8 value 11571.466783
## iter   9 value 11326.376779
## iter  10 value 11325.917923
## iter  11 value 11325.673180
## iter  12 value 11275.004418
## iter  13 value 11273.457365
## iter  14 value 11273.454606
## iter  14 value 11273.454606
## iter  14 value 11273.454606
## final  value 11273.454606 
## converged
##               [,1]          [,2]          [,3]
## [1,]  6.692039e-06 -4.620080e-06 -9.311765e-09
## [2,] -4.620080e-06  6.415126e-06 -1.021759e-08
## [3,] -9.311765e-09 -1.021759e-08  4.556547e-08
## [1] 6.692039e-06 6.415126e-06 4.556547e-08



Use model_params() to see the model output. user1 and user2 are the expected catch parameters and V1 the travel distance parameter. A reasonably specified model should find positive coefficients for user1 and user2 and negative coefficiencts for V1.

model_params("scallopMod", output = 'print')
  • lz:

      estimate std_error t_value
    exp1 0.045 0.003 17.23
    exp2 0.062 0.003 24.5
    V1 -0.006 0 -26.62



Compare model fit.

model_fit_summary("scallopMod")
Model_name AIC AICc BIC PseudoR2
lz -22541 -22541 -22522 0.985