-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
89 lines (72 loc) · 2.09 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# mizerStarvation
<!-- badges: start -->
<!-- badges: end -->
This is an extension package for the mizer package
(https://sizespectrum.org/mizer/) to implement starvation mortality.
## Installation
<!--
You can install the released version of mizerStarvation from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("mizerStarvation")
```
-->
You can install the development version of mizerStarvation from GitHub
with
``` r
remotes::install_github("sizespectrum/mizerStarvation")
```
## Example
This is an artificial example just to illustrate usage. We start with the
North Sea model that comes with the mizer package.
```{r message=FALSE}
library(mizerStarvation)
library(tidyverse)
library(ggplot2)
params <- NS_params
plotSpectra(params, power = 2)
```
We add starvation mortality
```{r}
params <- setStarvation(NS_params, 10)
```
We decrease resource availability to create some starvation
```{r}
capacity <- getResourceCapacity(params)
capacity[w_full(params) > 0.1] <- 0
params <- setResource(params, resource_capacity = capacity)
initialNResource(params)[w_full(params) > 0.1] <- 0
```
We can calculate the starvation mortality for each species as a function of
size with `getStarvMort()`:
```{r}
starv_mort <- getStarvMort(params)
```
This returns a matrix. For plotting we turn this into a data frame with `melt()`
and send it to ggplot:
```{r}
ggplot(melt(starv_mort)) +
geom_line(aes(x = w, y = value, colour = sp, linetype = sp), size = 1) +
scale_x_log10() +
xlab("Size [g]") +
ylab("Starvation mortality [1/year]") +
scale_colour_manual(values = params@linecolour) +
scale_linetype_manual(values = params@linetype)
```
Of course now Saithe will go extinct, not only because of the starvation
mortality but also because it stops growing before maturity.
```{r}
sim <- project(params, t_max = 30)
plotBiomass(sim)
```