| Type: | Package |
| Title: | Develop and Apply Two-Regression Algorithms |
| Version: | 1.1.1 |
| Depends: | R (≥ 3.5.0) |
| Description: | Facilitates development and application of two-regression algorithms for research-grade wearable devices. It provides an easy way for users to access previously-developed algorithms, and also to develop their own. Initial motivation came from Hibbing PR, LaMunion SR, Kaplan AS, & Crouter SE (2018) <doi:10.1249/MSS.0000000000001532>. However, other algorithms are now supported. Please see the associated references in the package documentation for full details of the algorithms that are supported. |
| License: | GPL-3 |
| Encoding: | UTF-8 |
| LazyData: | true |
| Imports: | dplyr (≥ 0.5.0), ggplot2 (≥ 3.4.0), gridExtra (≥ 2.3), lubridate, magrittr (≥ 1.5), PAutilities (≥ 1.1.0), pROC (≥ 1.16.0), RcppRoll, rlang, stats, tidyr |
| RoxygenNote: | 7.1.2 |
| Suggests: | knitr, rmarkdown, testthat (≥ 3.0.0) |
| VignetteBuilder: | knitr |
| URL: | https://github.com/paulhibbing/TwoRegression |
| BugReports: | https://github.com/paulhibbing/TwoRegression/issues |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2025-11-15 12:38:45 UTC; paulh |
| Author: | Paul R. Hibbing [aut, cre], Vincent T. van Hees [ctb] |
| Maintainer: | Paul R. Hibbing <paulhibbing@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2025-11-19 19:50:13 UTC |
Perform leave-one-participant-out-cross-validation on a two-regression algorithm
Description
Perform leave-one-participant-out-cross-validation on a two-regression algorithm
Usage
DualCP_LOSO(
subject_var = "id",
data,
model,
MET_var = "MET_RMR",
activity_var = "Behavior",
verbose = FALSE,
trace = FALSE
)
fold(x, subject_var, data, model, MET_var, activity_var, trace)
get_cv_predictions(model, fold_data, cv_data)
get_fold_model(formula_string, fold_data, level = c("walkrun", "intermittent"))
get_classifications(
data,
model,
numeric = TRUE,
labels = c("SB", "walkrun", "intermittent")
)
Arguments
subject_var |
character. Variable name that distinguishes between participants |
data |
the full data set to cross-validate |
model |
a |
MET_var |
character. The outcome variable name (in metabolic equivalents) |
activity_var |
character. The variable name for the activity being performed |
verbose |
logical. Print updates? |
trace |
logical. Print information about each iteration? |
x |
character. The id to hold out |
fold_data |
the validation data set |
cv_data |
the holdout (i.e., cross-validation) data set |
formula_string |
character. Formula to apply in call to |
level |
character. Classification subset to include in call to |
Value
A data frame with predictions obtained from leave-one-participant-out-cross-validation
Note
This function will not work for TwoRegression objects formed
from previously-published research. The TwoRegression object needs
to have more information than is available in those cases in order to
perform cross-validation, and this is sensible, since there is no reason or
way to re-perform cross-validation on an already-finalized algorithm.
Apply an existing two-regression model
Description
Acts as a generic function that dispatches to specific implementation
functions (crouter_2006, crouter_2010,
crouter_2012, or hibbing_2018)
Usage
TwoRegression(
AG,
method = c("Crouter 2006", "Crouter 2010", "Crouter 2012", "Hibbing 2018"),
verbose = FALSE,
...
)
crouter_2006(AG, movement_var, time_var, ...)
crouter_2010(AG, movement_var, time_var, ...)
crouter_2012(AG, movement_var, time_var, model, check = TRUE, ...)
hibbing_2018(
AG,
accel_var = "ENMO",
gyro_var = "GVM",
direction_var = "Direction",
time_var = "Timestamp",
site = c("Hip", "Left Wrist", "Right Wrist", "Left Ankle", "Right Ankle"),
algorithm = 1:3,
smooth = FALSE,
verbose = FALSE,
...
)
Arguments
AG |
data frame of ActiGraph data |
method |
character scalar telling which model to apply to the data.
Currently supported selections are |
verbose |
logical. Print updates to console? |
... |
arguments passed to the implementation function indicated by
|
movement_var |
character scalar. Name of the movement variable (default
is |
time_var |
character scalar. Name of the timestamp variable (required to verify that input epoch length is 10 seconds) |
model |
character scalar. One of |
check |
Logical. Should a warning be issued that will prompt you to check that the selected model matches the selected movement variable? |
accel_var |
Character scalar. Name of accelerometer variable to operate on (expected format is Euclidian Norm Minus One, in milli-gravitational units) |
gyro_var |
character scalar. Name of gyroscope variable to operate on (expected format is gyroscope vector magnitude, in degrees per second) |
direction_var |
character scalar. Name of magnetometer variable to
operate on (expected format is a vector of directions, likely produced by
|
site |
character scalar or vector of attachment sites (more than one may be desired, e.g., if results are to be compared from running both of the wrist-specific algorithms) |
algorithm |
An integer/numeric scalar or vector giving the algorithm(s)
to apply to the data from the primary accelerometer and (if applicable)
IMU. Must be |
smooth |
logical. Should data be averaged over a longer time period after processing? |
Value
The original data appended with columns giving activity classification (sedentary, ambulatory, or intermittent) and energy expenditure (i.e, METs)
See Also
Crouter et al. (2006, J Appl Physiol) Crouter et al. (2010, Med Sci Sports Exerc) Crouter et al. (2012, Med Sci Sports Exerc) Hibbing et al. (2018, Med Sci Sports Exerc)
apply_two_regression_hibbing18
smooth_2rm
Examples
## Datasets
data(count_data, package = "TwoRegression")
data(all_data, package = "TwoRegression")
## Crouter 2006-2012 models
TwoRegression(
count_data, "Crouter 2006",
movement_var = "Axis1", time_var = "time"
)
TwoRegression(
count_data, "Crouter 2010",
movement_var = "Axis1", time_var = "time"
)
TwoRegression(
count_data, "Crouter 2012", movement_var = "Axis1",
time_var = "time", model = "VA", check = FALSE
)
TwoRegression(
count_data, "Crouter 2012", movement_var = "Vector.Magnitude",
time_var = "time", model = "VM", check = FALSE
)
## Hibbing 2018 models (can be vectorized)
all_data$ENMO_CV10s <- NULL
all_data$GVM_CV10s <- NULL
all_data$Direction <- NULL
result <- TwoRegression(
all_data, "Hibbing 2018", gyro_var = "Gyroscope_VM_DegPerS",
direction_var = "mean_magnetometer_direction",
site = c("Left Ankle", "Right Ankle"), algorithm = 1:2
)
utils::head(result)
Develop and Apply Two-Regression Algorithms
Description
The TwoRegression package is designed to make working with two-regression algorithms quick, easy, and accurate.
Details
Originally, the package was designed to house the algorithms created by
Hibbing et al. (2018). Since then, support has been added for other
algorithms, including Crouter et al. (2006), Crouter et al. (2010), and
Crouter et al. (2012). Functionality has also been added to develop and
cross-validate new two-regression algorithms. The package RcppRoll
has also been invoked to speed up rolling coefficient of variation
calculations.
Associated References
Hibbing PR, LaMunion SR, Kaplan AS, & Crouter SE (2018). Estimating energy expenditure with ActiGraph GT9X Inertial Measurement Unit. Medicine and Science in Sports and Exercise. 50(5), 1093-1102. doi: 10.1249/MSS.0000000000001532
Crouter, S. E., Clowers, K. G., & Bassett Jr, D. R. (2006). A novel method for using accelerometer data to predict energy expenditure. Journal of Applied Physiology, 100(4), 1324-1331.
Crouter, S. E., Kuffel, E., Haas, J. D., Frongillo, E. A., & Bassett Jr, D. R. (2010). Refined Two-Regression Model for the ActiGraph Accelerometer. Medicine and Science in Sports and Exercise, 42(5), 1029.
Crouter, S. E., Horton, M., & Bassett Jr, D. R. (2012). Use of a Two-regression model for estimating energy expenditure in children. Medicine and Science in Sports and Exercise, 44(6), 1177.
Examples
## Datasets
data(count_data, package = "TwoRegression")
data(all_data, package = "TwoRegression")
## Crouter 2006-2012 models
TwoRegression(
count_data, "Crouter 2006",
movement_var = "Axis1", time_var = "time"
)
TwoRegression(
count_data, "Crouter 2010",
movement_var = "Axis1", time_var = "time"
)
TwoRegression(
count_data, "Crouter 2012", movement_var = "Axis1",
time_var = "time", model = "VA", check = FALSE
)
TwoRegression(
count_data, "Crouter 2012", movement_var = "Vector.Magnitude",
time_var = "time", model = "VM", check = FALSE
)
## Hibbing 2018 models (can be vectorized)
all_data$ENMO_CV10s <- NULL
all_data$GVM_CV10s <- NULL
all_data$Direction <- NULL
result <- TwoRegression(
all_data, "Hibbing 2018", gyro_var = "Gyroscope_VM_DegPerS",
direction_var = "mean_magnetometer_direction",
site = c("Left Ankle", "Right Ankle"), algorithm = 1:2
)
utils::head(result)
Two-regression-ready data frame
Description
A dataset with pre-processed primary accelerometer and IMU data that is ready for applying a two-regression algorithm.
Usage
all_data
Format
A data frame with 299 rows and 17 variables:
- PID
Participant ID
- file_source_PrimaryAccel
The filename of the primary accelerometer file
- date_processed_PrimaryAccel
The date the primary accelerometer file was processed
- file_source_IMU
The filename of the IMU file
- date_processed_IMU
The date the IMU file was processed
- Timestamp
The corresponding time for each row of data
- day_of_year
The numeric day of the year, i.e., the Julian date
- minute_of_day
The numeric minute of the day
- ENMO
Euclidian Norm Minus One, in milli-g
- Gyroscope_VM_DegPerS
Gyroscope vector magnitude, in degrees per second
- mean_abs_Gyroscope_x_DegPerS
Rotation in x axis, degrees per second
- mean_abs_Gyroscope_y_DegPerS
Rotation in y axis, degrees per second
- mean_abs_Gyroscope_z_DegPerS
Rotation in z axis, degrees per second
- mean_magnetometer_direction
Cardinal direction of magnetometer signal, averaged over one second
- ENMO_CV10s
Coefficient of variation per 10-s, applied to Euclidian Norm Minus One
- GVM_CV10s
Coefficient of variation per 10-s, applied to gyroscope vector magnitude
- Direction
Direction changes per 5-s
Activity count data for demonstrating prior two-regression models
Description
A small amount of 10-s epoch activity counts for code examples
Usage
count_data
Format
A data frame with 30 rows and 5 variables:
- time
POSIX. The timestamp
- Axis1
numeric. The vertical axis activity counts
- Axis2
numeric. The horizontal axis
- Axis3
numeric. The lateral axis
- Vector.Magnitude
numeric. The vector magnitude of all three axes
Calculate direction changes per five seconds in sliding windows
Description
get_directions is legacy code, whereas get_dcp5 is cleaner and
(possibly) faster
Usage
get_directions(x, window_size = 5)
get_dcp5(x, window_size = 5)
Arguments
x |
a numeric vector on which to perform the calculation |
window_size |
width of the sliding window, in data points |
Value
a numeric vector of values, giving the number of direction changes in the sliding window that corresponds to each epoch of data
Develop a two-regression algorithm
Description
Develop a two-regression algorithm
Check if an object has class TwoRegression
Usage
fit_2rm(
data,
activity_var,
sed_cp_activities,
sed_activities,
sed_cp_var,
sed_METs,
walkrun_activities,
walkrun_cp_var,
met_var,
walkrun_formula,
intermittent_formula,
method = "user_unspecified"
)
is.TwoRegression(x)
Arguments
data |
The data with which to develop the algorithm |
activity_var |
Character scalar. Name of the variable defining which activity is being performed |
sed_cp_activities |
Character vector. Activities to be included in the process of forming the sedentary classifier |
sed_activities |
Character vector. Actual sedentary activities |
sed_cp_var |
Character scalar. Name of the variable on which the sedentary cut-point is defined |
sed_METs |
Numeric scalar. Metabolic equivalent value to apply to sedentary activities |
walkrun_activities |
Character vector. Actual ambulatory activities |
walkrun_cp_var |
Character scalar. Name of the variable on which the walk/run cut-point is defined |
met_var |
Character scalar. Name of the variable giving actual energy expenditure (in metabolic equivalents) |
walkrun_formula |
Character scalar. Formula to use for developing the walk/run regression model |
intermittent_formula |
Character scalar. Formula to use for developing the intermittent activity regression model |
method |
character scalar. Optional name for the model, potentially useful for printing. |
x |
object to be tested |
Value
An object of class 'TwoRegression'
See Also
predict.TwoRegression
summary.TwoRegression
plot.TwoRegression
Examples
set.seed(307)
data(all_data, package = "TwoRegression")
fake_sed <- c("Lying", "Sitting")
fake_lpa <- c("Sweeping", "Dusting")
fake_cwr <- c("Walking", "Running")
fake_ila <- c("Tennis", "Basketball")
fake_activities <- c(fake_sed, fake_lpa, fake_cwr, fake_ila)
all_data$Activity <- sample(fake_activities, nrow(all_data), TRUE)
all_data$fake_METs <- ifelse(
all_data$Activity %in% c(fake_sed, fake_lpa),
runif(nrow(all_data), 1, 2),
runif(nrow(all_data), 2.5, 8)
)
fit_2rm(
data = all_data,
activity_var = "Activity",
sed_cp_activities = c(fake_sed, fake_lpa),
sed_activities = fake_sed,
sed_cp_var = "ENMO",
sed_METs = 1.25,
walkrun_activities = fake_cwr,
walkrun_cp_var = "ENMO_CV10s",
met_var = "fake_METs",
walkrun_formula = "fake_METs ~ ENMO",
intermittent_formula = "fake_METs ~ ENMO + I(ENMO^2) + I(ENMO^3)"
)
Convert an object of class TwoRegression to a textual representation of the algorithm
Description
Convert an object of class TwoRegression to a textual representation of the algorithm
Usage
get_2rm_formula(object)
Arguments
object |
the TwoRegression object |
Develop a cut-point as part of the process for developing a two-regression algorithm
Description
Develop a cut-point as part of the process for developing a two-regression algorithm
Usage
get_cut_point(
data,
activity_var,
included_activities,
positive_activities,
cp_var
)
Arguments
data |
the data on which to perform the operation |
activity_var |
character scalar. Name of the variable that indicates what activity each data point corresponds to. |
included_activities |
character vector. All activities included in the data subset to be used for developing the cut-point |
positive_activities |
character vector. Activities considered part of the positive class |
cp_var |
Character scalar. Name of the variable on which the cut-point will be based. |
Value
an object of class 'roc'
Coefficient of variation for two-regression models
Description
Calculates coefficient of variation using static or sliding methods, with potential for custom methods as well
Usage
cv_2rm(
x,
window_size = 10,
approach = c("sliding", "static", "custom"),
verbose = FALSE,
...
)
static_cv(x, window_size)
sliding_cv(x, window_size)
custom_cv(x, window_size, pad_size = window_size - 1, ...)
Arguments
x |
a numeric vector on which to perform the calculation |
window_size |
width of the sliding window, in data points |
approach |
character scalar naming the desired calculation approach to
use. Can be |
verbose |
logical. Print progress updates? |
... |
arguments passed to functions in the |
pad_size |
The number of NA values to append at the start and end of
|
Details
For approach == "sliding", the value for each epoch
represents the lowest CV value of all the sliding windows that overlap with
that epoch. For aproach == "static", a truncated vector of CV values
is given, which reflects CV values from a non-overlapping sliding window.
For approach == "custom", users can pass arguments into
RcppRoll functions and create a variation on the sliding approach.
Behavior of this feature is not well documented and subject to change if
people start using it and requesting specific behavior.
Value
a numeric vector of values, giving the desired coefficient of variation
See Also
Crouter et al. (2010, Med Sci Sports Exerc) Crouter et al. (2006, J Appl Physiol)
Examples
data(raw_for_cv)
cv_2rm(raw_for_cv$ENMO)
Convert a linear model to a text representation of the prediction equation
Description
Convert a linear model to a text representation of the prediction equation
Usage
get_lm_formula(model)
Arguments
model |
The linear model object |
Apply a Hibbing 2018 two-regression algorithm
Description
Applies the specified two-regression algorithm from Hibbing et al. (2018, Med Sci Sports Exerc) to data from the primary accelerometer and IMU (if applicable)
Usage
apply_two_regression_hibbing18(
which_algorithm = data.frame(Wear_Location = "Hip", Algorithm = 1),
AG,
verbose = FALSE,
...
)
Arguments
which_algorithm |
a dataframe specifying which algorithm to use, based
on |
AG |
data frame of ActiGraph data |
verbose |
logical. Print updates to console? |
... |
arguments passed to |
Value
a numeric vector of predicted energy expenditure values, expressed in metabolic equivalents
Internal functions for the 2RM wrapper
Description
Internal functions for the 2RM wrapper
Usage
TwoRegression_Hibbing18_variable_validate(
varname,
AG,
algorithm,
sensor = c("accelerometer", "gyroscope", "magnetometer")
)
TwoRegression_Hibbing18_algorithm_validate(algorithm)
Arguments
varname |
character scalar. Name of variable to check |
AG |
data frame of ActiGraph data |
algorithm |
An integer/numeric scalar or vector giving the algorithm(s)
to apply to the data from the primary accelerometer and (if applicable)
IMU. Must be |
sensor |
character scalar indicating if |
IMU data to check
Description
A dataset for demonstrating checks that are applied to IMU data.
Usage
imu_to_check
Format
A data frame with 300 rows and 8 variables:
- file_source_IMU
The filename of the IMU file
- date_processed_IMU
The date the IMU file was processed
- Timestamp
The corresponding time for each row of data
- Gyroscope_VM_DegPerS
Gyroscope vector magnitude, in degrees per second
- mean_abs_Gyroscope_x_DegPerS
Rotation in x axis, degrees per second
- mean_abs_Gyroscope_y_DegPerS
Rotation in y axis, degrees per second
- mean_abs_Gyroscope_z_DegPerS
Rotation in z axis, degrees per second
- mean_magnetometer_direction
Cardinal direction of magnetometer signal, averaged over one second
IMU data to collapse
Description
A partially-processed IMU dataset ready to be collapsed from raw samples to one-second summaries.
Usage
imu_to_collapse
Format
A data frame with 1500 rows and 17 variables:
- Timestamp
The corresponding time for each row of data
- Accelerometer.X
Secondary accelerometer x-axis data, in G
- Accelerometer.Y
Secondary accelerometer y-axis data, in G
- Accelerometer.Z
Secondary accelerometer z-axis data, in G
- Temperature
Temperature of the IMU, in Celcius
- Gyroscope.X
Gyroscope x-axis data, in degrees per second
- Gyroscope.Y
Gyroscope y-axis data, in degrees per second
- Gyroscope.Z
Gyroscope z-axis data, in degrees per second
- Magnetometer.X
Magnetometer x-axis data, in micro-Teslas
- Magnetometer.Y
Magnetometer y-axis data, in micro-Teslas
- Magnetometer.Z
Magnetometer z-axis data, in micro-Teslas
- file_source_IMU
The filename of the IMU file
- date_processed_IMU
The date the IMU file was processed
- ms
The millisecond value of the timestamp
- mean_Accel_VM
Vector magnitude of the secondary accelerometer signal, in G
- Gyroscope_VM_DegPerS
Gyroscope vector magnitude, in degrees per second
- Magnetometer_VM_MicroT
Vector magnitude of the magnetometer signal, in micro-Teslas
Create summary plots for TwoRegression objects
Description
Four plots are generated: a threshold plot for both cut-points, and a model plot for both regression models
Usage
## S3 method for class 'TwoRegression'
plot(
x = NULL,
object = NULL,
sed_cp_activities,
sed_activities,
sed_cpVar = NULL,
activity_var,
met_var,
walkrun_activities,
walkrun_cpVar,
x_sed = NULL,
y_sed = NULL,
x_walkrun = NULL,
y_walkrun = NULL,
print = TRUE,
...
)
Arguments
x |
passed from generic function but not used in the method |
object |
the TwoRegression object |
sed_cp_activities |
Character vector. Activities to be included in the process of forming the sedentary classifier |
sed_activities |
Character vector. Actual sedentary activities |
sed_cpVar |
character scalar. The name of the variable on which the cut-point is based |
activity_var |
Character scalar. Name of the variable defining which activity is being performed |
met_var |
character scalar. The name of the variable containing energy expenditure values, in metabolic equivalents |
walkrun_activities |
Character vector. Actual ambulatory activities |
walkrun_cpVar |
character scalar giving the name of the variable on which the walk/run cut-point is based |
x_sed |
numeric scalar giving x coordinate for label placement in sedentary cut-point plot |
y_sed |
numeric scalar giving y coordinate for label placement in sedentary cut-point plot |
x_walkrun |
numeric scalar giving x coordinate for label placement in walk/run cut-point plot |
y_walkrun |
numeric scalar giving y coordinate for label placement in walk/run cut-point plot |
print |
logical. Should the plot be arranged in a grid? If false, the
panels will be returned in a list of |
... |
further arguments passed to plotting calls |
Value
A two-by-two grid of summary plots
Examples
data(all_data, package = "TwoRegression")
all_data$PID <-
rep(
c("Test1", "Test2"),
each = ceiling(nrow(all_data) / 2))[seq(nrow(all_data))]
fake_sed <- c("Lying", "Sitting")
fake_lpa <- c("Sweeping", "Dusting")
fake_cwr <- c("Walking", "Running")
fake_ila <- c("Tennis", "Basketball")
fake_activities <- c(fake_sed, fake_lpa, fake_cwr, fake_ila)
all_data$Activity <-
sample(fake_activities, nrow(all_data), TRUE)
all_data$fake_METs <-
ifelse(all_data$Activity %in% c(fake_sed, fake_lpa),
runif(nrow(all_data), 1, 2),
runif(nrow(all_data), 2.5, 8)
)
ex_2rm <- fit_2rm(
data = all_data,
activity_var = "Activity",
sed_cp_activities = c(fake_sed, fake_lpa),
sed_activities = fake_sed,
sed_cp_var = "ENMO",
sed_METs = 1.25,
walkrun_activities = fake_cwr,
walkrun_cp_var = "ENMO_CV10s",
met_var = "fake_METs",
walkrun_formula = "fake_METs ~ ENMO",
intermittent_formula = "fake_METs ~ ENMO + I(ENMO^2) + I(ENMO^3)"
)
model_plot_list <- plot(
object = ex_2rm,
sed_cp_activities = c(fake_sed, fake_lpa),
sed_activities = fake_sed,
sed_cpVar = "ENMO",
activity_var = "Activity",
met_var = "fake_METs",
walkrun_activities = fake_cwr,
walkrun_cpVar = "ENMO_CV10s",
print = FALSE
)
print(model_plot_list$sed_cut_point)
print(model_plot_list$walkrun_cut_point)
print(model_plot_list$walkrun_regression)
print(model_plot_list$intermittent_regression)
plot(
object = ex_2rm,
sed_cp_activities = c(fake_sed, fake_lpa),
sed_activities = fake_sed,
sed_cpVar = "ENMO",
activity_var = "Activity",
met_var = "fake_METs",
walkrun_activities = fake_cwr,
walkrun_cpVar = "ENMO_CV10s",
print = TRUE
)
Add a cut-point to a plot
Description
Add a cut-point to a plot
Usage
plotCP(fig, cutPoint, x = NULL, y = NULL)
Arguments
fig |
A partially-assembled figure |
cutPoint |
The threshold value to insert into the figure |
x |
numeric scalar giving x coordinate for label placement |
y |
numeric scalar giving y coordinate for label placement |
Plot behaviors for visualizing a sedentary cut-point
Description
Plot behaviors for visualizing a sedentary cut-point
Usage
plot_sed(
object,
sed_cp_activities,
sed_activities,
activity_var,
sed_cpVar,
met_var,
...
)
Arguments
object |
TwoRegression object to plot |
sed_cp_activities |
activities to include in a subset of |
sed_activities |
Character vector. Actual sedentary activities |
activity_var |
Character scalar. Name of the variable defining which activity is being performed |
sed_cpVar |
character scalar. The name of the variable on which the cut-point is based |
met_var |
character scalar. The name of the variable containing energy expenditure values, in metabolic equivalents |
... |
additional arguments passed to |
Plot behaviors for visualizing a walk/run cut-point
Description
Plot behaviors for visualizing a walk/run cut-point
Usage
plot_walkrun(
object,
activity_var,
walkrun_activities,
walkrun_cpVar,
met_var,
...
)
Arguments
object |
the |
activity_var |
Character scalar. Name of the variable defining which activity is being performed |
walkrun_activities |
character vector giving values of
|
walkrun_cpVar |
character scalar giving the name of the variable on which the walk/run cut-point is based |
met_var |
character scalar. The name of the variable containing energy expenditure values, in metabolic equivalents |
... |
further arguments passed to plotting calls |
Predict metabolic equivalents from a TwoRegression object
Description
Predict metabolic equivalents from a TwoRegression object
Usage
## S3 method for class 'TwoRegression'
predict(
object,
newdata,
min_mets = object$sed_METs,
max_mets = 20,
warn_high_low = TRUE,
verbose = FALSE,
...
)
Arguments
object |
the TwoRegression object |
newdata |
the data on which to predict metabolic equivalents (METs) |
min_mets |
the minimum allowable value for MET predictions. Defaults to
the value stored in |
max_mets |
the maximum allowable value for MET predictions. There is no
value embedded in |
warn_high_low |
logical. Issue warnings about values less than
|
verbose |
logical. Print processing updates? |
... |
further arguments passed to or from other methods |
Value
A two-column data frame giving the activity classification (sedentary, walk/run, or intermittent activity) and the corresponding metabolic equivalent prediction
Examples
data(all_data, package = "TwoRegression")
all_data$PID <-
rep(
c("Test1", "Test2"),
each = ceiling(nrow(all_data) / 2))[seq(nrow(all_data))]
train_data <- all_data[all_data$PID != "Test2", ]
test_data <- all_data[all_data$PID == "Test2", ]
fake_sed <- c("Lying", "Sitting")
fake_lpa <- c("Sweeping", "Dusting")
fake_cwr <- c("Walking", "Running")
fake_ila <- c("Tennis", "Basketball")
fake_activities <- c(fake_sed, fake_lpa, fake_cwr, fake_ila)
train_data$Activity <-
sample(fake_activities, nrow(train_data), TRUE)
train_data$fake_METs <-
ifelse(train_data$Activity %in% c(fake_sed, fake_lpa),
runif(nrow(train_data), 1, 2),
runif(nrow(train_data), 2.5, 8)
)
ex_2rm <- fit_2rm(
data = train_data,
activity_var = "Activity",
sed_cp_activities = c(fake_sed, fake_lpa),
sed_activities = fake_sed,
sed_cp_var = "ENMO",
sed_METs = 1.25,
walkrun_activities = fake_cwr,
walkrun_cp_var = "ENMO_CV10s",
met_var = "fake_METs",
walkrun_formula = "fake_METs ~ ENMO",
intermittent_formula = "fake_METs ~ ENMO + I(ENMO^2) + I(ENMO^3)"
)
predict(ex_2rm, test_data)
Primary accelerometer data to calculate coefficient of variation per 10-s
Description
A partially-processed primary accelerometer dataset ready to calculate the coefficient of variation per 10-s
Usage
raw_for_cv
Format
A data frame with 299 rows and 2 variables:
- Block
A vestigial variable synonymous with row number
- ENMO
Euclidian Norm Minus One, in milli-g
Primary accelerometer data to collapse
Description
A partially-processed primary accelerometer dataset ready to be collapsed from raw samples to one-second summaries.
Usage
raw_to_collapse
Format
A data frame with 24000 rows and 3 variables:
- Accelerometer X
Primary accelerometer x-axis data, in G
- Accelerometer Y
Primary accelerometer y-axis data, in G
- Accelerometer Z
Primary accelerometer z-axis data, in G
Smooth two-regression estimates over specified periods
Description
Smooth two-regression estimates over specified periods
Usage
smooth_2rm(AG, time_var = "Timestamp", unit = "60 sec", verbose = FALSE, ...)
Arguments
AG |
data frame of ActiGraph data |
time_var |
character scalar. Name of the timestamp variable (required to verify that input epoch length is 10 seconds) |
unit |
the interval to use for smoothing (see
|
verbose |
logical. Print updates to console? |
... |
currently unused |
Value
Smoothed data, collapsed in the specified intervals
Examples
data(all_data, package = "TwoRegression")
result <- TwoRegression(
all_data, "Hibbing 2018", gyro_var = "Gyroscope_VM_DegPerS",
direction_var = "mean_magnetometer_direction",
site = c("Left Ankle", "Right Ankle"), algorithm = 1:2
)
smooth_2rm(result)
Summary method for TwoRegression objects
Description
Summary method for TwoRegression objects
Usage
## S3 method for class 'TwoRegression'
summary(object, ...)
new_summary(object)
new_cut(
z,
object,
element = c("sed_roc", "walkrun_roc"),
label = c("sedentary", "walk_run")
)
new_model(
z,
object,
element = c("walkrun_model", "intermittent_model"),
label = c("walk_run", "intermittent_activity")
)
Arguments
object |
The TwoRegression object to summarize |
... |
Arguments passed to |
z |
An intermediate summary object for internal use |
element |
character. Element name to search for in |
label |
character. A label for the cut point |
Value
and object of class summary.TwoRegression, containing
information about the cut-points and diagnostics, regression model
performance, and overall algorithm performance during
leave-one-participant-out-cross-validation.
Examples
set.seed(307)
data(all_data, package = "TwoRegression")
all_data$PID <- rep(
c("Test1", "Test2"),
each = ceiling(nrow(all_data) / 2)
)[seq(nrow(all_data))]
fake_sed <- c("Lying", "Sitting")
fake_lpa <- c("Sweeping", "Dusting")
fake_cwr <- c("Walking", "Running")
fake_ila <- c("Tennis", "Basketball")
fake_activities <- c(fake_sed, fake_lpa, fake_cwr, fake_ila)
all_data$Activity <-
sample(fake_activities, nrow(all_data), TRUE)
all_data$fake_METs <-
ifelse(all_data$Activity %in% c(fake_sed, fake_lpa),
runif(nrow(all_data), 1, 2),
runif(nrow(all_data), 2.5, 8)
)
ex_2rm <- fit_2rm(
data = all_data,
activity_var = "Activity",
sed_cp_activities = c(fake_sed, fake_lpa),
sed_activities = fake_sed,
sed_cp_var = "ENMO",
sed_METs = 1.25,
walkrun_activities = fake_cwr,
walkrun_cp_var = "ENMO_CV10s",
met_var = "fake_METs",
walkrun_formula = "fake_METs ~ ENMO",
intermittent_formula = "fake_METs ~ ENMO + I(ENMO^2) + I(ENMO^3)"
)
summary(
ex_2rm,
subject_var = "PID",
MET_var = "fake_METs",
activity_var = "Activity"
)