Last updated on 2025-12-20 17:50:45 CET.
| Flavor | Version | Tinstall | Tcheck | Ttotal | Status | Flags |
|---|---|---|---|---|---|---|
| r-devel-linux-x86_64-debian-clang | 0.3.1 | 5.49 | 46.84 | 52.33 | ERROR | |
| r-devel-linux-x86_64-debian-gcc | 0.3.1 | 3.88 | 35.02 | 38.90 | ERROR | |
| r-devel-linux-x86_64-fedora-clang | 0.3.1 | 10.00 | 73.28 | 83.28 | ERROR | |
| r-devel-linux-x86_64-fedora-gcc | 0.3.1 | 9.00 | 82.02 | 91.02 | ERROR | |
| r-devel-windows-x86_64 | 0.3.1 | 7.00 | 86.00 | 93.00 | OK | |
| r-patched-linux-x86_64 | 0.3.1 | 6.10 | 52.81 | 58.91 | OK | |
| r-release-linux-x86_64 | 0.3.1 | 4.54 | 53.00 | 57.54 | OK | |
| r-release-macos-arm64 | 0.3.1 | OK | ||||
| r-release-macos-x86_64 | 0.3.1 | 4.00 | 110.00 | 114.00 | OK | |
| r-release-windows-x86_64 | 0.3.1 | 8.00 | 94.00 | 102.00 | OK | |
| r-oldrel-macos-arm64 | 0.3.1 | NOTE | ||||
| r-oldrel-macos-x86_64 | 0.3.1 | 4.00 | 140.00 | 144.00 | NOTE | |
| r-oldrel-windows-x86_64 | 0.3.1 | 11.00 | 101.00 | 112.00 | NOTE |
Version: 0.3.1
Check: examples
Result: ERROR
Running examples in ‘triact-Ex.R’ failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: Triact
> ### Title: R6 class for analyzing accelerometer data from cows
> ### Aliases: Triact
>
> ### ** Examples
>
>
> ## Please read the "introduction" vignette for more detailed examples
>
> ## -------------------------
> # method '$new'
> ## -------------------------
>
> # create a Triact object
> my_triact <- Triact$new()
>
> ## -------------------------
> # method '$load_files'
> ## -------------------------
>
>
> ## -------------------------
> # method 'load_table'
> ## -------------------------
>
> # create a Triact object
> my_triact <- Triact$new()
>
> my_triact$load_table(cows_5hz)
>
> # inspect imported data
> head(my_triact$data)
id time acc_fwd acc_up acc_right
1 cow01 2021-06-29 06:00:00 0.048 1.032 0.063
2 cow01 2021-06-29 06:00:00 0.048 1.000 0.063
3 cow01 2021-06-29 06:00:00 0.048 1.000 0.063
4 cow01 2021-06-29 06:00:00 0.048 1.032 0.063
5 cow01 2021-06-29 06:00:00 0.048 1.032 0.031
6 cow01 2021-06-29 06:00:01 0.079 1.032 0.031
>
> ## -------------------------
> # method 'check_orientation'
> ## -------------------------
>
> my_triact$check_orientation()
This method checks for potential incorrect mounted accelerometers, rotated 180° in the sagital plane.
No incorrectly mounted accelerometers found.
>
> ## -------------------------
> # method 'add_lying'
> ## -------------------------
>
> my_triact$add_lying()
Error in `[.data.table`(private$dataDT, , `:=`(paste0("gravity_", axd), :
attempt access index 5/5 in VECTOR_ELT
Calls: <Anonymous> -> <Anonymous> -> [ -> [.data.table
Execution halted
Flavors: r-devel-linux-x86_64-debian-clang, r-devel-linux-x86_64-debian-gcc
Version: 0.3.1
Check: re-building of vignette outputs
Result: ERROR
Error(s) in re-building vignettes:
...
--- re-building ‘introduction.Rmd’ using rmarkdown
Triact package:triact R Documentation
_<08>R_<08>6 _<08>c_<08>l_<08>a_<08>s_<08>s _<08>f_<08>o_<08>r _<08>a_<08>n_<08>a_<08>l_<08>y_<08>z_<08>i_<08>n_<08>g _<08>a_<08>c_<08>c_<08>e_<08>l_<08>e_<08>r_<08>o_<08>m_<08>e_<08>t_<08>e_<08>r _<08>d_<08>a_<08>t_<08>a _<08>f_<08>r_<08>o_<08>m _<08>c_<08>o_<08>w_<08>s
_<08>D_<08>e_<08>s_<08>c_<08>r_<08>i_<08>p_<08>t_<08>i_<08>o_<08>n:
An object for containing and analyzing data from accelerometers
attached to a hind leg of cows. Analyses focus on the lying
behaviour and on the cows' level of physical activity as detailed
in Simmler & Brouwers (2024). For a usage example see
'vignette("introduction", package = "triact")'.
_<08>A_<08>c_<08>t_<08>i_<08>v_<08>e _<08>b_<08>i_<08>n_<08>d_<08>i_<08>n_<08>g_<08>s:
'data'
Raw accelerometer data and analysis results. Mainly modified
by $load_... and the $add_... methods
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d_<08>s:
_<08>P_<08>u_<08>b_<08>l_<08>i_<08>c _<08>m_<08>e_<08>t_<08>h_<08>o_<08>d_<08>s:
• 'Triact$new()'
• 'Triact$load_files()'
• 'Triact$load_table()'
• 'Triact$check_orientation()'
• 'Triact$add_lying()'
• 'Triact$add_side()'
• 'Triact$add_activity()'
• 'Triact$summarize_intervals()'
• 'Triact$summarize_bouts()'
• 'Triact$extract_liedown()'
• 'Triact$extract_standup()'
• 'Triact$clone()'
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>n_<08>e_<08>w()':
Create a new Triact object.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$new()
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
A new Triact object.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>l_<08>o_<08>a_<08>d__<08>f_<08>i_<08>l_<08>e_<08>s()':
Import acceleration data of one or multiple cows from
delimiter-separated text files into the Triact object. Importing
from multiple files from the same cows is possible but data
should follow each other without any gaps in time (overlap is
allowed as duplicates after concatenation will be removed). The
filenames must allow unique identification of the cow
(parameter: 'id_substring'). Accelerometer sampling frequency
must be consistent across the files. Acceleration should be in
units of _g_ and represent _proper acceleration_. Triaxial,
biaxial, and uniaxial accelerometer data are allowed, but only
triaxial data corresponding to relative body directions allows
full functionality.
_Important_: Make sure to correctly specify how to map the axes
as named by the accelerometer (e.g., x, y, z) to the body
relative axes as used in triact (parameter:
'timeFwdUpRight_cols'). For an example see
'vignette("introduction", package = "triact")'.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$load_files(
input,
id_substring,
timeFwdUpRight_cols,
time_format = NULL,
tz = Sys.timezone(),
skip = "__auto__",
sep = "auto",
header = "auto",
dec = ".",
start_time = NULL,
end_time = NULL,
parallel = 1,
...)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'input'
Specifies the input acceleration data files. Character
vector with the name(s) of the file(s) or a directory
containing the files (files can be in subdirectories). If
it does not contain absolute paths, the directory or file
name(s) are relative to the current working directory,
'getwd()'.
'id_substring'
Integer vector identifying the substring of the file names
representing the unique identifier of the cows by
character position: c(first, last), e.g, 'c(1, 5)' for
first to fifth character. Alternatively, a Perl-like
regular expression matching the substring.
'timeFwdUpRight_cols'
Integer vector specifying the columns containing the time,
and the forward, up, and right axis acceleration data:
c(time, fwd, up, right). Missing acceleration axes are
specified as 'NA'. A negative mathematical sign is used to
indicate that the recorded data reflects the opposite
direction (e.g., if you recorded backward acceleration,
specify the forward acceleration column with a negative
mathematical sign).
'time_format'
Character vector specifying the date-time format
corresponding to the acceleration files (syntax as in
'strptime'). If 'NULL' a date-time format as tried by
as.POSIX* is expected. _Default:_ 'NULL'
'tz'
Character vector specifying the time zone. _Default:_
'Sys.timezone()'
'skip'
An integer indicating the number of lines to skip before
starting the search for the first data line, which is the
first row with a consistent number of columns.
Alternatively, a (sub)string specifying the line at which
to start the search, or '"__auto__"' to leave the decision
to 'fread'. _Default:_ '"__auto__"'
'sep'
The separator between columns in the acceleration data
files. If '"auto"', it is automatically detected by
'fread' according to the character in the set [,\t |;:]
that separates the sample of rows into the most number of
lines with the same number of fields. _Default:_ '"auto"'
'header'
A logical value that indicates whether the first data line
(afer considering 'skip') contains column names.
Alternatively, '"auto"' to autmatically detect by 'fread'
according to whether every non-empty field on the first
data line is type character. _Default:_ '"auto"'
'dec'
The decimal separator as in 'fread'. _Default:_ '"."'
'start_time'
Time from which the data should be considered. Formatted
as "%Y-%m-%d %H:%M:%OS" or in another format automatically
tried by as.POSIX*. _Default:_ 'NULL'
'end_time'
Time up to which the data should be considered. Formatted
as "%Y-%m-%d %H:%M:%OS" or in another format automatically
tried by as.POSIX*. _Default:_ 'NULL'
'parallel'
An integer indicating the number of files that are read in
parallel. For 'parallel > 1' the reading of the individual
file is set to single-threaded to avoid nested
parallelization. This behavior can be overwritten by
additionally passing 'nThread' via '...' argument, which
is passed on to 'fread'. _Default:_ '1'
'...'
Further arguments passed to 'fread'.
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
Returns the Triact object itself, but modified by reference.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
input_dir <- system.file("extdata", package = "triact")
my_triact$load_files(input = input_dir,
id_substring = c(1, 5),
timeFwdUpRight_cols = c(1, -2, 3, -4),
skip = "DATA")
# inspect imported data
head(my_triact$data)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>l_<08>o_<08>a_<08>d__<08>t_<08>a_<08>b_<08>l_<08>e()':
Import acceleration data from a data.frame-like table (see
'cows_5hz' as an example). The table should contain the
following columns:
_colname_ _type_ _description_
id Factor unique id for the cow
time POSIXct timestamp
acc_fwd numeric acceleration from _forward_ axis (units: _g_)
acc_up numeric acceleration from _up_ axis (units: _g_)
acc_right numeric acceleration from _right_ axis (units: _g_)
The accelerometer sampling frequency must be the same across all
cows (id). No time gaps are allowed (within data of one id). One
or two of the acceleration columns may be missing, but the
possible analyses are then limited.
_Important_: Make sure the accelerometer axes correctly
represent body relative axes as used in triact (forward, up,
right). For an example see 'vignette("introduction", package =
"triact")'.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$load_table(table)
_<08>U_<08>s_<08>a_<08>g_<08>e (_<08>a_<08>l_<08>t_<08>e_<08>r_<08>n_<08>a_<08>t_<08>i_<08>v_<08>e _<08>s_<08>y_<08>n_<08>t_<08>a_<08>x):
Triact$data <- table
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'table'
Data frame-like table containing the data to import. Must
follow the requirements detailed in the description above.
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
Returns the Triact object itself, but modified by reference.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
# inspect imported data
head(my_triact$data)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>c_<08>h_<08>e_<08>c_<08>k__<08>o_<08>r_<08>i_<08>e_<08>n_<08>t_<08>a_<08>t_<08>i_<08>o_<08>n()':
Checks for each id (unique identifier of the cow) whether the
accelerometer may have been unintentionally mounted 180° rotated
in the sagittal plane to the hind leg. If identified as such,
the mathematical correction is applied, i.e. the forward and up
axes are negated (multiplied by -1), i.e. the axes are
mathematically rotated in order to comply with the orientation
as specified when loading in the data. The check is 'sum(acc_up
> crit) < sum(acc_up < (-1 * crit))' with 'crit = 0.5' by
default.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$check_orientation(crit = 0.5, interactive = TRUE)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'crit'
Critical value used in the check according to the
expression noted in the description above. _Default:_
'0.5'
'interactive'
A logical value that indicates whether the function should
interactively prompt the user before applying the
correction. _Default:_ 'TRUE'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
Returns the Triact object itself, but modified by reference.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
my_triact$check_orientation()
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>a_<08>d_<08>d__<08>l_<08>y_<08>i_<08>n_<08>g()':
Classify data into lying and standing and add results as column
'lying' to the Triact object. Additionally, lying and standing
bouts are uniquely numbered per id (cow) in column 'bout_nr'.
The simple rule-based algorithm is composed of three steps: In
the first step, the _up_ acceleration is filtered to obtain the
gravity component of the signal. In the second step, a threshold
is used to classify the (filtered) gravitational acceleration
into lying and standing. Finally, in the third step, lying bouts
shorter than a given minimum duration are reclassified as
standing. The last step can be performed analogous for standing
bouts, but is not recommended by default. See Simmler & Brouwers
(2024) for a detailed discussion.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$add_lying(
filter_method = "median",
crit_lie = 0.5,
minimum_duration_lying = 30,
minimum_duration_standing = NULL,
add_filtered = FALSE,
window_size = 10,
cutoff = 0.1,
order = 1)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'filter_method'
Filter method to be applied to obtain the gravity
component of the acceleration on the _up_ axis. Options
are '"median"', for median filter, and '"butter"' for a
bidirectional (zero-lag) Butterworth low-pass filter.
_Default:_ '"median"'
'crit_lie'
Threshold for classifying the gravitational acceleration
on _up_ axis into lying (below threshold) and standing
(above threshold). _Default:_ '0.5'
'minimum_duration_lying'
Minimum duration for lying bouts in seconds. Lying bouts
shorter than this threshold are considered false and
reclassified as standing. _Default:_ '30'
'minimum_duration_standing'
Minimum duration for standing bouts in seconds. Standing
bouts shorter than this threshold are considered false and
reclassified as lying. _Default:_ 'NULL'
'add_filtered'
Logical value that indicates whether the filtered gravity
component of the _up_ acceleration should be added to the
Triact object. _Default:_ 'FALSE'
'window_size'
Window size in seconds for filter method 'median'.
_Default:_ '10'
'cutoff'
Cutoff frequency for low-pass filtering in Hz for filter
method 'butter'. _Default:_ '0.1'
'order'
Filter order for filter method 'butter'. _Default:_ '1'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
Returns the Triact object itself, but modified by reference.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
my_triact$add_lying()
# inspect result
head(my_triact$data)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>a_<08>d_<08>d__<08>s_<08>i_<08>d_<08>e()':
Classify lying bouts into left and right lying side and add the
results as column 'side' to the Triact object. The simple
one-step algorithm determines whether the majority of the
_right_ acceleration values measured during that bout are above
(left lying side) or below (right lying side) a threshold. The
default threshold depends on which hind leg (left/right hind
leg) the accelerometer is attached to, taking into account the
asymmetry of the cow's natural lying position. See Simmler &
Brouwers (2024) for a detailed explanation.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$add_side(left_leg, crit_left = if (left_leg) 0.5 else -0.5)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'left_leg'
Logical indicating whether the accelerometers were
attached to the left hind leg ('TRUE') or to the right
hind leg ('FALSE'). This information is used to choose the
default value for 'crit_left'. It is ignored if
'crit_left' is specified by the user.
'crit_left'
Threshold for classifying lying on left versus right side
based on _right_ acceleration. _Default:_ '0.5' if
'left_leg' is 'TRUE', else '-0.5'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
Returns the Triact object itself, but modified by reference.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
my_triact$add_lying()
my_triact$add_side(left_leg = TRUE)
# inspect result
head(my_triact$data)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>a_<08>d_<08>d__<08>a_<08>c_<08>t_<08>i_<08>v_<08>i_<08>t_<08>y()':
Calculate proxies for the physical activity level. By default,
the L2 norm of the dynamic body acceleration (DBA) vector is
calculated. The corresponding L1 norm is optionally available.
Also, the L1 and L2 norms of the jerk vector can be calculated.
By default, all activity values during lying bouts are
'adjusted' to zero, i.e., periods when cows are lying are
considered as 'inactive' by definition. See Simmler & Brouwers
(2024) for details.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$add_activity(
dynamic_measure = "dba",
norm = "L2",
adjust = TRUE,
filter_method = "median",
keep_dynamic_measure = FALSE,
window_size = 10,
cutoff = 0.1,
order = 1)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'dynamic_measure'
Type of dynamic measure to base the activity proxy on.
Options are '"dba"', for dynamic body acceleration, and
'"jerk"', for the jerk vector. One or both can be
provided, e.g., '"dba"' or 'c("dba", "jerk")'. _Default:_
'"dba"'
'norm'
The type of norm to be calculated. Options are '"L1"' and
'"L2"'. One or both can be provided, e.g., '"L1"' or
'c("L1", "L2")'. _Default:_ '"L2"'
'adjust'
A logical value that indicates whether the proxies for
physical activity should be 'adjusted' to 0 during lying
bouts, i.e., whether cows should be considered as inactive
by definition when lying. _Default:_ 'TRUE'
'filter_method'
Filter method to be used to determine the gravity
component subtracted from the raw acceleration to obtain
the dynamic body acceleration. Options are '"median"', for
median filter, and '"butter"' for a bidirectional
(zero-lag) Butterworth low-pass filter. _Default:_
'"median"'
'keep_dynamic_measure'
A logical value that indicates whether the intermediate
data, being the dynamic body acceleration vector and/or
the jerk vector, should be added to the Triact object.
_Default:_ 'FALSE'
'window_size'
Window size in seconds for filter method 'median' used in
DBA-based proxies. _Default:_ '10'
'cutoff'
Cutoff frequency for low-pass filtering in Hz for filter
method 'butter' used in DBA-based proxies. _Default:_
'0.1'
'order'
Filter order for filter method 'butter' used in DBA-based
proxies. _Default:_ '1'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
Returns the Triact object itself, but modified by reference.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
my_triact$add_lying()
my_triact$add_activity()
# inspect result
head(my_triact$data)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>s_<08>u_<08>m_<08>m_<08>a_<08>r_<08>i_<08>z_<08>e__<08>i_<08>n_<08>t_<08>e_<08>r_<08>v_<08>a_<08>l_<08>s()':
Summarizes the data in the Triact object, activity and lying
behaviour, by regular intervals. The information contained in
the output table depends on the analyses you added to the Triact
object using the $add_activity(), $add_lying(), and $add_side()
methods. With 'bout = TRUE' information on bouts per interval
(number and mean bout duration) will be returned additionally.
With 'side = TRUE' summarized information such lying duration is
additionally provided separately for the lying side
(left/right). For measures such as the number of lying bouts or
mean lying bout duration, a weighted mean ('wMean...') is
calculated with the weights being the proportion of the
individual bout overlapping with the respective interval. See
interval_summary for a complete list of summarized measures and
Simmler & Brouwers (2024) for details.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$summarize_intervals(
interval = "hour",
lag_in_s = 0,
duration_units = "mins",
bouts = FALSE,
side = FALSE,
calc_for_incomplete = FALSE)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'interval'
Character string specifying the intervals to be analyzed.
Any unique English abbreviation valid for the 'unit'
argument of 'floor_date' is allowed, e.g., '"hour"',
'"min"', '"10 mins"', and '"0.5 hours"'. _Default:_
'"hour"'
'lag_in_s'
Lag in seconds with respect to the full hour or full day.
Determines the start of the intervals. _Default:_ '0'
'duration_units'
Unit in which durations should be returned. Options are
'"secs"', '"mins"' and '"hours"'. _Default:_ '"mins"'
'bouts'
Logical indicating whether information on bouts should be
additionally summarized. _Default:_ 'FALSE'
'side'
Logical indicating whether lying side should be considered
in the summary. _Default:_ 'FALSE'
'calc_for_incomplete'
Logical indicating whether a complete summary should also
be returned for the incompletely observed intervals (first
and last interval for each cow) and for any parameter
using information of incompletely observed bouts (first
and last bout for each cow). Please note that these are
ill-defined. _Default:_ 'FALSE'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
A table with summaries by interval (rows). See
interval_summary for a complete list.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
my_triact$add_lying()
int_summary <- my_triact$summarize_intervals()
# inspect result
head(int_summary)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>s_<08>u_<08>m_<08>m_<08>a_<08>r_<08>i_<08>z_<08>e__<08>b_<08>o_<08>u_<08>t_<08>s()':
Summarizes the data in the Triact object, activity and lying
behaviour, by lying/standing bouts. The information contained in
the output table depends on the analyses you added to the Triact
object using the $add_activity(), $add_lying(), and $add_side()
methods. See bout_summary for a complete list of summarized
measures and Simmler & Brouwers (2024) for details.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$summarize_bouts(
bout_type = "both",
duration_units = "mins",
calc_for_incomplete = FALSE)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'bout_type'
Type of bout to be considered. Options are '"both"',
'"lying"', and '"standing"'. _Default:_ '"both"'
'duration_units'
Units in which durations should be returned. Options are
'"secs"', '"mins"', and '"hours"'. _Default:_ '"mins"'
'calc_for_incomplete'
Logical indicating whether a complete summary should also
be returned for the incompletely observed bouts (first and
last bout for each cow). Please note that these are
ill-defined. _Default:_ 'FALSE'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
A table with summaries by bout (rows). See bout_summary for a
complete list.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
my_triact$add_lying()
bouts_summary <- my_triact$summarize_bouts()
# inspect result
head(bouts_summary)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>e_<08>x_<08>t_<08>r_<08>a_<08>c_<08>t__<08>l_<08>i_<08>e_<08>d_<08>o_<08>w_<08>n()':
Extracts data associated with liedown events (standing-to-lying
transitions). Operates in two modes, see _Returns_ section.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$extract_liedown(sec_before = 0, sec_after = 0)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'sec_before'
From how many seconds before the liedown events data
should be considered. _Default:_ '0'
'sec_after'
Up to how many seconds after the liedown events data
should be considered. _Default:_ '0'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
With default settings, a table with one entry per liedown
event, with timestamp and bout_nr of the lying bout, plus
lying side information (if available). With parameters
'sec_before' and/or 'sec_after' > 0, a list containing
individual tables per liedown event. These tables are extracts
of all data in the Triact object from within the defined time
window around the liedown events.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
my_triact$add_lying()
l_downs <- my_triact$extract_liedown()
# inspect result
print(l_downs)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>e_<08>x_<08>t_<08>r_<08>a_<08>c_<08>t__<08>s_<08>t_<08>a_<08>n_<08>d_<08>u_<08>p()':
Extracts data associated with standup events (lying-to-standing
transitions). Operates in two modes, see _Returns_ section.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$extract_standup(sec_before = 0, sec_after = 0)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'sec_before'
From how many seconds before the standup events data
should be considered. _Default:_ '0'
'sec_after'
Up to how many seconds after the standup events data
should be considered. _Default:_ '0'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
With default settings, a table with one entry per standup
event, with timestamp and bout_nr of the lying bout, plus
lying side information (if available). With parameters
'sec_before' and/or 'sec_after' > 0, a list containing
individual tables per standup event. These tables are extracts
of all data in the Triact object from within the defined time
window around the standup events.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
my_triact$add_lying()
st_ups <- my_triact$extract_standup()
# inspect result
print(st_ups)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>c_<08>l_<08>o_<08>n_<08>e()':
Copy a Triact object. By default a shallow copy is returned,
which does not completely copy the data contained in the Triact
object. For a complete copy use 'deep = TRUE'.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$clone(deep = FALSE)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'deep'
Whether to make a deep copy. _Default:_ 'FALSE'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
A copy of the Triact object.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
# create a complete copy
my_triact_cp = my_triact$clone(deep = TRUE)
_<08>R_<08>e_<08>f_<08>e_<08>r_<08>e_<08>n_<08>c_<08>e_<08>s:
Simmler. M., Brouwers S. P., 2024. _triact_ package for R:
Analyzing the lying behavior of cows from accelerometer data.
PeerJ, 12:e17036. doi:10.7717/peerj.17036
<https://doi.org/10.7717/peerj.17036>
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
## Please read the "introduction" vignette for more detailed examples
## -------------------------
# method '$new'
## -------------------------
# create a Triact object
my_triact <- Triact$new()
## -------------------------
# method '$load_files'
## -------------------------
# create a Triact object
my_triact <- Triact$new()
input_dir <- system.file("extdata", package = "triact")
my_triact$load_files(input = input_dir,
id_substring = c(1, 5),
timeFwdUpRight_cols = c(1, -2 ,3, -4),
skip = "DATA")
# inspect imported data
head(my_triact$data)
## -------------------------
# method 'load_table'
## -------------------------
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
# inspect imported data
head(my_triact$data)
## -------------------------
# method 'check_orientation'
## -------------------------
my_triact$check_orientation()
## -------------------------
# method 'add_lying'
## -------------------------
my_triact$add_lying()
# inspect result
head(my_triact$data)
## -------------------------
# method 'add_side'
## -------------------------
my_triact$add_side(left_leg = TRUE)
# inspect result
head(my_triact$data)
## -------------------------
# method 'add_activity'
## -------------------------
my_triact$add_activity()
# inspect result
head(my_triact$data)
## -------------------------
# method 'summarize_intervals'
## -------------------------
int_summary <- my_triact$summarize_intervals()
# inspect result
head(int_summary)
## -------------------------
# method 'summarize_bouts'
## -------------------------
bouts_summary <- my_triact$summarize_bouts()
# inspect result
head(bouts_summary)
## -------------------------
# method 'extract_liedown'
## -------------------------
l_downs <- my_triact$extract_liedown()
# inspect result
print(l_downs)
## -------------------------
# method 'extract_standup'
## -------------------------
st_ups <- my_triact$extract_standup()
# inspect result
print(st_ups)
## -------------------------
# method 'clone'
## -------------------------
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
# create a complete copy
my_triact_cp = my_triact$clone(deep = TRUE)
cows_5hz package:triact R Documentation
_<08>C_<08>o_<08>w _<08>a_<08>c_<08>c_<08>e_<08>l_<08>e_<08>r_<08>a_<08>t_<08>i_<08>o_<08>n _<08>d_<08>a_<08>t_<08>a
_<08>D_<08>e_<08>s_<08>c_<08>r_<08>i_<08>p_<08>t_<08>i_<08>o_<08>n:
Acceleration data collected with triaxial accelerometers (MSR145,
MSR Electronics, Switzerland) attached to the left hind leg of two
dairy cows (cow01, cow02). The accelerometer sampling frequency
was 5 Hz. The _forward_, _up_, and _right_ acceleration correspond
to body relative directions as used in _triact_ (see
'vignette("introduction", package = "triact")' and Simmler &
Brouwers, 2024).
_colname_ _type_ _description_
id Factor unique id for the cow
time POSIXct timestamp
acc_fwd numeric acceleration from _forward_ axis (units: _g_)
acc_up numeric acceleration from _up_ axis (units: _g_)
acc_right numeric acceleration from _right_ axis (units: _g_)
_<08>U_<08>s_<08>a_<08>g_<08>e:
cows_5hz
_<08>N_<08>o_<08>t_<08>e:
From the raw data files distributed with the triact package,
'cows_5hz' can be reproduced as follows:
# create a Triact object
my_triact <- Triact$new()
input_dir <- system.file("extdata", package = "triact")
# load data from files
# note the mapping of XYZ to forward, up, right (parameter timeFwdUpRight_cols)
my_triact$load_files(input = input_dir,
id_substring = c(1, 5),
timeFwdUpRight_cols = c(1, -2, 3, -4),
tz = "Europe/Zurich",
skip = "DATA")
cows_5hz_recreated <- my_triact$data
# test whether they are identical
identical(cows_5hz_recreated, cows_5hz)
_<08>S_<08>o_<08>u_<08>r_<08>c_<08>e:
Agroscope, 8356 Ettenhausen, Switzerland
_<08>R_<08>e_<08>f_<08>e_<08>r_<08>e_<08>n_<08>c_<08>e_<08>s:
Simmler. M., Brouwers S. P., 2024. _triact_ package for R:
Analyzing the lying behavior of cows from accelerometer data.
PeerJ, 12:e17036. doi:10.7717/peerj.17036
<https://doi.org/10.7717/peerj.17036>
Quitting from introduction.Rmd:232-234 [unnamed-chunk-16]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<error/rlang_error>
Error in `[.data.table`:
! attempt access index 5/5 in VECTOR_ELT
---
Backtrace:
▆
1. └─my_triact$add_lying()
2. └─private$filter_acc(...)
3. ├─...[]
4. └─data.table:::`[.data.table`(...)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: processing vignette 'introduction.Rmd' failed with diagnostics:
attempt access index 5/5 in VECTOR_ELT
--- failed re-building ‘introduction.Rmd’
SUMMARY: processing the following file failed:
‘introduction.Rmd’
Error: Vignette re-building failed.
Execution halted
Flavors: r-devel-linux-x86_64-debian-clang, r-devel-linux-x86_64-debian-gcc
Version: 0.3.1
Check: examples
Result: ERROR
Running examples in ‘triact-Ex.R’ failed
The error most likely occurred in:
> ### Name: Triact
> ### Title: R6 class for analyzing accelerometer data from cows
> ### Aliases: Triact
>
> ### ** Examples
>
>
> ## Please read the "introduction" vignette for more detailed examples
>
> ## -------------------------
> # method '$new'
> ## -------------------------
>
> # create a Triact object
> my_triact <- Triact$new()
>
> ## -------------------------
> # method '$load_files'
> ## -------------------------
>
>
> ## -------------------------
> # method 'load_table'
> ## -------------------------
>
> # create a Triact object
> my_triact <- Triact$new()
>
> my_triact$load_table(cows_5hz)
>
> # inspect imported data
> head(my_triact$data)
id time acc_fwd acc_up acc_right
1 cow01 2021-06-29 06:00:00 0.048 1.032 0.063
2 cow01 2021-06-29 06:00:00 0.048 1.000 0.063
3 cow01 2021-06-29 06:00:00 0.048 1.000 0.063
4 cow01 2021-06-29 06:00:00 0.048 1.032 0.063
5 cow01 2021-06-29 06:00:00 0.048 1.032 0.031
6 cow01 2021-06-29 06:00:01 0.079 1.032 0.031
>
> ## -------------------------
> # method 'check_orientation'
> ## -------------------------
>
> my_triact$check_orientation()
This method checks for potential incorrect mounted accelerometers, rotated 180° in the sagital plane.
No incorrectly mounted accelerometers found.
>
> ## -------------------------
> # method 'add_lying'
> ## -------------------------
>
> my_triact$add_lying()
Error in `[.data.table`(private$dataDT, , `:=`(paste0("gravity_", axd), :
attempt access index 5/5 in VECTOR_ELT
Calls: <Anonymous> -> <Anonymous> -> [ -> [.data.table
Execution halted
Flavors: r-devel-linux-x86_64-fedora-clang, r-devel-linux-x86_64-fedora-gcc
Version: 0.3.1
Check: re-building of vignette outputs
Result: ERROR
Error(s) in re-building vignettes:
--- re-building ‘introduction.Rmd’ using rmarkdown
Triact package:triact R Documentation
_<08>R_<08>6 _<08>c_<08>l_<08>a_<08>s_<08>s _<08>f_<08>o_<08>r _<08>a_<08>n_<08>a_<08>l_<08>y_<08>z_<08>i_<08>n_<08>g _<08>a_<08>c_<08>c_<08>e_<08>l_<08>e_<08>r_<08>o_<08>m_<08>e_<08>t_<08>e_<08>r _<08>d_<08>a_<08>t_<08>a _<08>f_<08>r_<08>o_<08>m _<08>c_<08>o_<08>w_<08>s
_<08>D_<08>e_<08>s_<08>c_<08>r_<08>i_<08>p_<08>t_<08>i_<08>o_<08>n:
An object for containing and analyzing data from accelerometers
attached to a hind leg of cows. Analyses focus on the lying
behaviour and on the cows' level of physical activity as detailed
in Simmler & Brouwers (2024). For a usage example see
'vignette("introduction", package = "triact")'.
_<08>A_<08>c_<08>t_<08>i_<08>v_<08>e _<08>b_<08>i_<08>n_<08>d_<08>i_<08>n_<08>g_<08>s:
'data'
Raw accelerometer data and analysis results. Mainly modified
by $load_... and the $add_... methods
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d_<08>s:
_<08>P_<08>u_<08>b_<08>l_<08>i_<08>c _<08>m_<08>e_<08>t_<08>h_<08>o_<08>d_<08>s:
• 'Triact$new()'
• 'Triact$load_files()'
• 'Triact$load_table()'
• 'Triact$check_orientation()'
• 'Triact$add_lying()'
• 'Triact$add_side()'
• 'Triact$add_activity()'
• 'Triact$summarize_intervals()'
• 'Triact$summarize_bouts()'
• 'Triact$extract_liedown()'
• 'Triact$extract_standup()'
• 'Triact$clone()'
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>n_<08>e_<08>w()':
Create a new Triact object.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$new()
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
A new Triact object.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>l_<08>o_<08>a_<08>d__<08>f_<08>i_<08>l_<08>e_<08>s()':
Import acceleration data of one or multiple cows from
delimiter-separated text files into the Triact object. Importing
from multiple files from the same cows is possible but data
should follow each other without any gaps in time (overlap is
allowed as duplicates after concatenation will be removed). The
filenames must allow unique identification of the cow
(parameter: 'id_substring'). Accelerometer sampling frequency
must be consistent across the files. Acceleration should be in
units of _g_ and represent _proper acceleration_. Triaxial,
biaxial, and uniaxial accelerometer data are allowed, but only
triaxial data corresponding to relative body directions allows
full functionality.
_Important_: Make sure to correctly specify how to map the axes
as named by the accelerometer (e.g., x, y, z) to the body
relative axes as used in triact (parameter:
'timeFwdUpRight_cols'). For an example see
'vignette("introduction", package = "triact")'.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$load_files(
input,
id_substring,
timeFwdUpRight_cols,
time_format = NULL,
tz = Sys.timezone(),
skip = "__auto__",
sep = "auto",
header = "auto",
dec = ".",
start_time = NULL,
end_time = NULL,
parallel = 1,
...)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'input'
Specifies the input acceleration data files. Character
vector with the name(s) of the file(s) or a directory
containing the files (files can be in subdirectories). If
it does not contain absolute paths, the directory or file
name(s) are relative to the current working directory,
'getwd()'.
'id_substring'
Integer vector identifying the substring of the file names
representing the unique identifier of the cows by
character position: c(first, last), e.g, 'c(1, 5)' for
first to fifth character. Alternatively, a Perl-like
regular expression matching the substring.
'timeFwdUpRight_cols'
Integer vector specifying the columns containing the time,
and the forward, up, and right axis acceleration data:
c(time, fwd, up, right). Missing acceleration axes are
specified as 'NA'. A negative mathematical sign is used to
indicate that the recorded data reflects the opposite
direction (e.g., if you recorded backward acceleration,
specify the forward acceleration column with a negative
mathematical sign).
'time_format'
Character vector specifying the date-time format
corresponding to the acceleration files (syntax as in
'strptime'). If 'NULL' a date-time format as tried by
as.POSIX* is expected. _Default:_ 'NULL'
'tz'
Character vector specifying the time zone. _Default:_
'Sys.timezone()'
'skip'
An integer indicating the number of lines to skip before
starting the search for the first data line, which is the
first row with a consistent number of columns.
Alternatively, a (sub)string specifying the line at which
to start the search, or '"__auto__"' to leave the decision
to 'fread'. _Default:_ '"__auto__"'
'sep'
The separator between columns in the acceleration data
files. If '"auto"', it is automatically detected by
'fread' according to the character in the set [,\t |;:]
that separates the sample of rows into the most number of
lines with the same number of fields. _Default:_ '"auto"'
'header'
A logical value that indicates whether the first data line
(afer considering 'skip') contains column names.
Alternatively, '"auto"' to autmatically detect by 'fread'
according to whether every non-empty field on the first
data line is type character. _Default:_ '"auto"'
'dec'
The decimal separator as in 'fread'. _Default:_ '"."'
'start_time'
Time from which the data should be considered. Formatted
as "%Y-%m-%d %H:%M:%OS" or in another format automatically
tried by as.POSIX*. _Default:_ 'NULL'
'end_time'
Time up to which the data should be considered. Formatted
as "%Y-%m-%d %H:%M:%OS" or in another format automatically
tried by as.POSIX*. _Default:_ 'NULL'
'parallel'
An integer indicating the number of files that are read in
parallel. For 'parallel > 1' the reading of the individual
file is set to single-threaded to avoid nested
parallelization. This behavior can be overwritten by
additionally passing 'nThread' via '...' argument, which
is passed on to 'fread'. _Default:_ '1'
'...'
Further arguments passed to 'fread'.
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
Returns the Triact object itself, but modified by reference.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
input_dir <- system.file("extdata", package = "triact")
my_triact$load_files(input = input_dir,
id_substring = c(1, 5),
timeFwdUpRight_cols = c(1, -2, 3, -4),
skip = "DATA")
# inspect imported data
head(my_triact$data)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>l_<08>o_<08>a_<08>d__<08>t_<08>a_<08>b_<08>l_<08>e()':
Import acceleration data from a data.frame-like table (see
'cows_5hz' as an example). The table should contain the
following columns:
_colname_ _type_ _description_
id Factor unique id for the cow
time POSIXct timestamp
acc_fwd numeric acceleration from _forward_ axis (units: _g_)
acc_up numeric acceleration from _up_ axis (units: _g_)
acc_right numeric acceleration from _right_ axis (units: _g_)
The accelerometer sampling frequency must be the same across all
cows (id). No time gaps are allowed (within data of one id). One
or two of the acceleration columns may be missing, but the
possible analyses are then limited.
_Important_: Make sure the accelerometer axes correctly
represent body relative axes as used in triact (forward, up,
right). For an example see 'vignette("introduction", package =
"triact")'.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$load_table(table)
_<08>U_<08>s_<08>a_<08>g_<08>e (_<08>a_<08>l_<08>t_<08>e_<08>r_<08>n_<08>a_<08>t_<08>i_<08>v_<08>e _<08>s_<08>y_<08>n_<08>t_<08>a_<08>x):
Triact$data <- table
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'table'
Data frame-like table containing the data to import. Must
follow the requirements detailed in the description above.
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
Returns the Triact object itself, but modified by reference.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
# inspect imported data
head(my_triact$data)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>c_<08>h_<08>e_<08>c_<08>k__<08>o_<08>r_<08>i_<08>e_<08>n_<08>t_<08>a_<08>t_<08>i_<08>o_<08>n()':
Checks for each id (unique identifier of the cow) whether the
accelerometer may have been unintentionally mounted 180° rotated
in the sagittal plane to the hind leg. If identified as such,
the mathematical correction is applied, i.e. the forward and up
axes are negated (multiplied by -1), i.e. the axes are
mathematically rotated in order to comply with the orientation
as specified when loading in the data. The check is 'sum(acc_up
> crit) < sum(acc_up < (-1 * crit))' with 'crit = 0.5' by
default.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$check_orientation(crit = 0.5, interactive = TRUE)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'crit'
Critical value used in the check according to the
expression noted in the description above. _Default:_
'0.5'
'interactive'
A logical value that indicates whether the function should
interactively prompt the user before applying the
correction. _Default:_ 'TRUE'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
Returns the Triact object itself, but modified by reference.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
my_triact$check_orientation()
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>a_<08>d_<08>d__<08>l_<08>y_<08>i_<08>n_<08>g()':
Classify data into lying and standing and add results as column
'lying' to the Triact object. Additionally, lying and standing
bouts are uniquely numbered per id (cow) in column 'bout_nr'.
The simple rule-based algorithm is composed of three steps: In
the first step, the _up_ acceleration is filtered to obtain the
gravity component of the signal. In the second step, a threshold
is used to classify the (filtered) gravitational acceleration
into lying and standing. Finally, in the third step, lying bouts
shorter than a given minimum duration are reclassified as
standing. The last step can be performed analogous for standing
bouts, but is not recommended by default. See Simmler & Brouwers
(2024) for a detailed discussion.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$add_lying(
filter_method = "median",
crit_lie = 0.5,
minimum_duration_lying = 30,
minimum_duration_standing = NULL,
add_filtered = FALSE,
window_size = 10,
cutoff = 0.1,
order = 1)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'filter_method'
Filter method to be applied to obtain the gravity
component of the acceleration on the _up_ axis. Options
are '"median"', for median filter, and '"butter"' for a
bidirectional (zero-lag) Butterworth low-pass filter.
_Default:_ '"median"'
'crit_lie'
Threshold for classifying the gravitational acceleration
on _up_ axis into lying (below threshold) and standing
(above threshold). _Default:_ '0.5'
'minimum_duration_lying'
Minimum duration for lying bouts in seconds. Lying bouts
shorter than this threshold are considered false and
reclassified as standing. _Default:_ '30'
'minimum_duration_standing'
Minimum duration for standing bouts in seconds. Standing
bouts shorter than this threshold are considered false and
reclassified as lying. _Default:_ 'NULL'
'add_filtered'
Logical value that indicates whether the filtered gravity
component of the _up_ acceleration should be added to the
Triact object. _Default:_ 'FALSE'
'window_size'
Window size in seconds for filter method 'median'.
_Default:_ '10'
'cutoff'
Cutoff frequency for low-pass filtering in Hz for filter
method 'butter'. _Default:_ '0.1'
'order'
Filter order for filter method 'butter'. _Default:_ '1'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
Returns the Triact object itself, but modified by reference.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
my_triact$add_lying()
# inspect result
head(my_triact$data)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>a_<08>d_<08>d__<08>s_<08>i_<08>d_<08>e()':
Classify lying bouts into left and right lying side and add the
results as column 'side' to the Triact object. The simple
one-step algorithm determines whether the majority of the
_right_ acceleration values measured during that bout are above
(left lying side) or below (right lying side) a threshold. The
default threshold depends on which hind leg (left/right hind
leg) the accelerometer is attached to, taking into account the
asymmetry of the cow's natural lying position. See Simmler &
Brouwers (2024) for a detailed explanation.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$add_side(left_leg, crit_left = if (left_leg) 0.5 else -0.5)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'left_leg'
Logical indicating whether the accelerometers were
attached to the left hind leg ('TRUE') or to the right
hind leg ('FALSE'). This information is used to choose the
default value for 'crit_left'. It is ignored if
'crit_left' is specified by the user.
'crit_left'
Threshold for classifying lying on left versus right side
based on _right_ acceleration. _Default:_ '0.5' if
'left_leg' is 'TRUE', else '-0.5'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
Returns the Triact object itself, but modified by reference.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
my_triact$add_lying()
my_triact$add_side(left_leg = TRUE)
# inspect result
head(my_triact$data)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>a_<08>d_<08>d__<08>a_<08>c_<08>t_<08>i_<08>v_<08>i_<08>t_<08>y()':
Calculate proxies for the physical activity level. By default,
the L2 norm of the dynamic body acceleration (DBA) vector is
calculated. The corresponding L1 norm is optionally available.
Also, the L1 and L2 norms of the jerk vector can be calculated.
By default, all activity values during lying bouts are
'adjusted' to zero, i.e., periods when cows are lying are
considered as 'inactive' by definition. See Simmler & Brouwers
(2024) for details.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$add_activity(
dynamic_measure = "dba",
norm = "L2",
adjust = TRUE,
filter_method = "median",
keep_dynamic_measure = FALSE,
window_size = 10,
cutoff = 0.1,
order = 1)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'dynamic_measure'
Type of dynamic measure to base the activity proxy on.
Options are '"dba"', for dynamic body acceleration, and
'"jerk"', for the jerk vector. One or both can be
provided, e.g., '"dba"' or 'c("dba", "jerk")'. _Default:_
'"dba"'
'norm'
The type of norm to be calculated. Options are '"L1"' and
'"L2"'. One or both can be provided, e.g., '"L1"' or
'c("L1", "L2")'. _Default:_ '"L2"'
'adjust'
A logical value that indicates whether the proxies for
physical activity should be 'adjusted' to 0 during lying
bouts, i.e., whether cows should be considered as inactive
by definition when lying. _Default:_ 'TRUE'
'filter_method'
Filter method to be used to determine the gravity
component subtracted from the raw acceleration to obtain
the dynamic body acceleration. Options are '"median"', for
median filter, and '"butter"' for a bidirectional
(zero-lag) Butterworth low-pass filter. _Default:_
'"median"'
'keep_dynamic_measure'
A logical value that indicates whether the intermediate
data, being the dynamic body acceleration vector and/or
the jerk vector, should be added to the Triact object.
_Default:_ 'FALSE'
'window_size'
Window size in seconds for filter method 'median' used in
DBA-based proxies. _Default:_ '10'
'cutoff'
Cutoff frequency for low-pass filtering in Hz for filter
method 'butter' used in DBA-based proxies. _Default:_
'0.1'
'order'
Filter order for filter method 'butter' used in DBA-based
proxies. _Default:_ '1'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
Returns the Triact object itself, but modified by reference.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
my_triact$add_lying()
my_triact$add_activity()
# inspect result
head(my_triact$data)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>s_<08>u_<08>m_<08>m_<08>a_<08>r_<08>i_<08>z_<08>e__<08>i_<08>n_<08>t_<08>e_<08>r_<08>v_<08>a_<08>l_<08>s()':
Summarizes the data in the Triact object, activity and lying
behaviour, by regular intervals. The information contained in
the output table depends on the analyses you added to the Triact
object using the $add_activity(), $add_lying(), and $add_side()
methods. With 'bout = TRUE' information on bouts per interval
(number and mean bout duration) will be returned additionally.
With 'side = TRUE' summarized information such lying duration is
additionally provided separately for the lying side
(left/right). For measures such as the number of lying bouts or
mean lying bout duration, a weighted mean ('wMean...') is
calculated with the weights being the proportion of the
individual bout overlapping with the respective interval. See
interval_summary for a complete list of summarized measures and
Simmler & Brouwers (2024) for details.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$summarize_intervals(
interval = "hour",
lag_in_s = 0,
duration_units = "mins",
bouts = FALSE,
side = FALSE,
calc_for_incomplete = FALSE)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'interval'
Character string specifying the intervals to be analyzed.
Any unique English abbreviation valid for the 'unit'
argument of 'floor_date' is allowed, e.g., '"hour"',
'"min"', '"10 mins"', and '"0.5 hours"'. _Default:_
'"hour"'
'lag_in_s'
Lag in seconds with respect to the full hour or full day.
Determines the start of the intervals. _Default:_ '0'
'duration_units'
Unit in which durations should be returned. Options are
'"secs"', '"mins"' and '"hours"'. _Default:_ '"mins"'
'bouts'
Logical indicating whether information on bouts should be
additionally summarized. _Default:_ 'FALSE'
'side'
Logical indicating whether lying side should be considered
in the summary. _Default:_ 'FALSE'
'calc_for_incomplete'
Logical indicating whether a complete summary should also
be returned for the incompletely observed intervals (first
and last interval for each cow) and for any parameter
using information of incompletely observed bouts (first
and last bout for each cow). Please note that these are
ill-defined. _Default:_ 'FALSE'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
A table with summaries by interval (rows). See
interval_summary for a complete list.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
my_triact$add_lying()
int_summary <- my_triact$summarize_intervals()
# inspect result
head(int_summary)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>s_<08>u_<08>m_<08>m_<08>a_<08>r_<08>i_<08>z_<08>e__<08>b_<08>o_<08>u_<08>t_<08>s()':
Summarizes the data in the Triact object, activity and lying
behaviour, by lying/standing bouts. The information contained in
the output table depends on the analyses you added to the Triact
object using the $add_activity(), $add_lying(), and $add_side()
methods. See bout_summary for a complete list of summarized
measures and Simmler & Brouwers (2024) for details.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$summarize_bouts(
bout_type = "both",
duration_units = "mins",
calc_for_incomplete = FALSE)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'bout_type'
Type of bout to be considered. Options are '"both"',
'"lying"', and '"standing"'. _Default:_ '"both"'
'duration_units'
Units in which durations should be returned. Options are
'"secs"', '"mins"', and '"hours"'. _Default:_ '"mins"'
'calc_for_incomplete'
Logical indicating whether a complete summary should also
be returned for the incompletely observed bouts (first and
last bout for each cow). Please note that these are
ill-defined. _Default:_ 'FALSE'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
A table with summaries by bout (rows). See bout_summary for a
complete list.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
my_triact$add_lying()
bouts_summary <- my_triact$summarize_bouts()
# inspect result
head(bouts_summary)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>e_<08>x_<08>t_<08>r_<08>a_<08>c_<08>t__<08>l_<08>i_<08>e_<08>d_<08>o_<08>w_<08>n()':
Extracts data associated with liedown events (standing-to-lying
transitions). Operates in two modes, see _Returns_ section.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$extract_liedown(sec_before = 0, sec_after = 0)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'sec_before'
From how many seconds before the liedown events data
should be considered. _Default:_ '0'
'sec_after'
Up to how many seconds after the liedown events data
should be considered. _Default:_ '0'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
With default settings, a table with one entry per liedown
event, with timestamp and bout_nr of the lying bout, plus
lying side information (if available). With parameters
'sec_before' and/or 'sec_after' > 0, a list containing
individual tables per liedown event. These tables are extracts
of all data in the Triact object from within the defined time
window around the liedown events.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
my_triact$add_lying()
l_downs <- my_triact$extract_liedown()
# inspect result
print(l_downs)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>e_<08>x_<08>t_<08>r_<08>a_<08>c_<08>t__<08>s_<08>t_<08>a_<08>n_<08>d_<08>u_<08>p()':
Extracts data associated with standup events (lying-to-standing
transitions). Operates in two modes, see _Returns_ section.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$extract_standup(sec_before = 0, sec_after = 0)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'sec_before'
From how many seconds before the standup events data
should be considered. _Default:_ '0'
'sec_after'
Up to how many seconds after the standup events data
should be considered. _Default:_ '0'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
With default settings, a table with one entry per standup
event, with timestamp and bout_nr of the lying bout, plus
lying side information (if available). With parameters
'sec_before' and/or 'sec_after' > 0, a list containing
individual tables per standup event. These tables are extracts
of all data in the Triact object from within the defined time
window around the standup events.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
my_triact$add_lying()
st_ups <- my_triact$extract_standup()
# inspect result
print(st_ups)
_<08>M_<08>e_<08>t_<08>h_<08>o_<08>d '_<08>c_<08>l_<08>o_<08>n_<08>e()':
Copy a Triact object. By default a shallow copy is returned,
which does not completely copy the data contained in the Triact
object. For a complete copy use 'deep = TRUE'.
_<08>U_<08>s_<08>a_<08>g_<08>e:
Triact$clone(deep = FALSE)
_<08>A_<08>r_<08>g_<08>u_<08>m_<08>e_<08>n_<08>t_<08>s:
'deep'
Whether to make a deep copy. _Default:_ 'FALSE'
_<08>R_<08>e_<08>t_<08>u_<08>r_<08>n_<08>s:
A copy of the Triact object.
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
# create a complete copy
my_triact_cp = my_triact$clone(deep = TRUE)
_<08>R_<08>e_<08>f_<08>e_<08>r_<08>e_<08>n_<08>c_<08>e_<08>s:
Simmler. M., Brouwers S. P., 2024. _triact_ package for R:
Analyzing the lying behavior of cows from accelerometer data.
PeerJ, 12:e17036. doi:10.7717/peerj.17036
<https://doi.org/10.7717/peerj.17036>
_<08>E_<08>x_<08>a_<08>m_<08>p_<08>l_<08>e_<08>s:
## Please read the "introduction" vignette for more detailed examples
## -------------------------
# method '$new'
## -------------------------
# create a Triact object
my_triact <- Triact$new()
## -------------------------
# method '$load_files'
## -------------------------
# create a Triact object
my_triact <- Triact$new()
input_dir <- system.file("extdata", package = "triact")
my_triact$load_files(input = input_dir,
id_substring = c(1, 5),
timeFwdUpRight_cols = c(1, -2 ,3, -4),
skip = "DATA")
# inspect imported data
head(my_triact$data)
## -------------------------
# method 'load_table'
## -------------------------
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
# inspect imported data
head(my_triact$data)
## -------------------------
# method 'check_orientation'
## -------------------------
my_triact$check_orientation()
## -------------------------
# method 'add_lying'
## -------------------------
my_triact$add_lying()
# inspect result
head(my_triact$data)
## -------------------------
# method 'add_side'
## -------------------------
my_triact$add_side(left_leg = TRUE)
# inspect result
head(my_triact$data)
## -------------------------
# method 'add_activity'
## -------------------------
my_triact$add_activity()
# inspect result
head(my_triact$data)
## -------------------------
# method 'summarize_intervals'
## -------------------------
int_summary <- my_triact$summarize_intervals()
# inspect result
head(int_summary)
## -------------------------
# method 'summarize_bouts'
## -------------------------
bouts_summary <- my_triact$summarize_bouts()
# inspect result
head(bouts_summary)
## -------------------------
# method 'extract_liedown'
## -------------------------
l_downs <- my_triact$extract_liedown()
# inspect result
print(l_downs)
## -------------------------
# method 'extract_standup'
## -------------------------
st_ups <- my_triact$extract_standup()
# inspect result
print(st_ups)
## -------------------------
# method 'clone'
## -------------------------
# create a Triact object
my_triact <- Triact$new()
my_triact$load_table(cows_5hz)
# create a complete copy
my_triact_cp = my_triact$clone(deep = TRUE)
cows_5hz package:triact R Documentation
_<08>C_<08>o_<08>w _<08>a_<08>c_<08>c_<08>e_<08>l_<08>e_<08>r_<08>a_<08>t_<08>i_<08>o_<08>n _<08>d_<08>a_<08>t_<08>a
_<08>D_<08>e_<08>s_<08>c_<08>r_<08>i_<08>p_<08>t_<08>i_<08>o_<08>n:
Acceleration data collected with triaxial accelerometers (MSR145,
MSR Electronics, Switzerland) attached to the left hind leg of two
dairy cows (cow01, cow02). The accelerometer sampling frequency
was 5 Hz. The _forward_, _up_, and _right_ acceleration correspond
to body relative directions as used in _triact_ (see
'vignette("introduction", package = "triact")' and Simmler &
Brouwers, 2024).
_colname_ _type_ _description_
id Factor unique id for the cow
time POSIXct timestamp
acc_fwd numeric acceleration from _forward_ axis (units: _g_)
acc_up numeric acceleration from _up_ axis (units: _g_)
acc_right numeric acceleration from _right_ axis (units: _g_)
_<08>U_<08>s_<08>a_<08>g_<08>e:
cows_5hz
_<08>N_<08>o_<08>t_<08>e:
From the raw data files distributed with the triact package,
'cows_5hz' can be reproduced as follows:
# create a Triact object
my_triact <- Triact$new()
input_dir <- system.file("extdata", package = "triact")
# load data from files
# note the mapping of XYZ to forward, up, right (parameter timeFwdUpRight_cols)
my_triact$load_files(input = input_dir,
id_substring = c(1, 5),
timeFwdUpRight_cols = c(1, -2, 3, -4),
tz = "Europe/Zurich",
skip = "DATA")
cows_5hz_recreated <- my_triact$data
# test whether they are identical
identical(cows_5hz_recreated, cows_5hz)
_<08>S_<08>o_<08>u_<08>r_<08>c_<08>e:
Agroscope, 8356 Ettenhausen, Switzerland
_<08>R_<08>e_<08>f_<08>e_<08>r_<08>e_<08>n_<08>c_<08>e_<08>s:
Simmler. M., Brouwers S. P., 2024. _triact_ package for R:
Analyzing the lying behavior of cows from accelerometer data.
PeerJ, 12:e17036. doi:10.7717/peerj.17036
<https://doi.org/10.7717/peerj.17036>
Quitting from introduction.Rmd:232-234 [unnamed-chunk-16]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<error/rlang_error>
Error in `[.data.table`:
! attempt access index 5/5 in VECTOR_ELT
---
Backtrace:
▆
1. └─my_triact$add_lying()
2. └─private$filter_acc(...)
3. ├─...[]
4. └─data.table:::`[.data.table`(...)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: processing vignette 'introduction.Rmd' failed with diagnostics:
attempt access index 5/5 in VECTOR_ELT
--- failed re-building ‘introduction.Rmd’
SUMMARY: processing the following file failed:
‘introduction.Rmd’
Error: Vignette re-building failed.
Execution halted
Flavors: r-devel-linux-x86_64-fedora-clang, r-devel-linux-x86_64-fedora-gcc
Version: 0.3.1
Check: installed package size
Result: NOTE
installed size is 17.7Mb
sub-directories of 1Mb or more:
data 1.3Mb
doc 1.3Mb
extdata 14.8Mb
Flavors: r-oldrel-macos-arm64, r-oldrel-macos-x86_64, r-oldrel-windows-x86_64