Sage-Bionetworks / mhealthtools

A modular R package for extracting features from mobile sensor data
Apache License 2.0
13 stars 10 forks source link

get_tremor_features: Obscure error list #180

Closed itismeghasyam closed 5 years ago

itismeghasyam commented 5 years ago

Motivation

I recently ran into an error while analyzing a batch of rest tremor records, where I am subsetting a 10s tremor file between 2s and 9s, and then processing using ddply.

Some records, even though stored as a valid JSON, are not 10s long. One of them had 39 samples (~ 0.4 s at 100Hz sampling rate), another just 5 samples! (Must have been some error on the app side to even consider this). These records were causing issues with the set of parameters I was using for input to get_tremor_features(). I tested a few sets of parameters and figured out the following setups that do not work as intended

This is also true for get_kinetic_tremor_features(), I believe the problem lies deep down in the sensor modules.

Error list

Setup environment

library(mhealthtools)
library(tidyverse)

# Subsetting our data to a smaller time window(0-1s) to emulate the incompletion
# of a record. We need a 10s tremor record, for which we are removing the 
# first two seconds and the last second, ie., (2,9)s, to remove any 
# activity start/end errors
miniAccel <- mhealthtools::accelerometer_data %>% 
  dplyr::filter(t < 1)
miniGyro <- mhealthtools::gyroscope_data %>% 
  dplyr::filter(t < 1)

Error 1

# This should be a empty feature list, with an error, but is not
# The issue is related to time_filter parameter
tremorFeatures1 <- mhealthtools::get_tremor_features(
  accelerometer_data = miniAccel,
  gyroscope_data = miniGyro,
  time_filter = c(2,9)
)

Error 2

# This should also be an empty feature list, with an error, but
# throws an error and does not execute
# The issue is confounded with time_filter and detrend parameters
tremorFeatures2 <- mhealthtools::get_tremor_features(
  accelerometer_data = miniAccel,
  gyroscope_data = miniGyro,
  time_filter = c(2,9),
  detrend = T
)

Error 3

# This should also be an empty feature list, with an error, but
# throws a different error than before and does not execute
# The issue is compounded with time_filter and IMF parameters
tremorFeatures3 <- mhealthtools::get_tremor_features(
  accelerometer_data = miniAccel,
  gyroscope_data = miniGyro,
  time_filter = c(2,9),
  IMF = 2
)

Error 4

# Data that is DISMAL < i.e say ~10 samples)
miniAccel <- mhealthtools::accelerometer_data %>% 
  dplyr::filter(t < 0.1)
miniGyro <- mhealthtools::gyroscope_data %>% 
  dplyr::filter(t < 0.1)

# This should also be an empty feature list, with an error, but
# throws a different error than before and does not execute.
# The issue here is from the IMF parameter, if that is removed
# no problems, runs smoothly
tremorFeatures <- mhealthtools::get_tremor_features(
  accelerometer_data = miniAccel,
  gyroscope_data = miniGyro,
  frequency_filter = c(1,25),
  IMF = 2
)
philerooski commented 5 years ago

Errors 1-3 are a side effect of filter_time not returning an error dataframe if none of the data fits between the bounds. Error 4 is a separate issue most likely related to other errors we've had with unrealistically small inputs.

I'm going to label this as critical since it's a small fix for errors 1-3 and file a separate issue for Error 4.