| Title: | Develop and Apply Two-Regression Algorithms |
|---|---|
| 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. |
| Authors: | Paul R. Hibbing [aut, cre], Vincent T. van Hees [ctb] |
| Maintainer: | Paul R. Hibbing <[email protected]> |
| License: | GPL-3 |
| Version: | 1.1.1 |
| Built: | 2026-05-13 09:03:55 UTC |
| Source: | https://github.com/paulhibbing/tworegression |
A dataset with pre-processed primary accelerometer and IMU data that is ready for applying a two-regression algorithm.
all_dataall_data
A data frame with 299 rows and 17 variables:
Participant ID
The filename of the primary accelerometer file
The date the primary accelerometer file was processed
The filename of the IMU file
The date the IMU file was processed
The corresponding time for each row of data
The numeric day of the year, i.e., the Julian date
The numeric minute of the day
Euclidian Norm Minus One, in milli-g
Gyroscope vector magnitude, in degrees per second
Rotation in x axis, degrees per second
Rotation in y axis, degrees per second
Rotation in z axis, degrees per second
Cardinal direction of magnetometer signal, averaged over one second
Coefficient of variation per 10-s, applied to Euclidian Norm Minus One
Coefficient of variation per 10-s, applied to gyroscope vector magnitude
Direction changes per 5-s
A small amount of 10-s epoch activity counts for code examples
count_datacount_data
A data frame with 30 rows and 5 variables:
POSIX. The timestamp
numeric. The vertical axis activity counts
numeric. The horizontal axis
numeric. The lateral axis
numeric. The vector magnitude of all three axes
Develop a two-regression algorithm
Check if an object has class TwoRegression
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)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)
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 |
An object of class 'TwoRegression'
predict.TwoRegression
summary.TwoRegression
plot.TwoRegression
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)" )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)" )
A dataset for demonstrating checks that are applied to IMU data.
imu_to_checkimu_to_check
A data frame with 300 rows and 8 variables:
The filename of the IMU file
The date the IMU file was processed
The corresponding time for each row of data
Gyroscope vector magnitude, in degrees per second
Rotation in x axis, degrees per second
Rotation in y axis, degrees per second
Rotation in z axis, degrees per second
Cardinal direction of magnetometer signal, averaged over one second
A partially-processed IMU dataset ready to be collapsed from raw samples to one-second summaries.
imu_to_collapseimu_to_collapse
A data frame with 1500 rows and 17 variables:
The corresponding time for each row of data
Secondary accelerometer x-axis data, in G
Secondary accelerometer y-axis data, in G
Secondary accelerometer z-axis data, in G
Temperature of the IMU, in Celcius
Gyroscope x-axis data, in degrees per second
Gyroscope y-axis data, in degrees per second
Gyroscope z-axis data, in degrees per second
Magnetometer x-axis data, in micro-Teslas
Magnetometer y-axis data, in micro-Teslas
Magnetometer z-axis data, in micro-Teslas
The filename of the IMU file
The date the IMU file was processed
The millisecond value of the timestamp
Vector magnitude of the secondary accelerometer signal, in G
Gyroscope vector magnitude, in degrees per second
Vector magnitude of the magnetometer signal, in micro-Teslas
Four plots are generated: a threshold plot for both cut-points, and a model plot for both regression models
## 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, ... )## 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, ... )
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 |
A two-by-two grid of summary plots
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 )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 )
Predict metabolic equivalents from a TwoRegression object
## S3 method for class 'TwoRegression' predict( object, newdata, min_mets = object$sed_METs, max_mets = 20, warn_high_low = TRUE, verbose = FALSE, ... )## S3 method for class 'TwoRegression' predict( object, newdata, min_mets = object$sed_METs, max_mets = 20, warn_high_low = TRUE, verbose = FALSE, ... )
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 |
A two-column data frame giving the activity classification (sedentary, walk/run, or intermittent activity) and the corresponding metabolic equivalent prediction
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)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)
A partially-processed primary accelerometer dataset ready to calculate the coefficient of variation per 10-s
raw_for_cvraw_for_cv
A data frame with 299 rows and 2 variables:
A vestigial variable synonymous with row number
Euclidian Norm Minus One, in milli-g
A partially-processed primary accelerometer dataset ready to be collapsed from raw samples to one-second summaries.
raw_to_collapseraw_to_collapse
A data frame with 24000 rows and 3 variables:
Primary accelerometer x-axis data, in G
Primary accelerometer y-axis data, in G
Primary accelerometer z-axis data, in G
Smooth two-regression estimates over specified periods
smooth_2rm(AG, time_var = "Timestamp", unit = "60 sec", verbose = FALSE, ...)smooth_2rm(AG, time_var = "Timestamp", unit = "60 sec", verbose = FALSE, ...)
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 |
Smoothed data, collapsed in the specified intervals
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)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)
The TwoRegression package is designed to make working with two-regression algorithms quick, easy, and accurate.
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.
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.
## 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)## 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)