R/dataset_checks.R
dataset_check_outlier_by_species.RdCompares each numeric value in a dataset with the values other datasets in a
compiled database report for the same taxon and trait, and lists those that
differ by at least min_fold-fold. The question it answers is whether a
value is plausible given everything else known about the species, which the
allowed range in traits.yml cannot: a seed mass of 0.005 mg is in range for
plants but not for an Angophora. This is a curation aid, not a test –
species do vary – but a value 10, 100 or 1000 times what everyone else
reports is most often a unit slip, a misplaced decimal point or a value
mapped to the wrong trait.
Compiled database object, e.g. austraits
dataset_id's to check. The default, NULL, checks every
dataset in the database against the rest.
Traits to check. The default, NULL, checks every numeric
trait that cannot be negative.
Values that differ from other_median by at least this
factor, in either direction, are listed in records. The default, 10,
catches unit slips while leaving most natural variation alone.
Minimum number of other datasets with values for the taxon and trait for a value to be compared. The default, 2, means a value is only flagged when it disagrees with the consensus of at least two other datasets, rather than with a single one that might be the one in error. Set it to 1 to also check taxa only one other dataset has measured.
List of groups of value_types to compare with each
other; see Details. A value whose value_type is in no group is not
checked.
A list of two tibbles:
summaryOne row per dataset, trait and group of value types with
values that could be compared, so a dataset or trait missing from it had
nothing to compare with. n_taxa and n_values count the taxa and values
compared, n_flagged the values listed in records, and median_ratio is
the median across taxa of each taxon's median ratio – far from 1 when
the whole trait is shifted. Sorted with the largest shifts first.
recordsThe values at least min_fold from other_median, with
ratio (value / other_median, so below 1 for a value lower than the
others) and fold_difference (the larger of ratio and 1 / ratio), the
range of the other datasets' values (other_min, other_max), how many
values and datasets they comprise, and the record's details. Sorted with
the largest fold_difference first.
How values are compared. Each value is compared with other_median, the
median, across the other datasets with values for that taxon and trait, of
each dataset's own median. Every other dataset gets one vote however many
values it holds, so a dataset of 30 individual measurements does not outvote
three datasets of one mean each – which matters when the 30 values are the
ones in error. The dataset being checked is never part of its own
comparison. Values are compared as ratios, value / other_median, since
errors such as unit slips are multiplicative and traits like seed mass vary
over orders of magnitude, so only numeric traits that cannot be negative
(allowed_values_min of 0 or more) are checked, and zeros are left out:
a fold-difference is undefined for them. Traits that can be negative, such
as water potentials and isotope ratios, are not checked.
Value types. Only values of compatible value_type are compared:
value_types lists the groups, and a value is compared only with values in
its own group. By default a minimum is compared only with other minima and a
maximum only with other maxima – comparing a flora's maximum height with
field means would flag every tall species – while mean, median, mode
and raw values, which all estimate a typical value, are compared with one
another. A value whose value_type is in no group, such as a bin, is not
checked. To compare them all together, pass
value_types = list(all = c("mean", "median", "mode", "raw", "minimum", "maximum"));
to check means alone, value_types = list("mean").
Other attributes of a value, such as life_stage and entity_type, are
not matched, and are returned so that a seedling measured against adults
can be recognised as such.
Reading the output. A value with a ratio near 1000 or 0.001 – or 100
or 10 for traits such as lengths recorded in mm, cm or m – is worth checking
first. A dataset whose values for a trait are all shifted, so that
median_ratio in summary is far from 1 across many taxa, is more likely to
have a unit or mapping error than one with a single flagged value. Traits
that vary widely within a species, such as bark_thickness (with stem size)
and plant_height (with age), produce the most flags that are not errors.
dataset_check_outlier_by_genus() to compare with the rest of the
genus, for taxa too few datasets have measured.
if (FALSE) { # \dontrun{
outliers <- dataset_check_outlier_by_species(austraits, "Ooi_2007")
outliers$summary
outliers$records
} # }