Skip to content

Commit

Permalink
Merge pull request Sage-Bionetworks#184 from itismeghasyam/vignette-d…
Browse files Browse the repository at this point in the history
…evelop

Vignette develop
  • Loading branch information
philerooski authored Mar 4, 2019
2 parents 8531446 + 57581d0 commit d32c7c9
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 259 deletions.
10 changes: 3 additions & 7 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,20 @@
#' Sample heartrate data from a smartphone camera
#'
#' A dataframe containing sample JSON output format of the heartrate data,
#' containing red, green, blue levels from the camera sensor, along with the
#' timestamp, and the derived metrics of hue, saturation and brightness.
#' containing red, green, blue levels from the camera sensor, indexed with the
#' timestamp t.
#'
#' A video(240p) of a finger covering the smartphone camera with the flash
#' turned on was recorded at 60fps. The average intensity of all the pixels per
#' frame in all the three color channels was calculated, and indexed along
#' the timestamp of the frame. We also have hue, brightness and saturation
#' calculated in a similar way.
#' the timestamp of the frame.
#'
#' @format A data frame with 3661 rows (observations) and 7 variables:
#' \describe{
#' \item{t}{time, in seconds}
#' \item{green}{mean green intensity across the frame at the given timestamp}
#' \item{blue}{mean blue intensity across the frame at the given timestamp}
#' \item{red}{mean red intensity across the frame at the given timestamp}
#' \item{brightness}{mean brightness across the frame at the given timestamp}
#' \item{hue}{mean hue across the frame at the given timestamp}
#' \item{saturation}{mean saturation across the frame at the given timestamp}
#' }
"heartrate_data"

Expand Down
28 changes: 9 additions & 19 deletions R/get_balance_features.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,37 +67,27 @@
#' @examples
#' accelerometer_data = cbind(
#' t = balance_data$timestamp,
#' balance_data$userAcceleration)
#' balance_data$userAcceleration) %>%
#' dplyr::filter(t < 5)
#' gyroscope_data = cbind(
#' t = balance_data$timestamp,
#' balance_data$rotationRate)
#' balance_data$rotationRate) %>%
#' dplyr::filter(t < 5)
#'
#' balance_features <- get_balance_features(accelerometer_data, gyroscope_data)
#'
#' balance_features <- get_balance_features(
#' accelerometer_data,
#' gyroscope_data,
#' time_filter = c(2,8))
#'
#' balance_features <- get_balance_features(
#' accelerometer_data,
#' gyroscope_data,
#' detrend = TRUE)
#'
#' balance_features <- get_balance_features(
#' accelerometer_data,
#' gyroscope_data,
#' frequency_filter = c(0.5, 25))
#'
#' balance_features <- get_balance_features(
#' accelerometer_data,
#' gyroscope_data,
#' window_length = 512,
#' window_overlap = 0.9)
#' time_filter = c(2,4),
#' detrend = TRUE,
#' frequency_filter = c(0.5,25))
#'
#' balance_features <- get_balance_features(
#' accelerometer_data,
#' gyroscope_data,
#' window_length = 256,
#' window_overlap = 0.2,
#' derived_kinematics = TRUE)
#'
#' balance_features <- get_balance_features(
Expand Down
10 changes: 7 additions & 3 deletions R/get_heartrate.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ get_heartrate <- function(heartrate_data, window_length = 10, window_overlap = 0
# Convert window length from seconds to samples
window_length <- round(sampling_rate * window_length)
mean_filter_order <- 65
if(sampling_rate <= 32){
mean_filter_order <- 33
}

## Apply pre-processing filter to all heartrate data

Expand Down Expand Up @@ -222,10 +225,11 @@ get_hr_from_time_series <- function(x, sampling_rate, method = 'acf', min_hr = 4
confidence <- NA
}


# If hr or condidence is NaN, then return hr = 0 and confidence = 0
if (is.na(confidence) || is.na(hr)) {
confidence <- NA
hr <- NA
if ((length(hr) == 0) || is.null(hr)) {
confidence <- NA
hr <- NA
}

return(c(hr, confidence))
Expand Down
26 changes: 8 additions & 18 deletions R/get_kinetic_tremor_features.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@
#' @examples
#' accelerometer_data = cbind(
#' t = kinetic_tremor_data$timestamp,
#' kinetic_tremor_data$userAcceleration)
#' kinetic_tremor_data$userAcceleration) %>%
#' dplyr::filter(t < 5)
#' gyroscope_data = cbind(
#' t = kinetic_tremor_data$timestamp,
#' kinetic_tremor_data$rotationRate)
#' kinetic_tremor_data$rotationRate) %>%
#' dplyr::filter(t < 5)
#'
#' kinetic_tremor_features <- get_kinetic_tremor_features(
#' accelerometer_data,
Expand All @@ -88,27 +90,15 @@
#' kinetic_tremor_features <- get_kinetic_tremor_features(
#' accelerometer_data,
#' gyroscope_data,
#' time_filter = c(2,8))
#'
#' kinetic_tremor_features <- get_kinetic_tremor_features(
#' accelerometer_data,
#' gyroscope_data,
#' detrend = TRUE)
#'
#' kinetic_tremor_features <- get_kinetic_tremor_features(
#' accelerometer_data,
#' gyroscope_data,
#' time_filter = c(2,4),
#' detrend = TRUE,
#' frequency_filter = c(0.5, 25))
#'
#' kinetic_tremor_features <- get_kinetic_tremor_features(
#' accelerometer_data,
#' gyroscope_data,
#' window_length = 512,
#' window_overlap = 0.9)
#'
#' kinetic_tremor_features <- get_kinetic_tremor_features(
#' accelerometer_data,
#' gyroscope_data,
#' window_length = 256,
#' window_overlap = 0.2,
#' derived_kinematics = TRUE)
#'
#' kinetic_tremor_features <- get_kinetic_tremor_features(
Expand Down
26 changes: 8 additions & 18 deletions R/get_tremor_features.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,37 +75,27 @@
#' @examples
#' accelerometer_data = cbind(
#' t = rest_tremor_data$timestamp,
#' rest_tremor_data$userAcceleration)
#' rest_tremor_data$userAcceleration) %>%
#' dplyr::filter(t < 5)
#' gyroscope_data = cbind(
#' t = rest_tremor_data$timestamp,
#' rest_tremor_data$rotationRate)
#' rest_tremor_data$rotationRate) %>%
#' dplyr::filter(t < 5)
#'
#' tremor_features <- get_tremor_features(accelerometer_data, gyroscope_data)
#'
#' tremor_features <- get_tremor_features(
#' accelerometer_data,
#' gyroscope_data,
#' time_filter = c(2,8))
#'
#' tremor_features <- get_tremor_features(
#' accelerometer_data,
#' gyroscope_data,
#' detrend = TRUE)
#'
#' tremor_features <- get_tremor_features(
#' accelerometer_data,
#' gyroscope_data,
#' time_filter = c(2,4),
#' detrend = TRUE,
#' frequency_filter = c(0.5, 25))
#'
#' tremor_features <- get_tremor_features(
#' accelerometer_data,
#' gyroscope_data,
#' window_length = 512,
#' window_overlap = 0.9)
#'
#' tremor_features <- get_tremor_features(
#' accelerometer_data,
#' gyroscope_data,
#' window_length = 256,
#' window_overlap = 0.2,
#' derived_kinematics = TRUE)
#'
#' tremor_features <- get_tremor_features(
Expand Down
28 changes: 9 additions & 19 deletions R/get_walk_features.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@
#' @examples
#' accelerometer_data = cbind(
#' t = walk_data$timestamp,
#' walk_data$userAcceleration)
#' walk_data$userAcceleration) %>%
#' dplyr::filter(t < 5)
#' gyroscope_data = cbind(
#' t = walk_data$timestamp,
#' walk_data$rotationRate)
#' walk_data$rotationRate) %>%
#' dplyr::filter(t < 5)
#'
#' walk_features <- get_walk_features(
#' accelerometer_data,
Expand All @@ -80,27 +82,15 @@
#' walk_features <- get_walk_features(
#' accelerometer_data,
#' gyroscope_data,
#' time_filter = c(2,8))
#'
#' walk_features <- get_walk_features(
#' accelerometer_data,
#' gyroscope_data,
#' detrend = TRUE)
#'
#' walk_features <- get_walk_features(
#' accelerometer_data,
#' gyroscope_data,
#' frequency_filter = c(0.5, 25))
#'
#' walk_features <- get_walk_features(
#' accelerometer_data,
#' gyroscope_data,
#' window_length = 512,
#' window_overlap = 0.9)
#' time_filter = c(2,4),
#' detrend = TRUE,
#' frequency_filter = c(0.5,25))
#'
#' walk_features <- get_walk_features(
#' accelerometer_data,
#' gyroscope_data,
#' window_length = 256,
#' window_overlap = 0.2,
#' derived_kinematics = TRUE)
#'
#' walk_features <- get_walk_features(
Expand Down
Binary file modified data/heartrate_data.rda
Binary file not shown.
10 changes: 3 additions & 7 deletions man/heartrate_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions mhealthtools.Rproj

This file was deleted.

Loading

0 comments on commit d32c7c9

Please sign in to comment.