Learn R Programming

mizer (version 3.4.0)

plotYieldObservedVsModel: Plotting observed vs. model yields

Description

[Experimental] If yield observations are available for at least some species via the yield_observed column, this function plots the yield of each species in the model against the observed yields. When called with a MizerSim object, the plot will use the model yields predicted for the final time step in the simulation.

Usage

plotYieldObservedVsModel(
  object,
  species = NULL,
  ratio = FALSE,
  log_scale = TRUE,
  return_data = FALSE,
  labels = TRUE,
  show_unobserved = FALSE,
  gear = NULL,
  ...
)

Value

A ggplot2 object with the plot of model yield by species compared to observed yield. If return_data = TRUE, the data frame used to create the plot is returned instead of the plot.

Arguments

object

An object of class MizerParams or MizerSim.

species

The species to be included. Optional. By default all observed yields will be included. A vector of species names, or a numeric vector with the species indices, or a logical vector indicating for each species whether it is to be included (TRUE) or not.

ratio

Whether to plot model yield vs. observed yield (FALSE) or the ratio of model : observed yield (TRUE). Default is FALSE.

log_scale

Whether to plot on the log10 scale (TRUE) or not (FALSE). For the non-ratio plot this applies for both axes, for the ratio plot only the x-axis is on the log10 scale. Default is TRUE.

return_data

Whether to return the data frame for the plot (TRUE) or not (FALSE). Default is FALSE.

labels

Whether to show text labels for each species (TRUE) or not (FALSE). Default is TRUE.

show_unobserved

Whether to include also species for which no yield observation is available. If TRUE, these species will be shown as if their observed yield was equal to the model yield.

gear

The gears to be included. Optional. By default the catch of all gears is included. A vector of gear names. Only species caught by the selected gears are shown.

...

For plotlyYieldObservedVsModel(), additional arguments passed to plotHover(). Otherwise unused.

Details

Before you can use this function you will need to have added a yield_observed column to your model which gives the observed yield in grams per year. Its home is the gear parameter data frame, see gear_params(), where you give the yield for each gear-species pair and this function adds them up over the gears. For backwards compatibility a yield_observed column in the species parameter data frame is also accepted, see get_yield_observed(). For species for which you have no observed yield, you should set the value in the yield_observed column to 0 or NA.

If a species is caught by several gears, both the model yield and the observed yield are summed over the gears. With the gear argument you can restrict the comparison to a subset of the gears, in which case only the catch of those gears enters on both axes. Because the species parameter data frame only holds the yield summed over all gears, the observations then have to come from the gear parameters.

The total relative error is shown in the caption of the plot, calculated by $$TRE = \sum_i|1-\rm{ratio_i}|$$ where \(\rm{ratio_i}\) is the ratio of model yield / observed yield for species i.

Examples

Run this code
# create an example
params <- NS_params
# In this model each species is caught by a single gear, so there is one
# row in the gear parameters for each species, in the same order.
# Species without an observation get NA.
gear_params(params)$yield_observed <-
    c(NA, NA, NA, 3e11, 4e9, 4e10, 5e10, NA, 2e11, 6e10, 3e11, NA)

# Plot with default options
plotYieldObservedVsModel(params)

# Plot including also species without observations
plotYieldObservedVsModel(params, show_unobserved = TRUE)

# Show the ratio instead
plotYieldObservedVsModel(params, ratio = TRUE)

# If several gears catch the same species, their yields are added up.
# Give Cod a second gear that takes a quarter of the observed yield.
gp <- gear_params(params)
gp["Cod, Otter", "yield_observed"] <- 3e11 * 0.75
extra <- gp["Cod, Otter", ]
extra$gear <- "Gillnet"
extra$yield_observed <- 3e11 * 0.25
gear_params(params) <- rbind(gp, extra)

# Compare only the catch of the Otter gear against its observation
plotYieldObservedVsModel(params, gear = "Otter")

Run the code above in your browser using DataLab