FETSI

Target species imputation

This check follows the suggestion of Starr (2007) to replace missing values for the column target_species with the most frequently recorded value for other fishing events in the trip.

-- © Copyright 2026 The Kahawai Collective
-- SPDX-License-Identifier: MIT
INSERT INTO grooming_rules
VALUES ('FETSI', 'edw', 'effort', 'Fix', 'Replace missing target species with the modal value for a trip');

CREATE OR REPLACE FUNCTION FETSI()
RETURNS VOID AS $$

WITH _fetsi AS (
    SELECT DISTINCT ON (trip) trip, target_species, count(*)
    FROM   groomed.effort
    WHERE  target_species IS NOT NULL
    AND trip IN (
        SELECT DISTINCT trip
        FROM   groomed.effort
        WHERE  target_species IS NULL AND trip IS NOT NULL
    )
    GROUP BY trip, target_species
    ORDER BY trip, count DESC, target_species
)
INSERT INTO groomed.checks (code, "table", "column", id, orig, new)
SELECT 'FETSI', 'effort', 'target_species', e.id, NULL, _fetsi.target_species
FROM   _fetsi
JOIN   groomed.effort e ON e.trip = _fetsi.trip
AND    e.target_species IS NULL;

UPDATE groomed.effort
SET    checks = checks || '{FETSI}', target_species = x.new
FROM   groomed.checks x
WHERE  x.code = 'FETSI'
AND    groomed.effort.id = x.id;

$$ LANGUAGE SQL;
SELECT FETSI();
Effects of grooming
Figure 1: The number of records affected by the FETSI rule, by year and source.
Figure 2: The proportion of records affected by the FETSI rule, by form type, for all form types where some records are groomed by the FETSI rule.