| Type: | Package |
| Title: | Apply Sojourn Methods for Processing ActiGraph Accelerometer Data |
| Version: | 1.2.1 |
| Depends: | R (≥ 3.1.0) |
| Description: | Provides a simple way for utilizing Sojourn methods for accelerometer processing, as detailed in Lyden K, Keadle S, Staudenmayer J, & Freedson P (2014) <doi:10.1249/MSS.0b013e3182a42a2d>, Ellingson LD, Schwabacher IJ, Kim Y, Welk GJ, & Cook DB (2016) <doi:10.1249/MSS.0000000000000915>, and Hibbing PR, Ellingson LD, Dixon PM, & Welk GJ (2018) <doi:10.1249/MSS.0000000000001486>. |
| License: | GPL-3 |
| Encoding: | UTF-8 |
| LazyData: | true |
| Imports: | dplyr (≥ 0.7), magrittr (≥ 1.5), lubridate (≥ 1.7.4), nnet (≥ 7.3), PAutilities (≥ 0.2.0), rlang (≥ 0.2), stats, svDialogs (≥ 1.0), utils, zoo (≥ 1.8) |
| RoxygenNote: | 7.1.2 |
| URL: | https://github.com/paulhibbing/Sojourn |
| BugReports: | https://github.com/paulhibbing/Sojourn/issues |
| Suggests: | data.table, testthat |
| NeedsCompilation: | no |
| Packaged: | 2025-11-15 12:21:48 UTC; paulh |
| Author: | Paul R. Hibbing [aut, cre], Kate Lyden [aut], Isaac J. Schwabacher [aut] |
| Maintainer: | Paul R. Hibbing <paulhibbing@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2025-11-19 19:50:19 UTC |
Zero crossings for ActiGraph data
Description
Zero crossings for ActiGraph data
Usage
AG_zero_cross(data)
Arguments
data |
the data to analyze for zero crossings |
Calculate proportion of zeroes in a data stream
Description
Calculate proportion of zeroes in a data stream
Usage
AG_zero_prop(data)
Arguments
data |
the data stream to analyze |
ActiGraph sample data for exploring Sojourns Including Posture (SIP) method.
Description
ActiGraph sample data for exploring Sojourns Including Posture (SIP) method.
Usage
SIP_ag
Format
A data frame with 12257 rows and 5 variables:
- counts
Activity counts from the first axis
- axis2
Activity counts from the second axis
- axis3
Activity counts from the third axis
- vm
Vector magnitude of activity counts
- Time
POSIX-formatted variable giving the timestamp for each observation
activPAL sample data for exploring Sojourns Including Posture (SIP) method
Description
activPAL sample data for exploring Sojourns Including Posture (SIP) method
Usage
SIP_ap
Format
A data frame with 12257 rows and 5 variables:
- Time
POSIX-formatted variable giving the timestamp for each observation
- DataCount
Integer value giving the index of the sample from which the row of data is drawn
- Interval
Duration (in seconds) of the interval from one data point to the next
- ActivityCode
Integer giving the posture activity classification: 0 is sedentary, 1 is standing, and 2 is stepping
- CumulativeStepCount
Integer giving the cumulative step count from the start of the file to the current data point.
- ActivityScore
Numeric giving MET-hours
Check the formatting of a data frame for use in the SIP pipeline
Description
Check the formatting of a data frame for use in the SIP pipeline
Usage
SIP_frame_test(frame, expected_var_names, expected_classes, verbose)
Arguments
frame |
The data frame to check |
expected_var_names |
character vector. The expected variable names in
|
expected_classes |
character vector. The expected variable classes in
|
verbose |
logical. Print information to console? |
Sojourn: Apply Sojourn Methods for Processing ActiGraph Accelerometer Data
Description
The Sojourn package provides a convenient way to apply the family of Sojourn methods published in previous works including Lyden K, Keadle S, Staudenmayer J, & Freedson P (2014) <doi:10.1249/MSS.0b013e3182a42a2d>, Ellingson LD, Schwabacher IJ, Kim Y, Welk GJ, & Cook DB (2016) <doi:10.1249/MSS.0000000000000915>, and Hibbing PR, Ellingson LD, Dixon PM, & Welk GJ (2018) <doi:10.1249/MSS.0000000000001486>.
Details
It is meant for use with data from ActiGraph monitors and (in the case of Sojourns Including Posture, by Ellingson et al. (2016)) activPAL monitors. File reading is not included in the functionality of the Sojourn package. For help with that preliminary step, users are directed to the packages AGread (for ActiGraph files) and activpalProcessing (for activPAL files).
Compute lag-one autocorrelation
Description
Compute lag-one autocorrelation
Usage
acf.lag1(x)
Arguments
x |
numeric vector for the computation |
Value
a numeric scalar giving the lag-one autocorrelation
Alternate lag-1 autocorrelation function
Description
This function is used to compute lag-1 autocorrelation for the SIP method
Usage
acf.lag1.alt(x)
Arguments
x |
numeric vector for the computation |
Apply the youth Sojourn method
Description
Function for using the youth Sojourn method developed by Hibbing et al. (2018)
Usage
apply_youth_sojourn(
AG,
vm = c("Vector.Magnitude", "ENMO"),
Site = c("Hip", "Wrist"),
demo_interactive = FALSE,
verbose = FALSE,
...
)
Arguments
AG |
a data frame of monitor and demographic data |
vm |
the variable to use for processing, either
|
Site |
the wear location of the monitor, either |
demo_interactive |
logical. Input demographics interactively if missing variables are identified during format checking? |
verbose |
logical. Print processing updates to the console? |
... |
Further arguments passed to |
Value
The original data frame, plus additional predictions made by the Sojourn method
Note
The functions AGread::read_AG_counts and
AGread::read_AG_raw are recommended for assembling the
monitor-specific portion of the AG data frame.
Examples
data(example_data, package = "Sojourn")
results_youth_soj <- apply_youth_sojourn(
AG = example_data,
vm = "Vector.Magnitude",
Site = "Hip"
)
utils::head(results_youth_soj)
Combine short Sojourns
Description
Iteratively combine sojourns that are too short, until all Sojourns meet the minimum length requirement
Usage
combine_soj3x(durations, short, sojourns, verbose)
combine.sojourns(durations, short)
Arguments
durations |
durations of a set of Sojourns |
short |
minimum length of one Sojourn |
sojourns |
vector of Sojourn assignments |
verbose |
logical. Print updates to console? |
Summarize outcomes from data processed using the Sojourn method
Description
A function to summarize predictions made by the original Sojourn method of Lyden et al. (2014).
Usage
compute.bouts.info(est.mets, units = c("secs", "mins"))
Arguments
est.mets |
numeric vector of predicted metabolic equivalents |
units |
time units associated with each row of data |
Value
a data frame summarizing the predictions made by the Sojourn method.
Examples
data(example_data, package = "Sojourn")
example_data <- soj_3x_original(
example_data$axis1,
example_data$axis2,
example_data$axis3,
example_data$Vector.Magnitude
)
compute.bouts.info(example_data$METs)
Combine ActiGraph and activPAL data
Description
Merge data streams for separate monitors in the SIP method
Usage
enhance_actigraph(ag, ap, verbose = FALSE)
Arguments
ag |
ActiGraph data |
ap |
activPAL data |
verbose |
logical. Print information to console? |
Value
data frame of combined ActiGraph and activPAL data
Examples
data(SIP_ag, package = "Sojourn")
data(SIP_ap, package = "Sojourn")
combined_data <- enhance_actigraph(SIP_ag, SIP_ap)
utils::head(combined_data)
Sample data for exploring original and youth Sojourn methods
Description
Sample data for exploring original and youth Sojourn methods
Usage
example_data
Format
A data frame with 79989 rows and 11 variables:
- id
An example ID for the data set
- Sex
An example sex for the data set
- Age
An example age (in years) for the data set
- BMI
An example body mass index (in kg/m^2) for the data set
- Timestamp
POSIX-formatted variable giving the timestamp for each observation
- axis1
Activity counts from the first axis
- axis2
Activity counts from the second axis
- axis3
Activity counts from the third axis
- Vector.Magnitude
Vector magnitude of activity counts (sqrt(sum(axis1^2, axis2^2, axis3^2)))
- steps
Predicted steps taken
- incline
Inclinometer status (0 = off, 1 = lying, 2 = sitting, 3 = standing)
Find transitions
Description
Examine a data stream for qualifying transitions according to the SIP method
Usage
find.transitions(y)
Arguments
y |
the data stream to examine |
Label Sojourns in a data stream according to the youth-specific algorithm
Description
Identify Sojourns using the algorithm of Hibbing et al. (2018)
Usage
get_youth_sojourns(
vm,
short = 30,
Output = c("Counts", "Raw"),
Site = c("Hip", "Wrist"),
epoch = 1,
difference = 15,
threshold = 100,
verbose = FALSE
)
Arguments
vm |
vector of triaxial accelerometer values, either the vector magnitude for activity counts, or the Euclidian Norm Minus One for raw acceleration |
short |
numeric scalar. Shortest allowable duration for a Sojourn. Should be detected automatically from the internally-stored grid search values for the attachment site (hip or wrist) and data type (counts or raw) |
Output |
the data type (counts or raw) |
Site |
the attachment site (hip or wrist) |
epoch |
the epoch length, in seconds |
difference |
the difference parameter |
threshold |
the threshold parameter |
verbose |
logical. Print processing updates to the console? |
Value
A data frame (with nrow equal to length(vm)) that gives
sojourn labels and durations
Examples
data(example_data, package = "Sojourn")
get_youth_sojourns(example_data$Vector.Magnitude,
Output = "Counts", Site = "Hip")
Interactively input demographic information
Description
Interactively input demographic information
Usage
input_demographic(...)
Arguments
... |
Further arguments passed to svDialogs functions |
Value
A data frame containing an ID, attachment site of the monitor (hip or wrist), and the participant's sex, age, and BMI
Examples
if (interactive()) {
input_demographic()
}
Function for tidy assembly of text for printing in the console
Description
Function for tidy assembly of text for printing in the console
Usage
messager(n, theGrid = NULL, id = "`Unspecified ID`")
Arguments
n |
message number to assemble and return |
theGrid |
a grid entry from the package's internal data |
id |
character scalar giving the participant ID to print |
Value
text to print to the console
Shape data for input into the neural networks
Description
Prepare data for use in the neural networks of the SIP method
Usage
prep.nnetinputs(ag, sojourns, lag.fun)
Arguments
ag |
ActiGraph and activPAL combined data |
sojourns |
the Sojourns identified on the data |
lag.fun |
function to use for autocorrelations |
Prepare ActiGraph data for entry into the Sojourn neural network
Description
Prepare ActiGraph data for entry into the Sojourn neural network
Usage
prep_nnet_soj3x_original(
df,
variable = c("counts", "counts.2", "counts.3", "vect.mag"),
suffix = ""
)
Arguments
df |
The ActiGraph data |
variable |
The variable to prepare |
Read an activPAL events file
Description
Read an activPAL events file
Usage
read_AP(filename, tz = "UTC")
Arguments
filename |
character. Path to the file |
tz |
character. The timezone to use |
Value
Data frame reflecting the data contained in filename.
Note
There must be a corresponding .def file located in the same
directory as filename
Examples
ap_file <- system.file(
"extdata/sampledata_Events.csv",
package = "Sojourn"
)
if (isTRUE(requireNamespace("data.table"))) {
ap_data <- read_AP(ap_file)
utils::head(ap_data)
}
Perform mean imputation
Description
This function is used to perform mean imputation for the SIP method
Usage
replace.na(x)
Arguments
x |
data on which to perform the imputation |
Invoke the original uni-axial Sojourn method
Description
Calls the uni-axial Sojourn method from Lyden et al. (2014).
Usage
soj_1x_original(
counts,
perc.cut = 0.05,
perc.cut.2 = 0.12,
perc.cut.3 = 0.55,
too.short = 10,
sit.cut = 90,
long.soj = 120
)
Arguments
counts |
numeric vector of vertical axis counts |
perc.cut |
decision tree threshold 1 |
perc.cut.2 |
decision tree threshold 2 |
perc.cut.3 |
decision tree threshold 3 |
too.short |
minimum length of one Sojourn |
sit.cut |
cut-point for determining sitting |
long.soj |
maximum length of one Sojourn |
Value
a data frame of processed data
Examples
data(example_data, package = "Sojourn")
results_1x <- soj_1x_original(example_data$axis1)
utils::head(results_1x)
Invoke the original triaxial Sojourn method
Description
Calls the triaxial Sojourn method from Lyden et al. (2014).
Usage
soj_3x_original(
counts,
counts.2,
counts.3,
vect.mag,
short = 30,
verbose = FALSE
)
Arguments
counts |
numeric vector of activity counts from the first axis |
counts.2 |
numeric vector of activity counts from the second axis |
counts.3 |
numeric vector of activity counts from the third axis |
vect.mag |
vector magnitude of the activity counts |
short |
minimum length of one Sojourn |
verbose |
logical. Print updates to console? |
Value
a data frame of processed data
Examples
data(example_data, package = "Sojourn")
results_3x <- soj_3x_original(
example_data$axis1,
example_data$axis2,
example_data$axis3,
example_data$Vector.Magnitude
)
utils::head(results_3x)
Triaxial Sojourn method for the SIP method
Description
Triaxial Sojourn method for the SIP method
Usage
sojourn_3x_SIP(ag, short = 30)
Arguments
ag |
combined ActiGraph and activPAL data on which to identify transitions and make predictions |
short |
the minimum duration of a qualifying Sojourn |
Value
A data frame of processed data using the SIP method
Examples
data(SIP_ag, package = "Sojourn")
data(SIP_ap, package = "Sojourn")
data <- Sojourn::enhance_actigraph(SIP_ag, SIP_ap)
utils::head(sojourn_3x_SIP(data))
Check monitor data for required demographic variables
Description
Check monitor data for required demographic variables
Usage
youth_name_test(
AG,
demo_names = c("id", "Age", "Sex", "BMI"),
demo_interactive = FALSE,
fix_sex_var = TRUE,
...
)
Arguments
AG |
a data frame of monitor and demographic data |
demo_names |
character vector of required demographic variable names to look for |
demo_interactive |
logical. Input demographics interactively if missing variables are identified during format checking? |
fix_sex_var |
logical. Should "Sex" be changed to "SexM" and dummy coded? |
... |
further arguments passed to svDialogs functions |
Value
A properly-formatted data frame of monitor data
Format data for input into the youth Sojourn method's neural networks
Description
Format data for input into the youth Sojourn method's neural networks
Usage
youth_network_shape(
data,
sojourns = TRUE,
RAW = FALSE,
epoch = 1,
verbose = TRUE,
expand = TRUE,
time_var = "Timestamp",
first_print = TRUE,
...
)
Arguments
data |
a data frame of monitor and demographic data to format |
sojourns |
logical. Should the data be windowed by Sojourn (TRUE) or with a static window (15-s; FALSE)? |
RAW |
logical. Are the data raw acceleration? |
epoch |
numeric. The epoch length of the data. Values other than one are not recommended. |
verbose |
logical. Print processing updates to the console? |
expand |
logical. Should collapsed data be replicated to match the length of the original input? |
time_var |
character scalar giving the variable name in |
first_print |
logical. Print extra information? |
... |
further arguments passed to messager |
Value
A data frame containing data that are ready for making predictions with the youth Sojourn method's neural networks
Decision tree for making final predictions in the youth Sojourn method
Description
Decision tree for making final predictions in the youth Sojourn method
Usage
youth_sojourn_tree(
Vector.Magnitude,
Block.Est,
Sojourns.Est,
Hip = TRUE,
RAW = FALSE,
epoch = 1
)
Arguments
Vector.Magnitude |
numeric vector of triaxial acceleration (vector magnitude for activity counts, and Euclidian Norm Minus One for raw acceleration) |
Block.Est |
predictions obtained from the neural networks using static segmentation |
Sojourns.Est |
predictions obtained from the neural networks using dynamic segmentation (i.e., Sojourn-specific predictions) |
Hip |
logical. Are data from a hip-worn device? |
RAW |
logical. Are the data raw acceleration? |
epoch |
numeric. The epoch length of the data. Values other than one are not recommended. |
Value
A factor vector of predicted physical activity intensities (Sedentary, Light, or moderate-to-vigorous physical activity (MVPA))