diff --git a/DESCRIPTION b/DESCRIPTION index 400ad3081..cc58e2d04 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,7 @@ Authors@R: c(person("Gustav", "Delius", email="gustav.delius@york.ac.uk", comment = c(ORCID = "0000-0002-8478-3430")), person("Richard", "Southwell", email="richard.southwell@york.ac.uk", role=c("ctb", "cph"))) -Version: 2.0.2.9001 +Version: 2.0.3 License: GPL-3 Imports: assertthat, diff --git a/NEWS.md b/NEWS.md index 4526fd2ea..2ff95fab6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# mizer 2.0.2.9001 +# mizer 2.0.3 ## Bug fixes diff --git a/cran-comments.md b/cran-comments.md index eb3e2e059..daeb259e5 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -4,5 +4,9 @@ 0 errors ✓ | 0 warnings ✓ | 0 notes ✓ +* ubuntu 18.04 bionic, R 4.0.2 + + 0 errors ✓ | 0 warnings ✓ | 0 notes ✓ + * win-builder (release and oldrelease) No Notes, Warnings or Errors diff --git a/docs/404.html b/docs/404.html index 300311f41..af2724103 100644 --- a/docs/404.html +++ b/docs/404.html @@ -77,7 +77,7 @@
@@ -198,7 +198,7 @@This class holds the results of the simulation, including the community and resource abundances at size through time, as well as the original model parameters. It is explained in detail in the section on running a simulation.
After running the projection, it is possible to explore the results using a range of plots and analyses. These are described fully in the section on exploring the simulation results.
-To quickly look at the results of the projection you can call the plot()
method. This plots the feeding level, predation mortality, fishing mortality and abundance by size in the last time step of the simulation, and the total biomass through time. Each of the plots can be shown individually if desired.
plot(sim)
To quickly look at the results of the projection you can call the plot()
method. This plots the feeding level, predation mortality, fishing mortality and abundance by size in the last time step of the simulation, and the total biomass through time. Each of the plots can be shown individually if desired.
plot(sim)
In the above plot there are several things going on that are worth talking about. Looking at the total biomass of the community against time, you can see that the biomass quickly reaches a stable equilibrium. The other panels show what is happening at the last time step in the simulation, which in this case is when the community is at equilibrium. Fishing mortality is 0 because we set the effort
argument to 0 when running the simulation. The predation mortality rate is clearly a function of size, with the smallest sizes experiencing the highest levels of predation. The feeding level describes how satiated an individual is, with 0 being unfed, and 1 being full satiated. The feeding level at size will be strongly affected by the values of the f0
and alpha
arguments passed to the newCommunityParams()
function.
The resource and community spectra are shown in the bottom panel of the plot (the plotted resource spectrum has been truncated to make for a better plot, but really extends all the way back to \(8.11\times 10^{-11}\) g). You can see that the community spectrum forms a continuum with the resource spectrum. This is strongly affected by the level of fixed reproduction rate (the reproduction
argument passed to newCommunityParams()
)
To pull out the predation mortality at size in the final time step we use:
pred_mort_final <- pred_mort[idxFinalT(sim), ]
If you plot this predation mortality on a log-log scale you can see how the predation mortality declines to almost zero for the largest sizes.
-plot(x = w(params), y = pred_mort_final, log = "xy", type = "l", +plot(x = w(params), y = pred_mort_final, log = "xy", type = "l", xlab = "Size [g]", ylab = "Predation mortality [1/year]")Note how we used
@@ -231,8 +231,8 @@w(sim)
to get the vector of sizes to plot along the x-axis and how we specified that we wanted to have logarithmic axes.
sim0 <- project(params_knife, effort = 0, t_max = 50)Now we want to simulate again, this time with fishing. In the simulations, fishing mortality is calculated as the product of the fishing selectivity, effort and catchability (see the section on fishing gears for more details). By default catchability is set to 1. This means that a fishing effort of 1 will result in a fishing mortality of 1/year for fully selected sizes. Here we run a simulation with fishing effort set to 1 for the duration of the simulation:
-sim1 <- project(params_knife, effort = 1, t_max = 50)You can compare the difference between these scenarios by using the
-plot()
method as before. Of particular interest is the fishing mortality at size. The knife-edge selectivity at 1000 g can be clearly seen and an effort of 1 has resulted in a fishing mortality of 1 for the fully selected sizes.+plot(sim1, power = 2)You can compare the difference between these scenarios by using the
+plot()
method as before. Of particular interest is the fishing mortality at size. The knife-edge selectivity at 1000 g can be clearly seen and an effort of 1 has resulted in a fishing mortality of 1 for the fully selected sizes.plot(sim1, power = 2)To explore the presence of a trophic cascade, we are interested in looking at the relative change in abundance when the community is fished compared to when it is not fished. To do this we need to get the abundances at size from the simulation objects. This is done with the
@@ -242,7 +242,7 @@N()
function, which returns a three dimensional array with dimensions time x species x size. Here we have 51 time steps (50 from the simulation plus one which stores the initial population), 1 species and 100 sizes:
For convenience, to save you from having to determine the index of the final time, mizer provides the function
finalN()
, so we could have doneThis can then be plotted using basic R plotting commands.
-diff --git a/docs/articles/community_model_files/accessible-code-block-0.0.1/empty-anchor.js b/docs/articles/community_model_files/accessible-code-block-0.0.1/empty-anchor.js new file mode 100644 index 000000000..ca349fd6a --- /dev/null +++ b/docs/articles/community_model_files/accessible-code-block-0.0.1/empty-anchor.js @@ -0,0 +1,15 @@ +// Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> +// v0.0.1 +// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. + +document.addEventListener('DOMContentLoaded', function() { + const codeList = document.getElementsByClassName("sourceCode"); + for (var i = 0; i < codeList.length; i++) { + var linkList = codeList[i].getElementsByTagName('a'); + for (var j = 0; j < linkList.length; j++) { + if (linkList[j].innerHTML === "") { + linkList[j].setAttribute('aria-hidden', 'true'); + } + } + } +}); diff --git a/docs/articles/developer_FAQ.html b/docs/articles/developer_FAQ.html index 4e049794c..47d4d107d 100644 --- a/docs/articles/developer_FAQ.html +++ b/docs/articles/developer_FAQ.html @@ -33,7 +33,7 @@plot(x = w(params), y = relative_abundance, log = "x", type = "n", +@@ -287,7 +287,7 @@plot(x = w(params), y = relative_abundance, log = "x", type = "n", xlab = "Size (g)", ylab = "Relative abundance") lines(x = w(params), y = relative_abundance) lines(x = c(min(w(params)), max(w(params))), y = c(1, 1), lty = 2)
Mizer is compatible with R versions 3.1 and later. If you still need to install R, simply install the latest version. This guide was prepared with R version 3.6.3 (2020-02-29).
+Mizer is compatible with R versions 3.1 and later. If you still need to install R, simply install the latest version. This guide was prepared with R version 4.0.2 (2020-06-22).
This guide assumes that you will be using RStudio to work with R. There is really no reason not to use RStudio and it makes a lot of things much easier. RStudio develops rapidly and adds useful features all the time and so it pays to upgrade to the latest version frequently. This guide was written with version 1.2.1268.
Mizer is developed using the version control system Git and the code is hosted on GitHub. To contribute to the mizer code, you need to have the Git software installed on your system. On most Linux machines it will be installed already, but on other platforms you need to install it. You do not need to install any GUI for git because RStudio has built-in support for git. A good place to learn about using Git and GitHub is this chapter in the guide by Hadley on R package development.
There are several different functions for setting up a MizerParams
object for specifying various concrete models. These setup functions make various simplifying assumptions about the model parameters to reduce the amount of information that needs to be specified. This usually takes the form of assuming allometric scaling laws.
The core of mizer is the project()
function that runs a simulation of the size-spectrum model. It takes a specification of the model contained in an object of type MizerParams
and returns the results of the simulation in an object of type MizerSim
.
There are many functions for analysing and plotting the results of a mizer simulation contained in a MizerSim
object.
The MizerParams
and MizerSim
objects are S4 objects, meaning that their slots are rigorously defined and are accessed with the ‘@’ notation. You do not need to learn about S4 classes in order to understand the mizer code, because the code avoids using S4 methods. In the presentation below we assume that the MizerParams
object is called params
and the MixerSim
object is called sim
.
The MizerParams
and MizerSim
objects are S4 objects, meaning that their slots are rigorously defined and are accessed with the ‘@’ notation. You do not need to learn about S4 classes in order to understand the mizer code, because the code avoids using S4 methods. In the presentation below we assume that the MizerParams
object is called params
and the MizerSim
object is called sim
.
R is very powerful when it comes to exploring data through plots. Two useful packages for plotting are ggplot2
and plotly
. These use data.frames for input data whereas many of the mizer functions return arrays or matrices. Fortunately it is straightforward to turn arrays and matrices into data.frames using the melt()
function from the reshape2
package that mizer makes available to you. Although mizer
does include some dedicated plots, it is definitely worth your time getting to grips with these other plotting packages. This will make it possible for you to make your own plots. We provide some details in the section on using ggplot2 and plotly with mizer.
Included in mizer
are several dedicated plots that use MizerSim
objects as inputs (see the plots help page.). As well as displaying the plots, these functions all return objects of type ggplot
from the ggplot2
package, meaning that they can be further modified by the user (e.g. by changing the plotting theme). See the help page of the individual plot functions for more details. The generic plot()
method has also been overloaded for MizerSim
objects. This produces several plots in the same window to provide a snapshot of the results of the simulation.
Included in mizer
are several dedicated plots that use MizerSim
objects as inputs (see the plots help page.). As well as displaying the plots, these functions all return objects of type ggplot
from the ggplot2
package, meaning that they can be further modified by the user (e.g. by changing the plotting theme). See the help page of the individual plot functions for more details. The generic plot()
method has also been overloaded for MizerSim
objects. This produces several plots in the same window to provide a snapshot of the results of the simulation.
Some of the plots plot values by size (for example plotFeedingLevel()
and plotSpectra()
). For these plots, the default is to use the data at the final time step of the projection. With these plotting functions, it is also possible to specify a different time, or a time range to average the values over before plotting.
As mentioned above, some of the plot functions plot values against size at a point in time (or averaged over a time period). For these plots it is possible to specify the time step to plot, or the time period to average the values over. The default is to use the final time step. Here we plot the abundance spectra (biomass), averaged over time = 5 to 10:
plotSpectra(sim, time_range = 5:10)
As mentioned above, and as we have seen several times in this guide, the generic plot()
method has also been overloaded. This produces 5 plots in the same window (plotFeedingLevel()
, plotBiomass()
, plotPredMort()
, plotFMort()
and plotSpectra()
). It is possible to pass in the same arguments that these individual plots use, e.g. arguments to change the time period over which the data is averaged.
plot(sim)
As mentioned above, and as we have seen several times in this guide, the generic plot()
method has also been overloaded. This produces 5 plots in the same window (plotFeedingLevel()
, plotBiomass()
, plotPredMort()
, plotFMort()
and plotSpectra()
). It is possible to pass in the same arguments that these individual plots use, e.g. arguments to change the time period over which the data is averaged.
plot(sim)
The next section describes how to use what we have learned to model the North Sea.
vignettes/making_modifications.Rmd
+ making_modifications.Rmd
Mizer allows you to set up a multispecies model with only a very minimal of required information. All you need is a data frame that for each species specifies its maximum size w_inf
,
After a simulation has been run, the results can be examined using a range of ?plotting_functions
, ?summary_functions
and ?indicator_functions
. The plot()
function combines several of these plots into one:
plot(sim)
After a simulation has been run, the results can be examined using a range of ?plotting_functions
, ?summary_functions
and ?indicator_functions
. The plot()
function combines several of these plots into one:
plot(sim)
Just as an example: we might be interested in how the proportion of large fish varies over time. We can get the proportion of Herrings in terms of biomass that have a weight above 50g in each of the 10 years:
getProportionOfLargeFish(sim, @@ -322,7 +322,7 @@
We have specified that the time is plotted along the x axis, the value along the y axis and that the different species are represented by the colours of the lines. Note the American spelling “color” required by plotly.
+ +We have specified that the time is plotted along the x axis, the value along the y axis and that the different species are represented by the colours of the lines. Note the American spelling “color” required by plotly.
Alternatively we can do the same thing with ggplot()
:
pg <- ggplot(biomass_frame) + geom_line(aes(x = time, y = value, colour = sp)) @@ -193,8 +193,8 @@
Notice the different syntax for the ggplot2 and for plotly packages. The underlying ideas are similar: they are both implementations of the grammar of graphics. I recommend learning ggplot2 first, and switching to plotly only when it has clear advantages (in particular for animations, see below).
The main advantage of plotly, namely the interactivity of the resulting figures, can be obtained also with the ggplot syntax by running the result of
ggplot()
through the functionggplotly()
:- -ggplotly(pg)Below we will always for each plot first give the ggplot code and then the plotly code.
+ +Below we will always for each plot first give the ggplot code and then the plotly code.
plot_ly(biomass_frame) %>% add_lines(x = ~time, y = ~value, color = ~sp, colors = getColours(params))
Again note the American spelling “colors” required by plotly.
+ +Again note the American spelling “colors” required by plotly.
%>%
which feeds the return value of one function into the first argument of the next function.
+
+ In the above we used the pipe operator %>%
which feeds the return value of one function into the first argument of the next function.
Note how in plotly the range is specified by giving the logarithm to base 10 of the limits.
+ +Note how in plotly the range is specified by giving the logarithm to base 10 of the limits.
Note how this produces a smooth animation in spite of the fact that we saved the abundances only once a year. That interpolation is facilitated by the line = list(simplify = FALSE)
argument.
Note how this produces a smooth animation in spite of the fact that we saved the abundances only once a year. That interpolation is facilitated by the line = list(simplify = FALSE)
argument.
The ggplot package does not provide a similarly convenient way of creating animations. There is the gganimate package, but it is not nearly as convenient.