GithubHelp home page GithubHelp logo

smsr's Introduction

smsR

smsR is a seasonal stock assessment model package using TMB to estimate parameters. The model is the current assessment model for sandeel (4 stocks) and sprat in the North Sea.

Installation

You can install the development version of smsR as

remotes::install_github("https://github.com/nissandjac/smsR", dependencies = TRUE)

Using the model

The model can be run with the provided data set {r} sandeel_1r and the Sandeel 1r standard configuration as

library(smsR)


# Set up sandeel for area 1r

df.tmb <- get_TMB_parameters(
  mtrx = sandeel_1r$lhs, # List that contains M, mat, west, weca
  Surveyobs = sandeel_1r$survey, # Survey observations
  Catchobs = sandeel_1r$Catch, # Catch observations
  years = 1983:2021, # Years to run
  nseason = 2, # Number of seasons
  useEffort = TRUE, # Use effort to calculate F
  ages = 0:4, # Ages of the species
  recseason = 2, # Season where recruitment occurs
  CminageSeason = c(1, 1), # Minimum catch age per season
  Fmaxage = 3, # Fully selected fishing mortality age
  Qminage = c(0, 1), # Minimum age in surveys
  Qmaxage = c(1, 3), # Max age in surveys
  Fbarage = c(1, 2), # Age use to calculate Fbar
  effort = sandeel_1r$effort, # Effort input
  blocks = c(1983, 1999), # Blocks with unique selectivity
  nocatch = sandeel_1r$nocatch, # Seasons where F is not calculated
  surveyStart = c(0.75, 0), #
  surveyEnd = c(1, 0), #
  surveySeason = c(2, 1), #
  surveyCV = list(c(0, 1), c(1, 2)),
  catchCV = list(c(1, 3), c(1, 3)), # Catch CV groupings
  estCV = c(0, 2, 0), # Estimate CVs for 1) survey, 2) catch, 3) Stock recruitment relationship
  beta = 105809, # Hockey stick break point
  nllfactor = c(1, 1, 0.05) # Factor for relative strength of log-likelihood
)


parms <- getParms(df.tmb)

sas <- runAssessment(df.tmb, parms)
#> Congrats, your model converged

The resulting fit to the data can then be visualized in a summary output showing SSB, Catch, recruitment and Fbar as

plot(sas, printFig = FALSE)

Or to evaluate the retrospective patterns as

mr <- mohns_rho(df.tmb, peels = 5, parms = parms, plotfigure = FALSE)

mr$p1()

smsr's People

Contributors

mebrooks avatar nissandjac avatar

Watchers

 avatar  avatar  avatar  avatar

smsr's Issues

Release smsR 0.1.0

First release:

Prepare for release:

  • git pull
  • usethis::use_github_links()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • git push
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted ๐ŸŽ‰
  • Add preemptive link to blog post in pkgdown news menu
  • usethis::use_github_release()
  • usethis::use_dev_version(push = TRUE)
  • usethis::use_news_md()
  • Finish blog post
  • Tweet

consistency of log(0)

I have a workaround for now so there's no hurry, but I think it would make sense to have more consistency in the output of log(0) in the following example, where term_logN_next is -Inf, log_exp_pattern is -1000, and logQsurv is 0 (presumably meaning NA). I'm guessing this is an artifact that came from matching the ADMB program. Some of the ugliness of the code below is from a similar artifact and I should probably find a cleaner way to extract things.

sdr = sas$reps
par0 = sdr$value	
ind = c(which(names(par0) == "term_logN_next"),
    which(names(par0) == "log_exp_pattern"),
    which(names(par0) == "logRec"),
    which(names(par0) == "logQsurv"))
	par1 = par0[ind]
	mat = data.frame("name"=names(par1), "value"= par1, "std.dev"= sdr$sd[ind])

gives

> mat
              name        value    std.dev
1   term_logN_next         -Inf 0.00000000
2   term_logN_next    17.130563 0.42477144
3   term_logN_next    16.325818 0.27611095
4   term_logN_next    15.825591 0.22910188
5   term_logN_next    14.684768 0.23189265
6  log_exp_pattern -1000.000000 0.00000000
7  log_exp_pattern    -1.532583 0.09854816
8  log_exp_pattern    -1.133878 0.11437294
9  log_exp_pattern    -1.496165 0.23268270
10 log_exp_pattern    -1.496165 0.23268270
11 log_exp_pattern -1000.000000 0.00000000
12 log_exp_pattern    -1.439350 0.15285682
13 log_exp_pattern    -1.040645 0.16703403
14 log_exp_pattern    -1.402932 0.27128167
15 log_exp_pattern    -1.402932 0.27128167
16          logRec    19.442605 0.23645249
17          logRec    18.104052 0.24696992
18          logRec    19.947444 0.22981291
19          logRec    18.018136 0.24459142
20          logRec    17.654240 0.26642098
21          logRec    19.086763 0.23730367
22          logRec    18.370971 0.24171893
23          logRec    18.730498 0.23361764
24          logRec    18.861127 0.23639289
25          logRec    17.580810 0.24639824
26          logRec    19.039926 0.23589939
27          logRec    19.387491 0.23477048
28          logRec    17.963590 0.24782406
29          logRec    19.935396 0.22766417
30          logRec    18.047769 0.24687381
31          logRec    18.613818 0.24807006
32          logRec    18.995342 0.24533747
33          logRec    19.326225 0.24253189
34          logRec    19.846429 0.23192436
35          logRec    17.211694 0.25728581
36          logRec    18.913017 0.24058588
37          logRec    18.220791 0.22562632
38          logRec    19.097824 0.21592199
39          logRec    18.508080 0.22966582
40          logRec    19.352209 0.22254398
41          logRec    18.294743 0.21620850
42          logRec    20.206953 0.18927660
43          logRec    17.677992 0.20197208
44          logRec    17.724674 0.19618009
45          logRec    18.660119 0.18986996
46          logRec    18.030493 0.19755503
47          logRec    19.390554 0.19514738
48          logRec    17.550524 0.20441362
49          logRec    19.612380 0.18222782
50          logRec    17.143113 0.18878349
51          logRec    17.845069 0.22059928
52          logRec    18.661665 0.21879049
53          logRec    17.961165 0.27505445
54          logRec    17.749197 0.42477144
55        logQsurv     1.893280 0.13350707
56        logQsurv     1.129374 0.20196252
57        logQsurv     0.000000 0.00000000
58        logQsurv     0.000000 0.00000000
59        logQsurv     0.000000 0.00000000
60        logQsurv     0.000000 0.00000000
61        logQsurv    -7.274198 0.20813752
62        logQsurv    -6.399699 0.18813509
63        logQsurv    -6.186116 0.20725250
64        logQsurv     0.000000 0.00000000

Something's confusing about logF0

Before I started using the function getFbar, I was using this other way. Now I noticed that they don't always agree and I'm wondering why. In some years they're the same within machine precision, but in other years (e.g. 2013), they're exactly 1.0 different. I can look into it this week, but wanted to document it before I forget.

library(plyr)
FF <- exp(array(sas$reps$value[names(sas$reps$value) == 'logF0'],
 						dim = c(df.tmb$nage, df.tmb$nyears,df.tmb$nseason),
 						dimnames=list(age=ages, year=years, s=1:nseason)))
 FFm <- subset(melt(FF), age %in% 1:2)
 Fbar <- ddply(FFm, ~year, summarize, F=sum(value)/2)

> Fbar$F-getFbar(df.tmb, sas)$F
 [1]  0.000000e+00  1.110223e-16  1.110223e-16  0.000000e+00  5.551115e-17  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
[10] -1.110223e-16  0.000000e+00 -5.551115e-17  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
[19]  2.220446e-16 -1.110223e-16  1.110223e-16  0.000000e+00  0.000000e+00  0.000000e+00  1.000000e+00 -1.110223e-16  0.000000e+00
[28]  0.000000e+00  0.000000e+00  1.000000e+00  1.000000e+00  0.000000e+00  1.000000e+00  1.000000e+00  1.110223e-16  0.000000e+00
[37] -1.110223e-16  0.000000e+00  0.000000e+00  1.000000e+00

report log scale estimates

An older version reported estimates of logCatch, logFbar, and logSSB with their estimated standard deviations each year. These are useful for plotting them on the natural scale with CI that reflect that they were estimated on the log-scale. This latest one only has logRec

df.tmb$years not matching other df.tmb objects

I noticed that the objects like df.tmb$M and df.tmb$west increased their size recently, so that now their 2nd dimension is 1+length(df.tmb$years), whereas they used to match. Was this on purpose and will it stay the same, or should df.tmb$years get longer as well? I'm asking because it affects the MSE code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.