Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch lottery stox4 #169

Merged
merged 5 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: RstoxFDA
Version: 1.5.0-9003
Date: 2025-01-24
Version: 1.5.0-9004
Date: 2025-02-04
Title: Fisheries Dependent Analysis with RstoX
Authors@R: c(
person(given = "Edvin",
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.5.0-9004
* Fixed a bug which caused AssignPSUSamplingParameters to report the wrong records as missing, when data is not provided for all sampled records

# 1.5.0-9003
* Added function to annotate length groups: AddLengthGroupStoxBiotic (#163), and report total catch by age group: ReportAnalyticalCatchAtLength (#150)
* Added function to report mean of weight and length by age: ReportAnalyticalLengthAtAge, and ReportAnalyticalWeightAtAge (#150).
Expand Down
2 changes: 1 addition & 1 deletion R/StoxAnalyticalBaselineFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ AssignPSUSamplingParameters <- function(PSUSamplingParametersData, StoxBioticDat

records <- PSUSamplingParametersData$SelectionTable$SamplingUnitId[!is.na(PSUSamplingParametersData$SelectionTable$SamplingUnitId)]
if (!all(records %in% StoxBioticData[[level]][[SamplingUnitId]])){
missing <- records[!(records %in% StoxBioticData[[l]][[SamplingUnitId]])]
missing <- records[!(records %in% StoxBioticData[[level]][[SamplingUnitId]])]
stop(paste("Records are not found for all sampled PSUs. Missing for the following SamplingUnitIds (", SamplingUnitId,"): ", truncateStringVector(missing), sep=""))
}

Expand Down
72 changes: 72 additions & 0 deletions inst/testresources/lotteryParameters/lotteryDesignNSHdetailed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
Stratum N n SelectionMethod FrameDescription Order SamplingUnitId InclusionProbability HTsamplingWeight SelectionProbability HHsamplingWeight SelectionDescription CountryVessel VesselLengthGroup TargetSpecies TargetStock
Sild2022 Nordsjo 811 71 Poisson "" 3 38401 0.213196915139625 0.0080680146704093 0.00217741935483873 0.00766305544800977 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 46 38433 0.247412405326388 0.00695226189957357 0.00258064516129031 0.00646570303425833 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 5 38440 0.1700984890555 0.0101122346740615 0.00169354838709679 0.00985249986172684 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 71 38445 0.108975250145035 0.0157840962672098 0.00104838709677424 0.015915576699712 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 44 38438 0.641175307024414 0.00268269195676777 0.0092741935483871 0.00179915214866318 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 36 38441 0.233906828422691 0.00735367945703649 0.0024193548387097 0.00689674990320879 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 39 38448 0.267229615158194 0.00643669616488522 0.00282258064516128 0.00591149991703619 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 7 38403 0.0767615148687669 0.0224080496844438 0.000725806451612909 0.0229891663440293 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 66 38435 0.143125007547176 0.0120179964948861 0.00140322580645158 0.0118909481089811 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 67 38436 0.147680162555427 0.0116473046160613 0.00145161290322582 0.0114945831720147 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 70 38443 0.0182839435244132 0.0940757576031566 0.000167741935483856 0.0994723543732134 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 9 38446 0.267229615158194 0.00643669616488522 0.00282258064516128 0.00591149991703619 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 43 38447 0.247412405326388 0.00695226189957357 0.00258064516129031 0.00646570303425833 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 10 38402 0.108975250145035 0.0157840962672098 0.00104838709677424 0.015915576699712 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 48 38434 0.220161129326957 0.00781280439599331 0.00225806451612898 0.00738937489629538 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 27 38442 0.068529393639208 0.0250998257490547 0.000645161290322549 0.0258628121370345 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 32 38444 0.147680162555427 0.0116473046160613 0.00145161290322582 0.0114945831720147 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 68 38437 0.147680162555427 0.0116473046160613 0.00145161290322582 0.0114945831720147 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 61 38439 0.311481476435603 0.00552224118980031 0.00338709677419358 0.00492624993086342 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 31 38431 0.0889747087440887 0.019332188475939 0.000846774193548394 0.0197049997234537 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 55 38415 0.136247006433322 0.0126246872064253 0.00133064516129033 0.0125395452785614 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 33 38406 0.097027756531011 0.0177276678399005 0.000927419354838754 0.0179915214866309 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 13 38417 0.101027788104015 0.0170257695562093 0.000967741935483879 0.017241874758022 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 18 38419 0.0849215381190344 0.0202548832384721 0.00080645161290327 0.0206902497096254 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 29 38408 0.184718409696934 0.00931188094275289 0.0018548387096774 0.00899576074331599 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 37 38412 0.216686691440281 0.00793807791147411 0.00221774193548385 0.00752372716713699 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 40 38422 0.0518463272604551 0.0331764259865801 0.00048387096774194 0.034483749516044 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 51 38432 0.162691408611336 0.0105726285961522 0.00161290322580643 0.0103451248548134 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 60 38429 0.338519898362406 0.00508116612155855 0.00375000000000003 0.00444951606658632 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 11 38404 0.162691408611336 0.0105726285961522 0.00161290322580643 0.0103451248548134 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 28 38413 0.097027756531011 0.0177276678399005 0.000927419354838754 0.0179915214866309 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 2 38414 0.240689370659604 0.00714645534332767 0.00249999999999995 0.00667427409987967 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 17 38405 0.267229615158194 0.00643669616488522 0.00282258064516128 0.00591149991703619 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 1 38411 0.458713264018625 0.00374978439464236 0.0055645161290323 0.00299858691443861 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 24 38416 0.116853084910627 0.014719986557035 0.00112903225806449 0.0147787497925908 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 25 38427 0.589628784636336 0.00291721822925146 0.00806451612903225 0.00206902497096266 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 38 38409 0.162691408611336 0.0105726285961522 0.00161290322580643 0.0103451248548134 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 23 38424 0.347296770955766 0.00495275505815625 0.00387096774193552 0.00431046868950549 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 30 38421 0.116853084910627 0.014719986557035 0.00112903225806449 0.0147787497925908 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 35 38430 0.116853084910627 0.014719986557035 0.00112903225806449 0.0147787497925908 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 56 38426 0.233906828422691 0.00735367945703649 0.0024193548387097 0.00689674990320879 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 54 38407 0.068529393639208 0.0250998257490547 0.000645161290322549 0.0258628121370345 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 21 38418 0.229685923270579 0.00748881696596698 0.00236952419354841 0.00704178724789118 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 42 38428 0.143125007547176 0.0120179964948861 0.00140322580645158 0.0118909481089811 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 50 38420 0.0425447856855458 0.040429768567782 0.000395161290322577 0.0422249994074016 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 20 38423 0.463520590962966 0.0037108941276137 0.00564516129032255 0.00295574995851809 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 16 38410 0.267034025829916 0.00644141072916334 0.00282016129032259 0.00591657126383371 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 34 38425 0.0930100890906527 0.0184934328721696 0.000887096774193519 0.0188093179178429 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 45 0.254076449772695 0.00676991449058477 0.00266129032258067 0.00626977263928072 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 8 0.0849215381190344 0.0202548832384721 0.00080645161290327 0.0206902497096254 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 15 0.260682016891707 0.00659836784885341 0.00274193548387092 0.00608536756165498 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 12 0.0602245433032077 0.0285610441306723 0.0005645161290323 0.0295574995851786 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 47 0.068529393639208 0.0250998257490547 0.000645161290322549 0.0258628121370345 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 53 0.216686691440281 0.00793807791147411 0.00221774193548385 0.00752372716713699 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 59 0.570866304669027 0.00301309750630624 0.00766129032258067 0.00217792102206594 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 26 0.199083079634323 0.00863999010961628 0.00201612903225812 0.0082760998838504 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 63 0.1700984890555 0.0101122346740615 0.00169354838709679 0.00985249986172684 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 65 0.1700984890555 0.0101122346740615 0.00169354838709679 0.00985249986172684 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 52 0.174511532419619 0.00985651673092022 0.00174193548387092 0.00957881931001258 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 22 0.202634883401628 0.00848854753020615 0.00205645161290324 0.00811382341553975 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 4 0.068529393639208 0.0250998257490547 0.000645161290322549 0.0258628121370345 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 6 0.132402285228299 0.0129912851282484 0.00129032258064521 0.0129314060685161 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 64 0.101027788104015 0.0170257695562093 0.000967741935483879 0.017241874758022 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 58 0.0808504995083754 0.0212747707125089 0.000766129032258034 0.0217792102206604 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 69 0.140074844132902 0.0122796912584854 0.00137096774193546 0.01217073512331 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 62 0.0552064585338686 0.0311571487234098 0.000516129032258061 0.0323285151712917 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 49 0.112922833036567 0.0152323121265962 0.00108870967741936 0.0153261108960195 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 19 0.386753608156008 0.00444747198929469 0.0044354838709677 0.00376186358356849 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 14 0.413480846839946 0.00415998915591446 0.0048387096774194 0.0034483749516044 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 41 0.247412405326388 0.00695226189957357 0.00258064516129031 0.00646570303425833 "" NOR >15m HER Nordsjo
Sild2022 Nordsjo 811 71 Poisson "" 57 0.0518463272604551 0.0331764259865801 0.00048387096774194 0.034483749516044 "" NOR >15m HER Nordsjo
8 changes: 7 additions & 1 deletion vignettes/Stox-Analytical.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ For testing pre-releases of StoX, obtain the stox packages from the testing repo
install.packages(c("RstoxData", "RstoxBase", "RstoxFramework", "RstoxFDA"), repos = c("https://stoxproject.github.io/testingRepo/"))
```

This will install latest pre-release available for your version of R and operating system. Make sure you have R 4.2 or 4.3 if testing on Mac or Windows.
This will install latest pre-release available for your version of R and operating system. Make sure you have R 4.4 or 4.4 if testing on Mac or Windows.

After you have finished testing, you may want to revert to the production packages. This may require explicitly uninstalling the packages first, as they have higher version numbers than production packages:

Expand All @@ -67,6 +67,7 @@ A minimal StoX project implementing analytical catch at age estimates with catch
| ReadSamples | ReadBiotic | Reads sample data |
| StoxBiotic | StoxBiotic | Convert sample data to StoxBiotic |
| AddSamplingId | AddToStoxBiotic | Add serialnumber to StoxBiotic |
| AddLengthGroups | AddLengthGroupStoxBiotic | If catch-at-length is desired. Adds a column to StoxBiotic, grouping individuals by length. |
| ReadPSUsamplingParameters | ReadPSUSamplingParameters | Read sampling parameters for each haul. These ar provided from the catch lottery. |
| ComputeINDsamplingParameters | ComputeIndividualSamplingParameters | Defines sampling parameters for each individual, within haul. Parameters are inferred from data with configurable assumptions. |
| AssignPSUSamplingParameters | AssignPSUSamplingParameters | Matches selections to data records, handles non-response corrections |
Expand All @@ -83,6 +84,11 @@ The following functions provides reporting from analytical estimates:
|:------|:-----|
| ReportAnalyticalCatchAtAge | Tabulate total catch of each age group |
| PlotCatchAtAgeTotals | Plot total catch of each age group |
| ReportAnalyticalCatchAtLength | Tabulate total catch of each length group |
| ReportAnalyticalLengthAtAge | Tabulate mean length of each age group |
| PlotMeanLengthAtAge | Plot mean length of each age group |
| ReportAnalyticalWeightAtAge | Tabulate mean weight of each age group |
| PlotMeanWeightAtAge | Plot mean weight of each age group |

In addition some functions are relevant in this context, that may also be used with other estimation approaches, such as Reca:

Expand Down
Loading