| Title: | Calculate Herd Lying Concordance Metrics |
|---|---|
| Description: | Calculates Herd Lying Concordance (HLC) metrics from individual animal lying-behaviour data. HLC is a continuous framework for quantifying group-level behavioural cohesion from between-animal dispersion within observation intervals. The package implements standard deviation, mean absolute deviation, interquartile range, and entropy formulations, lying-weighted extensions, threshold-based synchrony comparisons, temporal summaries, and descriptive method-ranking tools. The HLC formulations are introduced in this package; related approaches to cattle behavioural synchrony include Raussi et al. (2011) <doi:10.1017/S1751731110001928>, Kok et al. (2023) <doi:10.1016/j.applanim.2023.105906>, and the activity metric framework of van Dixhoorn et al. (2024) <doi:10.24072/pcjournal.489>. |
| Authors: | Guilherme Amorim Franchi [aut, cre, cph] (ORCID: <https://orcid.org/0000-0001-7653-6512>) |
| Maintainer: | Guilherme Amorim Franchi <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-07-23 15:45:31 UTC |
| Source: | https://github.com/cran/HLCtools |
Calculates Herd Lying Concordance (HLC) metrics from individual animal lying-time records. HLC is calculated within each group-time interval as one minus a normalised measure of between-animal dispersion.
calculate_hlc( data, group, animal, interval, lying, day = NULL, period = NULL, interval_min = 15, methods = c("sd", "mad", "iqr", "entropy"), lying_threshold = interval_min/2, sync_thresholds = c(0.6, 0.7, 0.8, 0.9), add_lying_weighted = TRUE )calculate_hlc( data, group, animal, interval, lying, day = NULL, period = NULL, interval_min = 15, methods = c("sd", "mad", "iqr", "entropy"), lying_threshold = interval_min/2, sync_thresholds = c(0.6, 0.7, 0.8, 0.9), add_lying_weighted = TRUE )
data |
A data frame containing individual animal behaviour records. |
group |
Column identifying the herd, treatment, pen, or group. |
animal |
Column identifying the individual animal. |
interval |
Column identifying the time interval within day. |
lying |
Column containing lying time within the interval, in minutes. |
day |
Optional column identifying day/date. |
period |
Optional column identifying a larger period, for example week. |
interval_min |
Length of the observation interval in minutes. Default is 15. |
methods |
Character vector of HLC methods to compute. Options are
|
lying_threshold |
Threshold in minutes used to define binary lying state
for entropy. Default is half of |
sync_thresholds |
Numeric vector of threshold synchrony cut-offs, expressed
as proportions. Default is |
add_lying_weighted |
Logical. If TRUE, adds lying-weighted HLC metrics. |
A tibble with one row per group-time interval.
data(example_lies) hlc_intervals <- calculate_hlc( data = example_lies, group = group, animal = cow, day = day, period = week, interval = time, lying = lying, interval_min = 15, methods = c("sd", "mad", "iqr", "entropy"), sync_thresholds = c(0.6, 0.7, 0.8, 0.9), add_lying_weighted = TRUE ) hlc_intervalsdata(example_lies) hlc_intervals <- calculate_hlc( data = example_lies, group = group, animal = cow, day = day, period = week, interval = time, lying = lying, interval_min = 15, methods = c("sd", "mad", "iqr", "entropy"), sync_thresholds = c(0.6, 0.7, 0.8, 0.9), add_lying_weighted = TRUE ) hlc_intervals
Summarises HLC metrics across available dispersion bases. This function helps users compare HLC implementations rather than automatically selecting a single best metric.
compare_hlc_methods(data, metrics = NULL)compare_hlc_methods(data, metrics = NULL)
data |
A data frame containing HLC summary columns. This can be daily, weekly, treatment-level, or another summarised object. |
metrics |
Optional character vector of HLC columns to compare. If |
A tibble with descriptive summaries for each available HLC method.
data(example_lies) hlc_intervals <- calculate_hlc( data = example_lies, group = group, animal = cow, day = day, period = week, interval = time, lying = lying ) hlc_daily <- summarise_hlc_daily( data = hlc_intervals, group = group, day = day, period = week ) compare_hlc_methods(hlc_daily)data(example_lies) hlc_intervals <- calculate_hlc( data = example_lies, group = group, animal = cow, day = day, period = week, interval = time, lying = lying ) hlc_daily <- summarise_hlc_daily( data = hlc_intervals, group = group, day = day, period = week ) compare_hlc_methods(hlc_daily)
A small synthetic dataset for demonstrating Herd Lying Concordance calculations. The dataset contains individual animal lying times for two groups, two days, two time intervals per day, and five cows per group-time interval.
example_liesexample_lies
A data frame with 40 rows and 6 columns:
Group identifier.
Day identifier.
Week identifier.
Time interval identifier.
Individual cow identifier.
Lying time within the interval, in minutes.
data(example_lies) hlc_intervals <- calculate_hlc( data = example_lies, group = group, animal = cow, day = day, period = week, interval = time, lying = lying ) hlc_intervalsdata(example_lies) hlc_intervals <- calculate_hlc( data = example_lies, group = group, animal = cow, day = day, period = week, interval = time, lying = lying ) hlc_intervals
Returns the currently implemented unweighted Herd Lying Concordance dispersion bases.
hlc_methods()hlc_methods()
A character vector of available unweighted method names.
Returns the names of the currently implemented lying-weighted Herd Lying Concordance methods.
hlc_weighted_methods()hlc_weighted_methods()
A character vector containing the available lying-weighted HLC method names.
hlc_weighted_methods()hlc_weighted_methods()
Ranks available Herd Lying Concordance (HLC) implementations using descriptive criteria relevant for method selection. The function supports daily, weekly, treatment-level, or other summarised HLC outputs.
rank_hlc_methods( data, group = NULL, period = NULL, lying_prop = NULL, metrics = NULL, weights = c(detectability = 1, temporal_stability = 1, outlier_robustness = 1, boundary = 1, missingness = 1, degeneracy = 1) )rank_hlc_methods( data, group = NULL, period = NULL, lying_prop = NULL, metrics = NULL, weights = c(detectability = 1, temporal_stability = 1, outlier_robustness = 1, boundary = 1, missingness = 1, degeneracy = 1) )
data |
A data frame containing HLC summary columns. |
group |
Optional column identifying treatment, herd, pen, farm, or another comparison group. If supplied, group detectability is evaluated. |
period |
Optional column identifying week, period, block, or another temporal unit. If supplied, temporal stability is evaluated. |
lying_prop |
Optional column containing lying proportion. If supplied, Spearman correlation between each HLC method and lying proportion is reported. |
metrics |
Optional character vector of HLC columns to rank. If |
weights |
Named numeric vector giving weights for ranking criteria.
Supported names are |
The ranking is intended to support transparent, dataset-specific selection of an HLC implementation. It does not imply that one dispersion basis is universally best.
Ranking criteria:
detectability: group separation, based on an F statistic from nested
linear models when group is supplied.
temporal_stability: SD of period-level means when period is supplied.
outlier_robustness: absolute distance of SD/MAD from 1.
boundary: percentage of exact 0 or 1 values.
missingness: percentage of missing values.
degeneracy: penalises metrics with zero variance or very high boundary
collapse.
Criteria that cannot be evaluated because the required columns were not supplied are omitted from the weighted score. Metrics with missing values for an otherwise available criterion are ranked last for that criterion.
A tibble summarising method performance and ranking. Lower
weighted_rank_score indicates a more favourable method under the chosen
criteria. The column selected marks the top-ranked method.
data(example_lies) hlc_intervals <- calculate_hlc( data = example_lies, group = group, animal = cow, day = day, period = week, interval = time, lying = lying ) hlc_daily <- summarise_hlc_daily( data = hlc_intervals, group = group, day = day, period = week ) rank_hlc_methods( data = hlc_daily, group = group, period = week, lying_prop = mean_lying_prop )data(example_lies) hlc_intervals <- calculate_hlc( data = example_lies, group = group, animal = cow, day = day, period = week, interval = time, lying = lying ) hlc_daily <- summarise_hlc_daily( data = hlc_intervals, group = group, day = day, period = week ) rank_hlc_methods( data = hlc_daily, group = group, period = week, lying_prop = mean_lying_prop )
Aggregates interval-level HLC metrics into daily group-level summaries.
summarise_hlc_daily(data, group, day, period = NULL, interval_min = 15)summarise_hlc_daily(data, group, day, period = NULL, interval_min = 15)
data |
Interval-level HLC data produced by |
group |
Column identifying herd, treatment, pen, or group. |
day |
Column identifying day/date. |
period |
Optional column identifying a larger period, for example week. |
interval_min |
Length of the observation interval in minutes. Default is 15. |
A tibble with daily HLC summaries.
data(example_lies) hlc_intervals <- calculate_hlc( data = example_lies, group = group, animal = cow, day = day, period = week, interval = time, lying = lying, interval_min = 15 ) hlc_daily <- summarise_hlc_daily( data = hlc_intervals, group = group, day = day, period = week, interval_min = 15 ) hlc_dailydata(example_lies) hlc_intervals <- calculate_hlc( data = example_lies, group = group, animal = cow, day = day, period = week, interval = time, lying = lying, interval_min = 15 ) hlc_daily <- summarise_hlc_daily( data = hlc_intervals, group = group, day = day, period = week, interval_min = 15 ) hlc_daily