Skip to main page content
U.S. flag

An official website of the United States government

Dot gov

The .gov means it’s official.
Federal government websites often end in .gov or .mil. Before sharing sensitive information, make sure you’re on a federal government site.

Https

The site is secure.
The https:// ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.

Access keys NCBI Homepage MyNCBI Homepage Main Content Main Navigation
. 2024 Feb 28:12:e17036.
doi: 10.7717/peerj.17036. eCollection 2024.

triact package for R: analyzing the lying behavior of cows from accelerometer data

Affiliations

triact package for R: analyzing the lying behavior of cows from accelerometer data

Michael Simmler et al. PeerJ. .

Abstract

Accelerometers are sensors proven to be useful to analyze the lying behavior of cows. For reasons of algorithm transparency and control, researchers often prefer to use their own data analysis scripts rather than proprietary software. We developed the triact R package that assists animal scientists in analyzing the lying behavior of cows from raw data recorded with a triaxial accelerometer (manufacturer agnostic) attached to a hind leg. In a user-friendly workflow, triact allows the determination of common measures for lying behavior including total lying duration, the number of lying bouts, and the mean duration of lying bouts. Further capabilities are the description of lying laterality and the calculation of proxies for the level of physical activity of the cow. In this publication we describe the functionality of triact and the rationales behind the implemented algorithms. The triact R package is developed as an open-source project and freely available via the CRAN repository.

Keywords: Activity; Animal welfare; Cattle; Sensor.

PubMed Disclaimer

Conflict of interest statement

The authors declare that they have no competing interests.

Figures

Figure 1
Figure 1. Natural lying positions of cows. Reproduced from Schnitzer (1971) with permission of KTBL.
Figure 2
Figure 2. Definition of directions.
(A) Body relative directions. (B) The directions as used in triact, corresponding to body relative directions when the cow is standing. Depicted is what the situation looks like when the accelerometer is mounted on the outside of the left hind leg (or on the inside of the right hind leg). Silhouette of the cow from Vecteezy.com. Silhouette of the cow leg reproduced from Hendriks et al. (2020a) with permission of Elsevier.
Figure 3
Figure 3. Schematic overview of the workflow enabled by methods and fields of the Triact R6 class.
Prefixes in method names indicate their role in the workflow. The code in this figure is executable if you follow the flow as indicated in the flowchart. However, it is intended to provide an overview of the workflow rather than to teach the use of the R package. For the latter, we have written a vignette that is distributed with the R package (https://cran.r-project.org/web/packages/triact/vignettes/introduction.html).
Figure 4
Figure 4. Determination of standing and lying posture and lying laterality.
(A) Results on standing and lying posture and lying laterality (left L, right R) as determined with triact. (B) Acceleration as measured on the upward axis (up) with median filtered data and critical lying threshold indicated as dashed horizontal line. (C) Acceleration as measured on the right axis with threshold for determining lying side indicated as dashed horizontal line. Data obtained at 20 Hz sampling frequency with a triaxial accelerometer mounted on the left hind leg of a dairy cow.
Figure 5
Figure 5. Observed gravitational acceleration as a function of the angle of the hind leg.
(A) The angle between the upward axis (blue arrow) and the vertical as a function of the static gravitational acceleration on the upward axis (formula given in figure). The dashed line indicates the threshold used in triact to discriminate between standing and lying posture. (B) Trigonometric visualization of the calculation of the critical angle of 60° from the threshold that is crit_lie = 0.5 g. The gravitational acceleration is directed skywards as the accelerometer measures proper acceleration (see Introduction). Silhouette of the cow leg reproduced from Hendriks et al. (2020a) with permission of Elsevier.
Figure 6
Figure 6. Level of physical activity of a cow as determined with triact.
L2DBA represents the L2 norm of the dynamic body acceleration. “Adjusted” refers to setting the value for the activity level to 0 for the lying periods, which are by definition considered as the “inactive” periods. The underlying acceleration data is shown in Fig. 3 (apart from the forward axis). Data obtained at 20 Hz sampling frequency with a triaxial accelerometer mounted on the left hind leg of a dairy cow.

Similar articles

Cited by

References

    1. Bayat A, Pomplun M, Tran DA. A study on human activity recognition using accelerometer data from smartphones. Procedia Computer Science. 2014;34:450–457. doi: 10.1016/j.procs.2014.07.009. - DOI
    1. Beaver A, Weary DM, von Keyserlingk MAG. Invited review: the welfare of dairy cattle housed in tiestalls compared to less-restrictive housing types: a systematic review. Journal of Dairy Science. 2021;104(9):9383–9417. doi: 10.3168/jds.2020-19609. - DOI - PubMed
    1. Brouwers SP, Simmler M, Savary P, Scriba MF. Towards a novel method for detecting atypical lying down and standing up behaviors in dairy cows using accelerometers and machine learning. Smart Agricultural Technology. 2023;4(5):100199. doi: 10.1016/j.atech.2023.100199. - DOI
    1. Chang W. R6: encapsulated classes with reference semantics. 2022. https://r6.r-lib.org/ https://r6.r-lib.org/
    1. Dittrich I, Gertz M, Krieter J. Alterations in sick dairy cows’ daily behavioural patterns. Heliyon. 2019;5(11):e02902. doi: 10.1016/j.heliyon.2019.e02902. - DOI - PMC - PubMed

Grants and funding

This publication benefitted from financial support provided by the Federal Food Safety and Veterinary Office on behalf of the Swiss government (grant number: 2.21.01). The funders had no role in study design, data collection and analysis, decision to publish, or preparation of the manuscript.

LinkOut - more resources