check_weight: Check consistency between total weight and number of...

View source: R/check_weight.r

check_weightR Documentation

Check consistency between total weight and number of individuals in MEDITS TB data.

Description

This function performs quality checks on the consistency between the total weight and the total number of individuals recorded in the MEDITS TB table. The consistency check is carried out both quantitatively-using known reference ranges of mean weights for each species-and qualitatively-via plots displaying the observed mean weights for each species across hauls.

Usage

  check_weight(ResultDataTB, year, DataTargetSpecies, wd, suffix)

Arguments

ResultDataTB

Catch data table formatted according to the MEDITS protocol (table TB). This data includes information on species, number of individuals, and total weight per haul.

year

Reference year for the analysis. Only hauls from the specified year will be analysed.

DataTargetSpecies

Table providing reference weight ranges for species. It contains the lower (5th percentile) and upper (95th percentile) bounds for the mean weight of individuals per species, based on historical data collected from 2012 to 2022 across all surveyed GSAs. This table should be kept updated to reflect the latest knowledge about species biology in the Mediterranean Sea.

wd

Working directory chosen by the user. This directory will contain subfolders where logs and plots will be saved.

suffix

Suffix string appended to the filenames of the log files. Useful for distinguishing outputs from multiple runs.

Details

The function operates in two phases:

1. Quantitative Check:

  • For each record in the TB table, the mean individual weight is computed.

  • If the species is listed in DataTargetSpecies, the mean weight is compared to its 5th-95th percentile reference range.

  • If the mean weight falls outside this interval, a record is saved in a CSV file reporting:

    • GSA

    • Year

    • Species

    • Haul number

    • Observed mean weight

    • Reference minimum (5th percentile)

    • Reference maximum (95th percentile)

    • Type of file

2. Qualitative Check (Plots):

  • For all species present in the dataset, the function generates plots of mean weight by haul, to visually check for possible outliers or abnormal variability.

  • To avoid excessive plotting, only species with at least 5 observations are plotted.

  • Plots display the mean weight for each haul, with haul numbers shown as labels.

  • If many species qualify for plotting, the function automatically splits the plots into multiple pages, each saved as a separate JPEG file. Each JPEG file contains up to 6 plots.

Files Produced:

  • Logfile (.dat): Contains a short message summarising whether any outliers were detected. Detailed warnings are no longer written here but are instead stored in the CSV file.

  • CSV File: Named as Check_Mean_Weights_Logfile_GSA<AREA>_Year<YEAR>_<suffix>.csv. Contains all observations where the mean weight falls outside the expected reference range.

  • Plots: Saved in JPEG format in the Graphs subdirectory. Filenames include GSA, year, and a page number.

Value

This function always returns TRUE. The purpose of the function is to perform checks and report inconsistencies, but it does not interrupt the execution of other routines in the RoME package.

Author(s)

W. Zupa, I. Bitetto

References

Anonymous. 2017. MEDITS-Handbook. Version n. 9. MEDITS Working Group. 106 pp. https://www.sibm.it/MEDITS%202011/principaledownload.htm

Examples

TB <- RoME::TB
year <- 2012
wd <- tempdir()
suffix <- "2020-03-05_time_h17m44s55"
check_weight(TB, year, DataTargetSpecies, wd, suffix)

RoME documentation built on April 24, 2026, 1:07 a.m.