inst/markdown/archive/snowcrab_presentation_methods.md

title: "Snow Crab, Scotian Shelf, Canada (NAFO Div. 4VWX) in 2023" subtitle: "Life history and Methodological considerations" author: "Snow Crab Group"

author: "Jae S. Choi"

footnote: "jae.choi@dfo-mpo.gc.ca"

institute: "Bedford Institute of Oceanography, DFO Science"

date: "r format(Sys.time(), '%d %B, %Y')"

output: beamer_presentation: theme: "metropolis" colortheme: "seagull" fonttheme: "professionalfonts" fig_caption: yes # latex_engine: pdflatex latex_engine: lualatex keep_tex: true classoption: - aspectratio=169 #16:9 wide - t # top align header-includes: - \usepackage{graphicx} - \usepackage[font={scriptsize}, labelfont={bf}]{caption} # - \usepackage{float} # - \usepackage{subfig} # - \newcommand{\btiny}{\begin{tiny}} # - \newcommand{\etiny}{\end{tiny}} params: year.assessment: 2023 media_loc: "media" debugging: FALSE

```{r setup, include=FALSE} require(knitr) knitr::opts_chunk$set( root.dir = data_root, echo = FALSE, out.width="6.2in",

dev.args = list(type = "cairo"),

fig.retina = 2,
dpi=192

)

# inits and data loading (front load all required data)

require(aegis)

media_loc = params$media_loc year.assessment = params$year.assessment year_previous = year.assessment - 1 p = bio.snowcrab::load.environment( year.assessment=year.assessment ) SCD = project.datadirectory("bio.snowcrab")

# fishery_model_results = file.path( "/home", "jae", "projects", "dynamical_model", "snowcrab", "outputs" ) fishery_model_results = file.path( SCD, "fishery_model" )

sn_env = snowcrab_load_key_results_to_memory( year.assessment, debugging=params$debugging, return_as_list=TRUE )

attach(sn_env)

# predator diet data diet_data_dir = file.path( SCD, "data", "diets" ) require(data.table) # for speed require(lubridate) require(stringr) require(gt) # table formatting require(janitor) require(ggplot2) require(aegis) # map-related require(bio.taxonomy) # handle species codes

# assimilate the CSV data tables: # diet = get_feeding_data( diet_data_dir, redo=TRUE ) # if there is a data update diet = get_feeding_data( diet_data_dir, redo=FALSE ) tx = taxa_to_code("snow crab") # matching codes are # spec tsn tx vern tx_index #1 528 172379 BENTHODESMUS BENTHODESMUS 1659 #2 2522 98427 CHIONOECETES SPIDER QUEEN SNOW UNID 728 #3 2526 98428 CHIONOECETES OPILIO SNOW CRAB QUEEN 729 # 2 and 3 are correct

snowcrab_predators = diet[ preyspeccd %in% c(2522, 2526), ] # n=159 oservations out of a total of 58287 observations in db (=0.28% of all data) snowcrab_predators$Species = code_to_taxa(snowcrab_predators$spec)$vern snowcrab_predators$Predator = factor(snowcrab_predators$Species)

counts = snowcrab_predators[ , .(Frequency=.N), by=.(Species)] setorderv(counts, "Frequency", order=-1)

# species composition psp = speciescomposition_parameters( yrs=p$yrs, carstm_model_label="default" ) pca = speciescomposition_db( DS="pca", p=psp )

pcadata = as.data.frame( pca$loadings ) pcadata$vern = stringr::str_to_title( taxonomy.recode( from="spec", to="taxa", tolookup=rownames( pcadata ) )$vern )

# bycatch summaries o_cfaall = observer.db( DS="bycatch_summary", p=p, yrs=p$yrs, region="cfaall" ) o_cfanorth = observer.db( DS="bycatch_summary", p=p, yrs=p$yrs, region="cfanorth" ) o_cfasouth = observer.db( DS="bycatch_summary", p=p, yrs=p$yrs, region="cfasouth" ) o_cfa4x = observer.db( DS="bycatch_summary", p=p, yrs=p$yrs, region="cfa4x" )




## Life history {.c}

## Photos {.c}
::: columns 
:::: column 
```{r photos, echo=FALSE, out.width='90%', fig.align='center', fig.show='hold',  fig.cap = 'Snow Crab pelagic Zoea.' }
fn1=file.path( media_loc, "snowcrab_zoea.png" )
knitr::include_graphics( c(fn1 ) ) 
# \@ref(fig:photos)  

:::: :::: column ```{r photos2, echo=FALSE, out.width='90%', fig.align='center', fig.show='hold', fig.cap = 'Snow Crab male and mating pair. Note sexual dimorphism.' } fn2=file.path( media_loc, "snowcrab_male.png" ) fn3=file.path( media_loc, "snowcrab_male_and_female.png" ) knitr::include_graphics( c( fn2, fn3) )

\@ref(fig:photos)

::::
:::


## Life history stages{.c}

```{r lifehistory, echo=FALSE, out.width='95%', fig.align='center', fig.cap = 'Life history patterns of snow crab and approximate timing of the main life history stages of snow crab and size (carapace width; CW mm) and instar (Roman numerals). Size and timings are specific to the area of study and vary with environmental conditions, food availability and genetic variability.' }
loc = file.path( Sys.getenv("HOME"), "projects", "dynamical_model", "snowcrab", "media" )
fn1=file.path( loc, "life_history.png" )
knitr::include_graphics( fn1 ) 
# \@ref(fig:lifehistory)  

Growth stanzas {.c}

```{r lifehistory_male, echo=FALSE, out.width='55%', fig.align='center', fig.cap = 'The growth stanzas of the male component and decision paths to maturity and terminal moult. Black ellipses indicate terminally molted animals.' } loc = file.path( Sys.getenv("HOME"), "projects", "dynamical_model", "snowcrab", "media" ) fn1=file.path( loc, "life_history_male.png" ) knitr::include_graphics( fn1 )

\@ref(fig:lifehistory_male)


## Growth modes{.c}

```{r growth_modes1, echo=FALSE, out.width='100%', fig.align='center', fig.cap = 'Modal analysis.' }
loc = file.path( Sys.getenv("HOME"), "bio.data", "bio.snowcrab", "output" )
fn1=file.path( loc, "size_structure", "growth_summary1.png" )
knitr::include_graphics( c(fn1) ) 

Growth modes 2 {.c}

```{r growth_modes2, echo=FALSE, out.width='30%', fig.align='center', fig.cap = 'Modal analysis.' } loc = file.path( Sys.getenv("HOME"), "bio.data", "bio.snowcrab", "output" ) fn1=file.path( loc, "size_structure", "growth_summary2.png" ) knitr::include_graphics( c(fn1) )



## Notable traits

  - Sexual dimorphism 
  - Pelagic in larval stages; benthic in pre-adolescent and adult stages
  - Biannual, annual molts depending upon size/age and environmental conditions
  - Terminal molt to maturity and survives for up to 5 years
  - Total life span: up to 15 years. 
  - Stenothermic (narrow) temperature requirements < 6 C
  - Ontogenetic shifts in habitat preferences: warmer, complex substrates to mud.  
  - Cannibalism of immature crab by mature female snow crab are known 
  - Primiparous female (57.4 mm CW) produces between 35,000 to 46,000 eggs
  - Multiparous females more fecund (>100,000 eggs) 
  - Eggs extruded February and April and brooded for up to two years (> 80% in SSE follow an annual cycle) and hatched/released from April to June.


## Life history: Spatially and temporally complex
  - 14+ instars/life stages with different preferences; 
  - Multiply prey and predators (ontogenetic shift); many ecosystem changes 
  - Growth: biannual (up to instar 5), annual, biennial (skip moulters)
  - Reproduction: annual and biennial; strong sexual selection (dimorphism) and parental investment for up to 2 years; lags of up to 10 years
  - Mortality: pulsed due to moult vulnerability, cannibalism
  - Movement: seasonal, annual, ontogenetic 
  - Evolution: sexual dimorphism, parental investment of brood, stenothermic
  - Population structure integrates all these effects ("Cumulative Effects")

## Population structure integrates everything
  - Spatial structures: scales > 100's km; local crab holes ( 10's to 100's m ) 
    - Confluence of major oceanic currents (temperature, salinity, nutrients, primary and secondary production)
  - Temporal processes: scales > 10 yrs; daily, tidal currents,  
    - 10-15 y life cycle, seasonal, annual, multiyear, decadal, evolutionary, etc. 
  - Biological (individual, age classes, population, etc.): cross multiple space, time and organismal scales 
    - Ontogeny (developmental change and habitat requirements)
    - Life history (habitat preferences)
    - Inter-specific interactions (feeding relationships change with biological stage)
    - Interactions with humans

## Multiple processes at multiple scales 

  - Populations integrate these processes  
  - **Induces** auto-correlations at multiple spatial-temporal-organisational scales
  - We perceive this as "autocorrelation"
  - First law of geography: "everything is related to everything else, but near things are more related than distant things" (Tobler 1970) 
  - "Nonstationary" processes (mean and variance not stable in space and time)
  - Ignoring correlated errors causes inappropriate parameter estimates


## Observations error (precision, accuracy) 

  - Pragmatic compromise between costs vs information gain
  - SSE snow crab domain with ~400 stations and ~109,120  $\text{km}^{2}$ 
  - Each station represents 273 $\text{km}^{2}$ , but actually samples ~0.0039 $\text{km}^{2}$ 
    - A factor of 1:70,000 (spatially)
  - Each sample is about 5 minutes but represents a whole year (525,600 minutes)
    - A factor of 1:105,120
  - In space-time: 
    - A factor of ~ 1:10 billion (note: 1 Angstrom = 10$^{-10}$m) .. the same scale as an atom! 
    - A few samples will do if it is spatially homogenous ("well mixed" = constant forcings, no ecosystem variability, no spatiotemporal autocorrelation)
  - Spatial bias/aliasing
  - Temporal bias/aliasing ("Spring" before 2004)


## Solutions: Experimental design

  - Naive (Ignore everything) "Random" Sampling / Fixed Station Sampling (IID)
  - Stratified (Hope this works) "Random" Sampling -- depth is all that matters (IID within, IID between)
    - Ignore spatiotemporal structure 
    - Ignore Ecosystem variability
    - Assume **no autocorrelated errors**
  - Geostatistical design (gridded, pseudo-random)
    - Address spatial autocorrelation as a stationary process
    - Abundance is NOT first and second order stationary and non-Gaussian (distributional bias)
    - Ignores time (temporal discretization/aliasing)
    - Ignores ecosystem variability
    - Variogram solutions unstable when population size declines

## Solutions: Experimental design 2

  - Hierarchical process temporal and covariate as an external forcing and spatial as a local process (UKED)
    - Variogram instability across time/stage when abundance declined and distribution was spotty
    - NOT second-order stationary
  - Mosaic process:
    - Hierarchical first and second-order **non-stationary** model (modular)
    - Global Hurdle/INLA/GAM/GLM 
    - Local Random spatial effects (residuals) Matern (SPDE; FFT)
    - Independent space and time process
    - Slow
  - Model-based inference: Bayesian hierarchical mixed-effects model
    - Conditional Autoregressive Space-Time Models (CARSTM, separable: Kronecker product space BYM2, time AR1)
    - Hurdle/Poisson and Binomial number process, with Gaussian weight process


## Latent ecological process

- Real (latent, unobserved) ecological processes are generaly spatiotemporal processes  

- Observations from samples/surveys are used to infer the real (latent, unobserved) state

- Stock assessments, almost always, focus only upon a purely *temporal process* by integrating the latent spatiotemporal process  

- Experimental design assumes samples are random or random-stratified, almost always, as a purely *spatial process*

- This is a problem: 
  - temporal aliasing is likely (as it is usually ignored)
  - spatial aliasing is likely when sampling environments that cannot be randomly sampled 
    - many locations are not directly accessible to trawls (rocks and bedrock)
    - easier to sample locations (softer, gravel or mud substrates) coincide with preferred snow habitats


## Snow crab survey locations {.c}

::: columns 
:::: column 
```{r survey-locations-map, out.width='60%', fig.show='hold', fig.align='center', fig.cap= 'Snow Crab survey locations. No survey in 2020 (Covid-19) and incomplete 2022 (mechanical issues).' }
loc = file.path( SCD, "output", "maps", "survey.locations" )
yrsplot = setdiff( year.assessment + c(0:-9), 2020)
fn6 = file.path( loc, paste( "survey.locations", yrsplot[6], "png", sep=".") )
fn5 = file.path( loc, paste( "survey.locations", yrsplot[5], "png", sep=".") )
fn4 = file.path( loc, paste( "survey.locations", yrsplot[4], "png", sep=".") )
fn3 = file.path( loc, paste( "survey.locations", yrsplot[3], "png", sep=".") )
fn2 = file.path( loc, paste( "survey.locations", yrsplot[2], "png", sep=".") )
fn1 = file.path( loc, paste( "survey.locations", yrsplot[1], "png", sep=".") )
knitr::include_graphics( c( fn2, fn1) )
# \@ref(fig:survey-locations-map)  

:::: :::: column

```{r surveydomain, out.width='100%', fig.show='hold', fig.align='center', fig.cap= 'Snow Crab survey prediction grid.' } fn1 = file.path( media_loc, "carstm_prediction_domain.png" ) knitr::include_graphics( c( fn1) )

::::
:::


## Clustering  {.c}

```{r aggregation, echo=FALSE, out.width='40%', fig.align='center', fig.show='hold',  fig.cap = 'Australian spider crab \\emph{Leptomithrax gaimardii} aggregation for moulting and migration and Alaska red king crab \\emph{Paralithodes camtschaticus} aggregation in Alaska for egg release, migrations.' }
fn1=file.path( media_loc, "australian_leptomithrax_gaimardii.png" )
fn2=file.path( media_loc, "kingcrab_aggregation.png" ) 
knitr::include_graphics( c(fn1, fn2 ) ) 
# \@ref(fig:aggregation)  

Clustering2 {.c}

```{r clustering, echo=FALSE, out.width='60%', fig.align='center', fig.show='hold', fig.cap = 'High density locations of Snow Crab, approximately 1 per square meter.'} fn = file.path(p$project.outputdir, "maps", "map_highdensity_locations.png" ) knitr::include_graphics( fn )

\@ref(fig:aggregation)

if (0) { # high density locations directly from databases M = snowcrab.db( DS="set.complete", p=p ) setDT(M) i = which(M$totno.all > 2.5*10^5) H = M[i, .( plon, plat, towquality, dist, distance, surfacearea, vessel, yr, z, julian, no.male.all, no.female.all, cw.mean, totno.all, totno.male.imm, totno.male.mat, totno.female.imm, totno.female.mat, totno.female.primiparous, totno.female.multiparous, totno.female.berried)] H$log10density = log10(H$totno.all) library(ggplot2) cst = coastline_db( p=p, project_to=st_crs(pg) ) isodepths = c(100, 200, 300) isob = isobath_db( DS="isobath", depths=isodepths, project_to=st_crs(pg)) isob$level = as.factor( isob$level) plt = ggplot() + geom_sf( data=cst, show.legend=FALSE ) + geom_sf( data=isob, aes( alpha=0.1, fill=level), lwd=0.1, show.legend=FALSE) + geom_point(data=H, aes(x=plon, y=plat, colour=log10density), size=5) + coord_sf(xlim = c(270, 940 ), ylim = c(4780, 5200 )) + theme(legend.position="inside", legend.position.inside=c(0.08, 0.8)) png(filename=fn, width=1000,height=600, res=144) (plt) dev.off() }


## Sampling bias: depth
```{r bias-depth, out.width='40%', fig.show='hold', fig.align='center', fig.cap= 'Comparison of depths in snow crab domain ("predictions") and survey locations ("observations"). Bias: survey trawls preferentially sample deeper locations. Red line is overall average.' }
loc = file.path( homedir, "projects", "snowcrabframework" )
knitr::include_graphics( file.path( loc, "bias_depth.png" ) )

Sampling bias: substrate grain size

```{r bias-substrate, out.width='40%', fig.show='hold', fig.align='center', fig.cap= 'Comparison of substrate grain size (log; mm) in snow crab domain ("predictions") and survey locations ("observations"). No bias observed. Red line is overall average.' } loc = file.path( homedir, "projects", "snowcrabframework" ) knitr::include_graphics( file.path( loc, "bias_substrate.png" ) )


## Sampling bias: bottom temperature

```{r bias-temperature, out.width='40%', fig.show='hold', fig.align='center', fig.cap= 'Comparison of bottom temperature (degrees Celcius) in snow crab domain ("predictions") and survey locations ("observations"). Bias: surveys preferentially sample cold water bottoms. Red line is overall average.' }
loc = file.path( homedir, "projects", "snowcrabframework" )
knitr::include_graphics( file.path( loc, "bias_temp.png" ) ) 

Sampling bias: species composition 1 (temperature related)

```{r bias-pc1, out.width='40%', fig.show='hold', fig.align='center', fig.cap= 'Comparison of species composition gradient (PC1) in snow crab domain ("predictions") and survey locations ("observations"). Bias: surveys preferentially sample cold water species. Red line is overall average.' } loc = file.path( homedir, "projects", "snowcrabframework" ) knitr::include_graphics( file.path( loc, "bias_pca1.png" ) )



## Sampling bias: species composition 2 (depth related)

```{r bias-pc2, out.width='40%', fig.show='hold', fig.align='center', fig.cap= 'Comparison of species composition gradient (PC2) in snow crab domain ("predictions") and survey locations ("observations"). Bias: surveys preferentially sample deeper species. Red line is overall average.' }
loc = file.path( homedir, "projects", "snowcrabframework" )
knitr::include_graphics( file.path( loc, "bias_pca2.png" ) ) 

Sampling bias: summary

Indications of sampling bias relative to spatial domain of snow crab:

Generalized linear models (GLM)

\small

::: columns :::: column

$S={S_{1},...,S_{K}}$ is a set of $k=1,...,K$ non-overlapping (areal) units.

$\boldsymbol{Y}=(y_{1},...,y_{K})$ are observations on $S$, then:

$$\begin{aligned} Y & \sim f(y|\Omega) g(\mu) &=\boldsymbol{x}^{T}\boldsymbol{\beta}+\boldsymbol{O}+\boldsymbol{\varepsilon}. \end{aligned}$$

::::

:::: column

:::: :::

\normalsize

Generalized linear models (GLM) ...

\small ::: columns :::: column For each distributional family: \vspace{2mm}

$Y\sim\text{Normal}(\mu,\sigma^{2})$

$Y\sim\text{Poisson}(\mu)$, and

$Y\sim\text{Binomial}(\eta,\theta)$

:::: column

Stratified random sampling assumes:

$$\begin{aligned} \varepsilon_{s} & \sim\text{N}(0,{}^{\varepsilon}!\sigma_{s}^{2}) \end{aligned}$$

i.e., IID errors in space (time is usually ignored)

:::: :::

\normalsize

Autocorrelated spatial errors

\small

Kriging extends $\varepsilon$ to spatial contraints ("variograms").

$$\begin{aligned} Y_{t} & \sim\text{MVN}(\boldsymbol{\mu}{t},\boldsymbol{\Sigma}{t})\ g(\mu_{t}) & =\boldsymbol{x_{t}}^{T}\boldsymbol{\beta_{t}}+\boldsymbol{\omega}{t}+\boldsymbol{\varepsilon}{t}\ \varepsilon_{t} & \sim N(0,{}^{\varepsilon}!\sigma_{t}^{2})\ \omega_{t} & \sim\text{GP}(\boldsymbol{0},C(s_{t},s_{t}';^{\omega}!\theta_{t}))\ \boldsymbol{\Sigma_{t}} & =\left[C(\text{s}{it},\text{s}{jt};^{\omega}!\theta_{t})\right]{i,j=1}^{K}+{}^{\varepsilon}!\sigma{t}^{2}I_{S} \ C(h){\text{Mat\'{e}rn}} & = ;^{\omega}\sigma^{2}\frac{1}{2^{\nu-1}\Gamma(\nu)}(\sqrt{2\nu}h/\phi)^{\nu}\ K{\nu}(\sqrt{2\nu}h/\phi). \end{aligned}$$

\footnotesize - ignores temporal structure, focus upon spatial-only process

\normalsize



jae0/snowcrab documentation built on Nov. 6, 2024, 10:13 p.m.