GithubHelp home page GithubHelp logo

sam's Introduction

SAM

Git page for stockassessment R-package containing the state-space assessment model (SAM)

Can be installed by typing:

devtools::install_github("fishfollower/SAM/stockassessment")

A quick example:

We start by downloading a few needed files. Here the files are taken from one of the test cases (North Sea Herring). We use a temporary folder to make sure we are not overwriting existing files.

setwd(tempdir())
filestoget <- c("cn.dat", "cw.dat", "dw.dat", "lf.dat", "lw.dat", 
                "mo.dat", "nm.dat", "pf.dat", "pm.dat", "sw.dat", 
                "survey.dat")
url <- "https://raw.githubusercontent.com/fishfollower/SAM/master/stockassessment/tests/nsher/"
d <- lapply(filestoget, function(f)download.file(paste(url,f,sep=""), f))

Now the files should be downloaded to our current working directory. Next we read in the data files and create a collected data object:

library(stockassessment)
cn <- read.ices("cn.dat")
cw <- read.ices("cw.dat")
dw <- read.ices("dw.dat")
lf <- read.ices("lf.dat")
lw <- read.ices("lw.dat")
mo <- read.ices("mo.dat")
nm <- read.ices("nm.dat")
pf <- read.ices("pf.dat")
pm <- read.ices("pm.dat")
sw <- read.ices("sw.dat")
surveys <- read.ices("survey.dat")

dat <- setup.sam.data(surveys=surveys,
                      residual.fleet=cn, 
                      prop.mature=mo, 
                      stock.mean.weight=sw, 
                      catch.mean.weight=cw, 
                      dis.mean.weight=dw, 
                      land.mean.weight=lw,
                      prop.f=pf, 
                      prop.m=pm, 
                      natural.mortality=nm, 
                      land.frac=lf)

From this defined data object it is possible to generate a default/minimalistic model configuration.

conf <- defcon(dat)

This configuration can be changed by modifying/overwriting the elements in the list. Here we set the fbar range to 2-6, allow correlated F processes, and modify the catchability couplings.

conf$fbarRange <- c(2,6)
conf$corFlag <- 1
conf$keyLogFpar <- matrix(c(
-1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
-1,    0,    1,    2,    3,    4,    5,    6,   -1,
-1,    7,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
 8,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1), nrow=4, byrow=TRUE)

Now the configuration and data is in place, so we can generate default initial values for all our model parameters.

par <- defpar(dat,conf)

These default initial can be modified (like the configuration), but it is rarely necessary. To illustrate we modify the initial values for the catchabilities

par$logFpar <- rep(0,9)

Now we are ready to optimize the model.

fit <- sam.fit(dat,conf,par) 

This fitted model object contains all information about the fit and can be used to plot and extract all requested quantities. Let's plot the SSB, Fbar, rectuitment, and total catch.

ssbplot(fit)

fbarplot(fit)

recplot(fit)

catchplot(fit)

Model diagnosis in terms of residuals (one observation ahead residuals, and process joint sample residuals), retrospective, and leave-out can be computed and plottet in the following way.

res <- residuals(fit)
plot(res)

resp <- procres(fit)
plot(resp)

retro <- retro(fit,year=10)
plot(retro)

lo <- leaveout(fit)
plot(lo)

Build Status

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.