Scallop Conditional Logit Model Example
Bryce McManus
2024-08-07
Source:vignettes/scallop-mod-example.Rmd
scallop-mod-example.Rmd
Introduction
This is an example of a conditional logit model using the
scallop
data from the FishSET
package.
Packages
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, will retire in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
## The sp package is now running under evolution status 2
## (status 2 uses the sf package in place of rgdal)
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 scallopModMainDataTable20240807 (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
## `C:\Users\pcarvalho\AppData\Local\Temp\Rtmp8MhMJa/scallopMod/data/spat/scallopModTenMnSqrSpatTable.geojson' using driver `GeoJSON'
## Writing 5267 features with 9 fields and geometry type Polygon.
## Writing layer `scallopModTenMnSqrSpatTable20240807' to data source
## `C:\Users\pcarvalho\AppData\Local\Temp\Rtmp8MhMJa/scallopMod/data/spat/scallopModTenMnSqrSpatTable20240807.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
## `C:\Users\pcarvalho\AppData\Local\Temp\Rtmp8MhMJa\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 NA
s
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. :357223 Min. : 0.022 Min. : 0.2 Min. :-76
## 2 Median :406712 Median :15.639 Median :146.7 Median :-71
## 3 Mean :400612 Mean :14.822 Mean :152.0 Mean :-73
## 4 Max. :427066 Max. :76.507 Max. :721.7 Max. :-71
## 5 NA's: 5 NA's: 0 NA's: 0 NA's: 0
## 6 Unique Obs: 469 Unique Obs: 10000 Unique Obs: 10000 Unique Obs: 6
## 7 No. 0's: NA 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: 3539
## 7 No. 0's: 0 No. 0's: NA No. 0's: NA No. Empty: 0
Remove NA
s 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)
## The following columns contain NAs: ZoneID, 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: 468 × 2
## ZoneID n
## <chr> <int>
## 1 416956 242
## 2 387323 229
## 3 406962 225
## 4 387313 223
## 5 387332 198
## 6 387322 193
## 7 387341 188
## 8 406923 177
## 9 406961 172
## 10 387463 160
## # ℹ 458 more rows
##
## $plot
Check for sparsity.
sparsetable(scallopModMainDataTable, 'scallopMod',
timevar = 'DATE_TRIP',
zonevar = 'ZoneID',
var = 'LANDED_thousands')
## 387321 387464 397242 387313 397231 407226 397241 397364 426756 407245
## daily 0.98 0.95 1.00 0.94 0.97 0.98 0.99 0.98 1.00 0.98
## weekly 0.94 0.84 0.98 0.80 0.89 0.93 0.96 0.94 0.99 0.92
## biweekly 0.88 0.75 0.97 0.73 0.83 0.88 0.92 0.89 0.99 0.86
## monthly 0.77 0.64 0.95 0.62 0.69 0.79 0.85 0.82 0.97 0.78
## quarterly 0.60 0.46 0.87 0.46 0.44 0.56 0.62 0.63 0.92 0.54
## yearly 0.31 0.23 0.62 0.15 0.00 0.08 0.23 0.23 0.69 0.15
## 406611 406761 416741 407236 387454 407366 387452 397213 397363 387322
## daily 0.99 0.98 0.99 0.99 0.97 0.99 0.99 0.97 0.99 0.94
## weekly 0.97 0.95 0.95 0.95 0.87 0.94 0.94 0.89 0.96 0.83
## biweekly 0.95 0.92 0.93 0.92 0.81 0.90 0.91 0.83 0.91 0.72
## monthly 0.92 0.86 0.89 0.87 0.70 0.82 0.86 0.71 0.84 0.62
## quarterly 0.83 0.69 0.77 0.73 0.52 0.56 0.75 0.48 0.67 0.46
## yearly 0.54 0.38 0.38 0.46 0.31 0.15 0.54 0.15 0.38 0.31
## 387341 416966 397351 387312 397356 407246 387462 387455 397365 397354
## daily 0.95 0.96 0.98 0.98 0.98 0.99 0.97 0.96 0.97 0.99
## weekly 0.83 0.83 0.90 0.92 0.92 0.96 0.91 0.87 0.91 0.96
## biweekly 0.73 0.74 0.84 0.86 0.88 0.93 0.86 0.80 0.85 0.93
## monthly 0.62 0.58 0.72 0.77 0.80 0.86 0.78 0.72 0.73 0.85
## quarterly 0.50 0.33 0.44 0.56 0.56 0.71 0.62 0.54 0.52 0.62
## yearly 0.23 0.00 0.00 0.31 0.23 0.31 0.38 0.31 0.15 0.15
## 406741 387463 426736 397341 406751 407254 397366 377241 397361 407215
## daily 0.98 0.95 0.99 0.99 0.98 0.99 0.98 1.00 0.99 0.99
## weekly 0.94 0.85 0.97 0.95 0.95 0.97 0.95 1.00 0.95 0.94
## biweekly 0.89 0.77 0.95 0.92 0.92 0.95 0.92 1.00 0.92 0.90
## monthly 0.81 0.67 0.90 0.85 0.86 0.89 0.85 0.99 0.84 0.80
## quarterly 0.56 0.52 0.79 0.63 0.75 0.75 0.69 0.98 0.65 0.63
## yearly 0.15 0.31 0.54 0.38 0.31 0.38 0.38 0.92 0.15 0.15
## 397355 397214 406961 397325 387342 407362 387354 397226 387314 357223
## daily 0.98 0.98 0.95 0.99 0.97 1.00 1.00 1.00 0.97 1.00
## weekly 0.92 0.92 0.82 0.98 0.91 1.00 1.00 1.00 0.90 1.00
## biweekly 0.87 0.84 0.71 0.96 0.86 1.00 1.00 1.00 0.84 1.00
## monthly 0.81 0.73 0.55 0.92 0.75 0.99 0.99 0.99 0.75 0.99
## quarterly 0.62 0.48 0.21 0.83 0.58 0.98 0.98 0.98 0.56 0.98
## yearly 0.23 0.31 0.00 0.62 0.31 0.92 0.92 0.92 0.23 0.92
## 397346 387453 397243 397223 387331 416956 417226 377366 407334 406811
## daily 0.96 0.98 1.00 0.97 0.97 0.93 1.00 1.00 1.00 0.97
## weekly 0.86 0.94 1.00 0.91 0.87 0.77 1.00 1.00 0.99 0.89
## biweekly 0.79 0.90 0.99 0.84 0.79 0.67 0.99 1.00 0.98 0.82
## monthly 0.65 0.82 0.99 0.75 0.63 0.53 0.99 0.99 0.96 0.68
## quarterly 0.42 0.67 0.96 0.52 0.38 0.23 0.96 0.98 0.88 0.48
## yearly 0.08 0.46 0.85 0.15 0.08 0.08 0.85 0.92 0.62 0.00
## 406612 387351 407264 387052 397352 407131 406841 406953 406962 416945
## daily 1.00 0.99 1.00 1.00 0.98 0.99 1.00 0.98 0.95 0.99
## weekly 1.00 0.94 0.99 1.00 0.92 0.97 0.99 0.94 0.87 0.95
## biweekly 0.99 0.90 0.98 1.00 0.85 0.95 0.99 0.90 0.80 0.91
## monthly 0.99 0.84 0.95 0.99 0.76 0.90 0.97 0.82 0.70 0.82
## quarterly 0.96 0.65 0.88 0.98 0.42 0.79 0.94 0.69 0.62 0.58
## yearly 0.85 0.38 0.62 0.92 0.15 0.46 0.77 0.38 0.23 0.23
## 406964 406963 416825 416826 416835 416946 396811 416845 416836 406831
## daily 1.00 0.98 0.97 0.97 0.98 0.99 1.00 1.00 0.99 1.00
## weekly 0.99 0.92 0.92 0.92 0.95 0.97 1.00 0.99 0.97 0.99
## biweekly 0.99 0.87 0.87 0.88 0.94 0.95 1.00 0.98 0.96 0.98
## monthly 0.98 0.78 0.80 0.84 0.91 0.90 0.99 0.95 0.92 0.97
## quarterly 0.94 0.67 0.67 0.73 0.83 0.75 0.98 0.88 0.87 0.92
## yearly 0.85 0.31 0.38 0.46 0.69 0.38 0.92 0.54 0.77 0.77
## 416846 407112 406952 407363 416816 397336 406721 406951 416935 407326
## daily 1.00 0.99 0.98 1.00 0.96 0.97 0.99 0.96 1.00 1.00
## weekly 1.00 0.95 0.92 1.00 0.90 0.90 0.98 0.85 1.00 1.00
## biweekly 0.99 0.92 0.88 0.99 0.85 0.83 0.96 0.74 0.99 0.99
## monthly 0.99 0.84 0.82 0.98 0.78 0.69 0.93 0.57 0.99 0.98
## quarterly 0.98 0.67 0.71 0.94 0.62 0.46 0.83 0.29 0.94 0.94
## yearly 0.92 0.31 0.23 0.77 0.31 0.15 0.54 0.00 0.85 0.85
## 416742 407113 407216 416955 387363 407244 416731 397326 416834 377353
## daily 1.00 0.99 0.99 0.98 1.00 0.99 0.99 0.99 0.98 1.00
## weekly 1.00 0.96 0.95 0.91 1.00 0.96 0.97 0.95 0.94 1.00
## biweekly 0.99 0.93 0.92 0.85 1.00 0.93 0.96 0.92 0.90 0.99
## monthly 0.99 0.88 0.84 0.75 0.99 0.88 0.93 0.84 0.84 0.99
## quarterly 0.96 0.71 0.65 0.56 0.98 0.69 0.85 0.69 0.75 0.96
## yearly 0.85 0.31 0.23 0.15 0.92 0.31 0.54 0.46 0.46 0.85
## 406742 387311 426746 406712 406732 387335 416853 397232 397345 396841
## daily 0.99 0.99 0.98 0.99 0.98 1.00 1.00 0.98 0.98 1.00
## weekly 0.97 0.96 0.93 0.98 0.93 1.00 1.00 0.93 0.94 1.00
## biweekly 0.96 0.92 0.89 0.96 0.89 1.00 0.99 0.88 0.89 1.00
## monthly 0.91 0.84 0.83 0.92 0.82 0.99 0.99 0.80 0.82 0.99
## quarterly 0.83 0.63 0.62 0.81 0.62 0.98 0.96 0.60 0.60 0.98
## yearly 0.46 0.23 0.08 0.46 0.23 0.92 0.85 0.15 0.31 0.92
## 406862 406812 406632 416954 406722 397334 406733 387343 416711 387352
## daily 0.99 0.98 1.00 0.99 0.99 1.00 0.99 0.99 1.00 0.99
## weekly 0.98 0.93 1.00 0.97 0.97 0.98 0.97 0.98 0.98 0.98
## biweekly 0.96 0.88 1.00 0.95 0.94 0.96 0.96 0.96 0.97 0.96
## monthly 0.93 0.78 0.99 0.90 0.89 0.93 0.92 0.92 0.95 0.92
## quarterly 0.83 0.56 0.98 0.79 0.77 0.85 0.85 0.85 0.88 0.85
## yearly 0.54 0.15 0.92 0.46 0.31 0.69 0.54 0.46 0.54 0.54
## 387461 397252 397344 406813 397211 397233 406861 416861 416944 416933
## daily 1.00 1.00 0.99 0.99 0.99 1.00 1.00 1.00 0.98 0.99
## weekly 0.99 1.00 0.96 0.97 0.96 1.00 1.00 0.99 0.94 0.97
## biweekly 0.98 1.00 0.93 0.95 0.92 0.99 0.99 0.98 0.91 0.94
## monthly 0.96 0.99 0.86 0.88 0.84 0.99 0.99 0.96 0.85 0.89
## quarterly 0.88 0.98 0.73 0.69 0.65 0.96 0.96 0.92 0.67 0.73
## yearly 0.62 0.92 0.38 0.23 0.23 0.85 0.85 0.77 0.15 0.46
## 397222 406851 406731 407352 397221 407214 406823 387366 397353 397215
## daily 0.99 1.00 0.99 1.00 0.99 0.99 0.99 1.00 0.99 0.99
## weekly 0.97 1.00 0.96 1.00 0.96 0.97 0.98 1.00 0.95 0.97
## biweekly 0.94 0.99 0.93 1.00 0.93 0.95 0.96 1.00 0.91 0.94
## monthly 0.88 0.99 0.88 0.99 0.86 0.91 0.91 0.99 0.82 0.89
## quarterly 0.77 0.96 0.75 0.98 0.69 0.77 0.81 0.98 0.63 0.75
## yearly 0.31 0.85 0.15 0.92 0.31 0.46 0.46 0.92 0.38 0.46
## 387353 416815 397316 397212 397216 406822 387333 407235 387332 387323
## daily 1.00 0.99 1.00 0.99 1.00 0.99 0.96 0.99 0.94 0.93
## weekly 0.99 0.95 0.98 0.97 1.00 0.97 0.85 0.96 0.80 0.80
## biweekly 0.99 0.92 0.96 0.94 0.99 0.95 0.79 0.93 0.72 0.72
## monthly 0.97 0.89 0.92 0.88 0.99 0.92 0.71 0.87 0.59 0.59
## quarterly 0.90 0.85 0.85 0.71 0.96 0.81 0.52 0.71 0.38 0.40
## yearly 0.69 0.69 0.54 0.31 0.85 0.38 0.15 0.38 0.08 0.15
## 407365 407263 397335 407265 407256 416756 377425 397331 407224 416712
## daily 0.98 1.00 0.99 1.00 1.00 0.99 1.00 0.99 0.99 1.00
## weekly 0.93 0.99 0.96 0.98 1.00 0.98 0.99 0.98 0.95 0.99
## biweekly 0.88 0.98 0.92 0.97 0.99 0.97 0.97 0.96 0.90 0.99
## monthly 0.78 0.95 0.84 0.93 0.99 0.94 0.94 0.91 0.80 0.97
## quarterly 0.60 0.87 0.71 0.87 0.98 0.83 0.88 0.81 0.58 0.90
## yearly 0.23 0.46 0.38 0.46 0.85 0.46 0.69 0.54 0.08 0.77
## 397264 387443 387324 377134 407234 407356 407355 407336 387154 407335
## daily 1.00 1.00 0.99 1.00 0.99 0.98 0.99 0.99 1.00 1.00
## weekly 1.00 0.99 0.94 1.00 0.96 0.94 0.95 0.97 1.00 0.99
## biweekly 1.00 0.99 0.90 1.00 0.92 0.89 0.90 0.94 1.00 0.98
## monthly 0.99 0.97 0.82 0.99 0.86 0.81 0.83 0.91 0.99 0.95
## quarterly 0.98 0.90 0.69 0.98 0.63 0.63 0.65 0.81 0.98 0.87
## yearly 0.92 0.77 0.38 0.92 0.23 0.38 0.38 0.54 0.92 0.69
## 387466 407345 397342 417014 407316 387465 416843 417016 416854 397466
## daily 0.99 0.99 0.99 1.00 1.00 0.97 1.00 1.00 1.00 1.00
## weekly 0.96 0.97 0.98 1.00 1.00 0.91 0.99 0.99 0.99 0.99
## biweekly 0.93 0.94 0.96 1.00 0.99 0.85 0.98 0.99 0.99 0.99
## monthly 0.87 0.90 0.94 0.99 0.99 0.78 0.95 0.97 0.97 0.98
## quarterly 0.77 0.75 0.85 0.98 0.96 0.65 0.88 0.92 0.92 0.94
## yearly 0.46 0.46 0.62 0.92 0.85 0.38 0.62 0.77 0.85 0.85
## 397343 416656 426726 417026 407225 396741 416934 397321 387446 387442
## daily 0.99 1.00 1.00 1.00 0.99 1.00 1.00 1.00 0.99 1.00
## weekly 0.98 1.00 1.00 1.00 0.95 1.00 1.00 0.99 0.97 1.00
## biweekly 0.96 1.00 0.99 0.99 0.91 1.00 0.99 0.98 0.95 0.99
## monthly 0.92 0.99 0.99 0.99 0.82 0.99 0.98 0.96 0.90 0.99
## quarterly 0.79 0.98 0.96 0.94 0.60 0.98 0.94 0.92 0.79 0.96
## yearly 0.54 0.92 0.85 0.85 0.23 0.92 0.77 0.62 0.54 0.85
## 407346 406843 406723 397312 406833 406941 407255 397333 416746 387023
## daily 0.98 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00
## weekly 0.93 1.00 0.99 1.00 0.99 0.99 0.99 0.99 1.00 0.99
## biweekly 0.89 0.99 0.98 0.99 0.98 0.99 0.98 0.97 1.00 0.99
## monthly 0.82 0.98 0.96 0.98 0.95 0.97 0.95 0.95 0.99 0.98
## quarterly 0.67 0.94 0.88 0.94 0.90 0.92 0.90 0.87 0.98 0.94
## yearly 0.38 0.77 0.62 0.77 0.62 0.69 0.69 0.54 0.92 0.85
## 387262 407344 377453 387456 387444 407213 377441 377442 377451 377431
## daily 1.00 1.00 1.00 0.97 1.00 1.00 0.99 0.98 0.99 1.00
## weekly 1.00 1.00 1.00 0.89 1.00 1.00 0.96 0.93 0.97 0.99
## biweekly 0.99 1.00 0.99 0.84 0.99 1.00 0.94 0.89 0.95 0.98
## monthly 0.99 0.99 0.99 0.78 0.99 0.99 0.89 0.82 0.90 0.96
## quarterly 0.96 0.98 0.96 0.62 0.96 0.98 0.73 0.65 0.77 0.92
## yearly 0.85 0.92 0.85 0.38 0.85 0.92 0.54 0.31 0.54 0.77
## 397362 377423 377434 377322 377213 387436 367413 377332 407354 387213
## daily 0.98 0.99 0.99 1.00 1.00 1.00 1.00 1.00 1.00 1.00
## weekly 0.94 0.97 0.96 1.00 1.00 0.99 1.00 0.99 0.99 0.99
## biweekly 0.89 0.95 0.93 1.00 1.00 0.99 1.00 0.99 0.97 0.99
## monthly 0.80 0.89 0.88 0.99 0.99 0.97 0.99 0.97 0.94 0.97
## quarterly 0.56 0.79 0.73 0.98 0.98 0.94 0.98 0.92 0.87 0.94
## yearly 0.15 0.62 0.62 0.92 0.92 0.85 0.92 0.69 0.62 0.77
## 377433 407333 377432 397315 397332 387315 377362 377012 416766 387345
## daily 0.98 1.00 0.99 1.00 1.00 1.00 1.00 1.00 1.00 1.00
## weekly 0.94 1.00 0.96 0.99 1.00 0.99 1.00 1.00 0.99 1.00
## biweekly 0.91 1.00 0.94 0.99 0.99 0.98 1.00 1.00 0.98 0.99
## monthly 0.86 0.99 0.91 0.97 0.99 0.95 0.99 0.99 0.96 0.99
## quarterly 0.77 0.98 0.83 0.94 0.96 0.92 0.98 0.98 0.88 0.96
## yearly 0.54 0.92 0.69 0.77 0.85 0.77 0.92 0.92 0.62 0.85
## 416744 416765 416616 416626 407053 416635 416615 416625 416755 416751
## daily 1.00 1.00 0.98 0.98 1.00 0.98 0.99 0.99 1.00 1.00
## weekly 1.00 0.99 0.94 0.94 1.00 0.93 0.97 0.98 1.00 1.00
## biweekly 1.00 0.98 0.91 0.92 1.00 0.91 0.96 0.96 0.99 1.00
## monthly 0.99 0.97 0.88 0.88 0.99 0.84 0.92 0.91 0.99 0.99
## quarterly 0.98 0.92 0.75 0.81 0.98 0.79 0.87 0.83 0.96 0.98
## yearly 0.92 0.69 0.38 0.54 0.92 0.54 0.62 0.54 0.85 0.92
## 406842 416636 416726 406954 406711 416862 377435 377422 387425 416844
## daily 1.00 0.99 1.00 0.99 1.00 1.00 1.00 1.00 1.00 0.99
## weekly 1.00 0.97 1.00 0.95 1.00 0.98 0.99 0.99 1.00 0.97
## biweekly 0.99 0.96 1.00 0.93 0.99 0.97 0.99 0.99 0.99 0.95
## monthly 0.99 0.92 0.99 0.90 0.98 0.95 0.97 0.97 0.98 0.89
## quarterly 0.98 0.85 0.98 0.83 0.94 0.88 0.94 0.92 0.96 0.75
## yearly 0.92 0.62 0.92 0.69 0.77 0.62 0.77 0.69 0.85 0.38
## 377312 387416 377444 387445 377446 416722 407212 377461 407361 387441
## 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 1.00 1.00 1.00 0.99 1.00 1.00
## biweekly 1.00 1.00 0.99 0.99 0.99 0.99 0.99 0.99 0.99 1.00
## monthly 0.99 0.99 0.97 0.99 0.99 0.99 0.99 0.98 0.99 0.99
## quarterly 0.98 0.98 0.92 0.96 0.96 0.96 0.96 0.96 0.98 0.98
## yearly 0.92 0.92 0.69 0.85 0.85 0.85 0.85 0.85 0.92 0.92
## 387344 367322 387336 377443 377424 377452 407364 387423 387233 416923
## daily 1.00 1.00 1.00 1.00 0.99 0.99 0.99 1.00 1.00 1.00
## weekly 1.00 1.00 1.00 0.98 0.97 0.98 0.97 0.99 1.00 0.98
## biweekly 0.99 0.99 0.99 0.98 0.96 0.97 0.95 0.99 1.00 0.96
## monthly 0.99 0.99 0.99 0.95 0.93 0.95 0.89 0.97 0.99 0.92
## quarterly 0.96 0.96 0.96 0.90 0.90 0.88 0.75 0.94 0.98 0.77
## yearly 0.85 0.85 0.85 0.77 0.77 0.69 0.54 0.77 0.92 0.38
## 377321 397456 387325 417366 397436 387334 357561 377352 387211 416913
## 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 1.00 1.00 1.00 1.00 1.00 1.00
## biweekly 1.00 1.00 0.99 1.00 1.00 0.99 1.00 1.00 1.00 1.00
## monthly 0.99 0.99 0.98 0.99 0.99 0.98 0.99 0.99 0.99 0.99
## quarterly 0.98 0.98 0.94 0.98 0.98 0.96 0.98 0.98 0.98 0.98
## yearly 0.92 0.92 0.85 0.92 0.92 0.85 0.92 0.92 0.92 0.92
## 407023 406942 387346 407122 407012 397464 407262 407111 397313 397311
## daily 1.00 1.00 1.00 0.99 1.00 1.00 0.99 1.00 1.00 1.00
## weekly 1.00 0.99 1.00 0.98 1.00 1.00 0.98 0.99 1.00 1.00
## biweekly 0.99 0.99 1.00 0.96 0.99 1.00 0.95 0.98 1.00 1.00
## monthly 0.99 0.97 0.99 0.93 0.98 0.99 0.92 0.96 0.99 0.99
## quarterly 0.98 0.92 0.98 0.83 0.96 0.98 0.79 0.92 0.98 0.98
## yearly 0.92 0.77 0.92 0.54 0.85 0.92 0.46 0.77 0.92 0.92
## 407021 407261 407253 406956 407242 387225 417146 397322 377454 377456
## 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 0.99 1.00 1.00 0.99 1.00 1.00 1.00
## biweekly 1.00 0.99 0.99 0.98 1.00 0.99 0.99 0.99 1.00 1.00
## monthly 0.99 0.99 0.97 0.96 0.99 0.99 0.97 0.98 0.99 0.99
## quarterly 0.98 0.96 0.92 0.90 0.98 0.96 0.92 0.94 0.98 0.98
## yearly 0.92 0.85 0.69 0.69 0.92 0.85 0.77 0.77 0.92 0.92
## 357352 407325 377462 407252 407266 397462 397224 387362 416833 406821
## daily 1.00 1.00 1.00 1.00 1.00 1.00 0.99 1.00 1.00 1.00
## weekly 1.00 1.00 1.00 0.98 1.00 1.00 0.96 1.00 1.00 0.98
## biweekly 1.00 0.99 1.00 0.97 0.99 0.99 0.93 1.00 1.00 0.98
## monthly 0.99 0.98 0.99 0.93 0.99 0.99 0.86 0.99 0.99 0.96
## quarterly 0.98 0.94 0.98 0.87 0.96 0.96 0.71 0.98 0.98 0.88
## yearly 0.92 0.85 0.92 0.69 0.85 0.85 0.46 0.92 0.92 0.77
## 397446 416965 357331 386961 416634 406816 416614 416624 416764 377411
## daily 1.00 0.99 1.00 1.00 0.99 1.00 1.00 0.99 1.00 1.00
## weekly 1.00 0.97 1.00 1.00 0.96 1.00 0.99 0.97 1.00 1.00
## biweekly 1.00 0.94 1.00 1.00 0.94 0.99 0.99 0.96 1.00 1.00
## monthly 0.99 0.89 0.99 0.99 0.89 0.99 0.97 0.93 0.99 0.99
## quarterly 0.98 0.73 0.98 0.98 0.81 0.96 0.92 0.83 0.98 0.98
## yearly 0.92 0.38 0.92 0.92 0.62 0.85 0.85 0.62 0.92 0.92
## 397236 407243 407232 377346 387241 367444 377364 406766 417064 416645
## daily 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 0.99
## weekly 1.00 0.98 1.00 1.00 1.00 1.00 1.00 1.00 1.00 0.98
## biweekly 1.00 0.97 1.00 1.00 1.00 1.00 1.00 1.00 1.00 0.96
## monthly 0.99 0.94 0.99 0.99 0.99 0.99 0.99 0.99 0.99 0.94
## quarterly 0.98 0.87 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.88
## yearly 0.92 0.69 0.92 0.92 0.92 0.92 0.92 0.92 0.92 0.69
## 416936 416916 416724 406725 416852 396961 406826 406635 367261 357364
## 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 1.00 1.00 1.00 1.00
## biweekly 0.99 1.00 1.00 1.00 0.99 1.00 0.99 0.99 1.00 1.00
## monthly 0.98 0.99 0.99 0.99 0.98 0.99 0.99 0.99 0.99 0.99
## quarterly 0.94 0.98 0.98 0.98 0.96 0.98 0.96 0.96 0.98 0.98
## yearly 0.77 0.92 0.92 0.92 0.85 0.92 0.85 0.85 0.92 0.92
## 416866 406932 416646 417015 367641 427056 416814 416943 416856 417013
## daily 1.00 1.00 1.00 1.00 1.00 1.00 1.00 0.99 1.00 1.00
## weekly 1.00 1.00 1.00 1.00 1.00 0.99 1.00 0.97 1.00 0.99
## biweekly 1.00 1.00 1.00 1.00 0.99 0.98 1.00 0.95 1.00 0.98
## monthly 0.99 0.99 0.99 0.99 0.99 0.97 0.99 0.91 0.99 0.97
## quarterly 0.98 0.98 0.98 0.98 0.96 0.90 0.98 0.79 0.98 0.92
## yearly 0.92 0.92 0.92 0.92 0.85 0.62 0.92 0.69 0.92 0.69
## 416942 406756 416963 406746 407353 416644 406944 407121 416721 417024
## daily 1.00 1.00 1.00 1.00 1.00 1.00 0.98 0.99 1.00 1.00
## weekly 1.00 1.00 1.00 1.00 1.00 1.00 0.94 0.97 0.99 1.00
## biweekly 1.00 1.00 1.00 1.00 1.00 0.99 0.91 0.95 0.99 0.99
## monthly 0.99 0.99 0.99 0.99 0.99 0.99 0.89 0.92 0.97 0.99
## quarterly 0.98 0.98 0.98 0.98 0.98 0.98 0.85 0.85 0.92 0.96
## yearly 0.92 0.92 0.92 0.92 0.92 0.92 0.77 0.54 0.77 0.85
## 406853 406631 416962 407466 407054 407132 407233 407114 417126 406966
## 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 0.99 1.00 0.99
## biweekly 0.99 0.99 1.00 1.00 1.00 1.00 1.00 0.99 1.00 0.99
## monthly 0.98 0.99 0.99 0.99 0.99 0.99 0.99 0.97 0.99 0.98
## quarterly 0.94 0.98 0.98 0.98 0.98 0.98 0.98 0.94 0.98 0.96
## yearly 0.77 0.92 0.92 0.92 0.92 0.92 0.92 0.69 0.92 0.77
## 407014 417154 407223 416813 406943 407133 416922 407123 407136 416951
## 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 0.99 1.00 1.00
## biweekly 0.99 1.00 0.99 1.00 0.99 1.00 0.99 0.99 1.00 1.00
## monthly 0.99 0.99 0.97 0.99 0.97 0.99 0.99 0.97 0.99 0.99
## quarterly 0.96 0.98 0.90 0.98 0.92 0.98 0.96 0.92 0.98 0.98
## yearly 0.85 0.92 0.69 0.92 0.85 0.92 0.92 0.77 0.92 0.92
## 407115 387411 407031 416745 407251 416842 407241 416924 417164 416921
## 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 1.00
## biweekly 0.99 0.99 0.99 1.00 1.00 0.99 1.00 1.00 1.00 0.99
## monthly 0.98 0.98 0.99 0.99 0.99 0.99 0.99 0.99 0.99 0.99
## quarterly 0.96 0.94 0.96 0.98 0.98 0.96 0.98 0.98 0.98 0.96
## yearly 0.85 0.77 0.85 0.92 0.92 0.85 0.92 0.92 0.92 0.92
## 416953 426725 387361 407151 406621 387655 406662 387214 407055 407051
## 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 0.99 1.00 1.00 1.00 1.00 1.00 1.00
## biweekly 1.00 1.00 0.99 0.98 0.99 1.00 1.00 0.99 0.99 1.00
## monthly 0.99 0.99 0.98 0.95 0.98 0.99 0.99 0.99 0.99 0.99
## quarterly 0.98 0.98 0.96 0.87 0.96 0.98 0.98 0.96 0.96 0.98
## yearly 0.92 0.92 0.92 0.77 0.85 0.92 0.92 0.85 0.92 0.92
## 407161 427065 387422 387326 397324 427043 427066 387265 426961 397323
## 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.99 1.00 0.99 1.00 1.00 0.99 1.00 1.00 1.00
## biweekly 0.99 0.99 1.00 0.99 0.99 1.00 0.99 1.00 1.00 0.99
## monthly 0.99 0.97 0.99 0.97 0.98 0.99 0.97 0.99 0.99 0.99
## quarterly 0.96 0.96 0.98 0.96 0.96 0.98 0.96 0.98 0.98 0.96
## yearly 0.85 0.85 0.92 0.85 0.92 0.92 0.92 0.92 0.92 0.85
## 427054 406734 387264 377323 406713 387355 407124 387224 387234 377311
## 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 1.00
## biweekly 0.99 1.00 1.00 1.00 1.00 0.99 0.99 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.96 0.98 0.98 0.98 0.98 0.96 0.98 0.98 0.98 0.98
## yearly 0.85 0.92 0.92 0.92 0.92 0.85 0.92 0.92 0.92 0.92
## 387212 406743 407141 377242 417136 397234 407143 417156 417055 417116
## 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 1.00 1.00 1.00 1.00 1.00 1.00
## biweekly 0.99 0.99 0.99 1.00 0.99 1.00 1.00 1.00 0.99 1.00
## monthly 0.99 0.99 0.97 0.99 0.99 0.99 0.99 0.99 0.99 0.99
## quarterly 0.96 0.96 0.94 0.98 0.96 0.98 0.98 0.98 0.96 0.98
## yearly 0.85 0.85 0.85 0.92 0.85 0.92 0.92 0.92 0.92 0.92
## 417166 387426 427044 427055 387356 387451 397256 406923 387244 387222
## daily 1.00 1.00 1.00 1.00 1.00 1.00 1.00 0.96 1.00 1.00
## weekly 1.00 1.00 1.00 1.00 1.00 1.00 1.00 0.91 1.00 1.00
## biweekly 1.00 1.00 0.99 1.00 0.99 1.00 1.00 0.89 1.00 1.00
## monthly 0.99 0.99 0.99 0.99 0.99 0.99 0.99 0.88 0.99 0.99
## quarterly 0.98 0.98 0.98 0.98 0.96 0.98 0.98 0.83 0.98 0.98
## yearly 0.92 0.92 0.92 0.92 0.92 0.92 0.92 0.77 0.92 0.92
## 387112 416743 407153 357322 387223 406825 406814 406933 406863 406753
## daily 1.00 1.00 1.00 1.00 1.00 1.00 1.00 0.97 1.00 1.00
## weekly 1.00 1.00 1.00 1.00 1.00 1.00 0.99 0.93 1.00 1.00
## biweekly 1.00 1.00 1.00 1.00 1.00 1.00 0.99 0.92 1.00 0.99
## monthly 0.99 0.99 0.99 0.99 0.99 0.99 0.98 0.90 0.99 0.99
## quarterly 0.98 0.98 0.98 0.98 0.98 0.98 0.94 0.87 0.98 0.96
## yearly 0.92 0.92 0.92 0.92 0.92 0.92 0.85 0.85 0.92 0.92
## 406911 406745 406934 416824 406752 406935 406913 416865 417135 406924
## daily 1.00 1.00 0.98 0.99 1.00 1.00 0.99 1.00 1.00 0.98
## weekly 1.00 1.00 0.95 0.98 0.99 0.99 0.96 1.00 1.00 0.96
## biweekly 1.00 1.00 0.92 0.96 0.99 0.99 0.95 1.00 1.00 0.95
## monthly 0.99 0.99 0.90 0.95 0.98 0.98 0.94 0.99 0.99 0.93
## quarterly 0.98 0.98 0.88 0.90 0.94 0.98 0.92 0.98 0.98 0.92
## yearly 0.92 0.92 0.85 0.85 0.85 0.92 0.85 0.92 0.92 0.92
## 406945 387122 406914 387263 426946 387433 406925 406955 All_zones
## daily 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 0
## weekly 0.99 1.00 1.00 1.00 1.00 1.00 1.00 1.00 0
## biweekly 0.99 1.00 0.99 1.00 1.00 1.00 1.00 1.00 0
## monthly 0.97 0.99 0.99 0.99 0.99 0.99 0.99 0.99 0
## quarterly 0.96 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0
## yearly 0.92 0.92 0.92 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 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.7 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.7
## 9 336422 -64.7 33.7
## 10 336423 -64.6 33.7
## # ℹ 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 |
---|---|
416956 | 242 |
387323 | 229 |
406962 | 225 |
387313 | 223 |
387332 | 198 |
387322 | 193 |
387341 | 188 |
406923 | 177 |
406961 | 172 |
387463 | 160 |
387464 | 160 |
387333 | 137 |
416966 | 134 |
387455 | 130 |
416816 | 121 |
416826 | 115 |
406951 | 113 |
406933 | 112 |
397346 | 111 |
406952 | 110 |
387456 | 108 |
387454 | 102 |
387331 | 99 |
406963 | 94 |
387462 | 91 |
397223 | 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 807521.840187
## iter 2 value 288722.921375
## iter 3 value 279354.295467
## iter 4 value 279273.182976
## iter 5 value 138489.248628
## iter 6 value 98290.376655
## iter 7 value 50850.645393
## iter 8 value 15181.408957
## iter 9 value 14583.948698
## iter 10 value 11474.221219
## iter 11 value 11367.619835
## iter 12 value 10937.786756
## iter 13 value 10751.748190
## iter 14 value 10689.222081
## iter 15 value 10685.096229
## iter 16 value 10685.073162
## iter 17 value 10685.038918
## iter 18 value 10685.038770
## iter 19 value 10685.016218
## iter 20 value 10685.016039
## iter 20 value 10685.016038
## iter 21 value 10685.013144
## iter 21 value 10685.013144
## iter 21 value 10685.013144
## final value 10685.013144
## converged
## [,1] [,2] [,3]
## [1,] 7.437669e-06 -5.165320e-06 -9.695235e-09
## [2,] -5.165320e-06 7.231852e-06 -6.044901e-09
## [3,] -9.695235e-09 -6.044901e-09 4.278647e-08
## [1] 7.437669e-06 7.231852e-06 4.278647e-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.exp1.exp2:
estimate std_error t_value exp1 0.045 0.003 16.64 exp2 0.064 0.003 23.75 V1 -0.005 0 -25.9
Compare model fit.
model_fit_summary("scallopMod")
Model_name | AIC | AICc | BIC | PseudoR2 |
---|---|---|---|---|
lz.exp1.exp2 | -21364 | -21364 | -21345 | 0.987 |