segmentation: Perform Segmentation on GENEActiv Accelerometer Data

View source: R/segmentation.R

segmentationR Documentation

Perform Segmentation on GENEActiv Accelerometer Data

Description

Perform segmentation of Activinsights accelerometer data. Data are smoothed by the second, or by 10 data points, whichever number of records is greater.

Filtering is performed by tools from waveslim. Options are passed to wavelet.filter.

Usage

segmentation(
  data,
  outputfile = "detectedChanges",
  outputdir = "GENEAclassification",
  datacols = "default",
  decimalplaces = "default",
  filterWave = FALSE,
  filtername = "haar",
  j = 8,
  changepoint = c("UpDownDegrees", "TempFreq", "UpDownFreq", "UpDownMean", "UpDownVar",
    "UpDownMeanVar", "DegreesMean", "DegreesVar", "DegreesMeanVar",
    "UpDownMeanVarDegreesMeanVar", "UpDownMeanVarMagMeanVar", "RadiansMean",
    "RadiansVar", "RadiansMeanVar", "UpDownMeanDegreesVar"),
  penalty = "Manual",
  pen.value1 = 40,
  pen.value2 = 400,
  intervalseconds = 30,
  mininterval = 5,
  samplefreq = 100,
  filterorder = 2,
  boundaries = c(0.5, 5),
  Rp = 3,
  plot.it = FALSE,
  hysteresis = 0.1,
  stft_win = 10,
  verbose = FALSE,
  verbose_timer = FALSE,
  ...
)

Arguments

data

the GENEActiv bin object to be segmented which should be the output of the dataImport function.

outputfile

single character, file name for saving the segmentation output as CSV (and if plot.it is TRUE, corresponding plot PNG). If NULL, create no files.

outputdir

single character, the absolute or relative path to directory in which plot and changes files) should be created, or NULL (default "GENEAclassification"). Ignored if outputfile is NULL.

datacols

character vector constructed 'column.summary'. This object specifies the data and summary to output for the classification. The first part of each element must name column in the GENEAbin datasets specified by filePath. Derived columns may also be selected:

  • Step (zero-crossing step counter method),

  • Principal.Frequency.

The second should be the name of a function that evaluates to lenth one. The functions must contain only alphabetical characters (no numbers, underscores or punctuation). The default matrix, specified using the length 1 character vector 'default' is:

  • UpDown.mean

  • UpDown.sd

  • UpDown.mad

  • Degrees.mean

  • Degrees.var

  • Degrees.sd

  • Light.mean

  • Light.max

  • Temp.mean

  • Temp.sumdiff

  • Temp.meandiff

  • Temp.abssumdiff

  • Temp.sddiff

  • Magnitude.mean

  • Step.GENEAcount

  • Step.sd

  • Step.mean

  • Step.GENEAamplitude

  • Step.GENEAwavelength

  • Principal.Frequency.median

  • Principal.Frequency.mad

  • Principal.Frequency.ratio

  • Principal.Frequency.sumdiff

  • Principal.Frequency.meandiff

  • Principal.Frequency.abssumdiff

  • Principal.Frequency.sddiff

decimalplaces

named numeric vector of decimal places with which to round summary columns. NULL returns unrounded values. The length 1 character vector 'default' applies default roundings:

  • Start.Time = 0,

  • Degrees.mean = 3,

  • Degrees.median = 3,

  • Degrees.var = 3,

  • Degrees.sd = 3,

  • Degrees.mad = 3,

  • Magnitude.mean = 3,

  • UpDown.mean = 3,

  • UpDown.median = 3,

  • UpDown.var = 3

  • UpDown.sd = 3,

  • UpDown.mad = 3,

  • Principal.Frequency.median = 3,

  • Principal.Frequency.mad = 3,

  • Principal.Frequency.ratio = 3,

  • Principal.Frequency.sumdiff = 3,

  • Principal.Frequency.meandiff = 3,

  • Principal.Frequency.abssumdiff = 3,

  • Principal.Frequency.sddiff = 3,

  • Light.mean = 0,

  • Light.max = 0,

  • Temp.mean = 1,

  • Temp.sumdiff = 3

  • Temp.meandiff = 3

  • Temp.abssumdiff = 3

  • Temp.sddiff = 3

  • Step.GENEAcount = 0

  • Step.sd = 1

  • Step.mean = 0

filterWave

single logical, should a smoothing filter from wave.filter be applied? (default FALSE).

filtername

single character, the name of the wavelet to use for smoothing when filter is TRUE. (default "haar") Passed to link[waveslim]{wave.filter}.

j

single numeric, the level to which to smooth. Passed to link[waveslim]{wave.filter} (default 8).

changepoint

defines the change point analysis to use. UpDownDegrees performs the change point analysis on the variance of arm elevation and wrist rotation. TempFreq performs a change point on the variance in the temeprature and frequency (Typically better for sleep behaviours).

penalty

single characgter, the penalty to use for changepoint detection. default ("SIC").

pen.value1

Value of the type 1 error required when penalty is "Asymptotic".

pen.value2

Default set as NULL and so equals pen.value1 if no input.

intervalseconds

An integer number of seconds between 5 and 30 during which at most one changepoint may occur.

mininterval

single numeric that defines the smallest changepoint initially found. Passed to cpt.var as the variable minseglen

samplefreq

The sampling frequency of the data, in hertz, when calculating the step number. (default 100).

filterorder

The order of the filter applied with respect to the butter or cheby options if stepCounter is used. The order of the moving average filter if step counter 2 is used. See cheby1 or butter.

boundaries

to pass to the filter in the step counting algorithm.

Rp

the decibel level that the cheby filter takes. See cheby1.

plot.it

single logical, Creates a plot showing the zero crossings counted by the step counting algorithm#' @param Centre Centres the xz signal about 0 when set to True.

hysteresis

The hysteresis applied after zero crossing. (default 100mg)

stft_win

numeric for the window to calculate the frequency of an event using the stft function.

verbose

single logical to print additional progress reporting (default FALSE).

verbose_timer

single logical tp print additional progress reporting on time for each section of the function (default FALSE).

...

other arguments to be passed to dataImport, segmentation and other functions with these functions.

Details

Performs the segmentation procedure on the provided elevation data. Optionally a wavelet filter is first applied to smooth the data. The number of changes occuring in a given number of seconds may be controlled using the intervalseconds argument. Changes will be removed based on which segments are the closest match in terms of variance. A series of features for each of the segments will then be calculated and returned as a csv file.

Value

The segment data are returned invisibly. This data frame has columns:

  • Serial.Number

  • Start.Time

  • Segment.Start.Time

  • Segment.Duration

  • UpDown.median

  • UpDown.var

  • Degrees.median

  • Degrees.mad

In addition, the requested columns are included. Optionally, as a side effect a csv file is returned listing all of the segments found in the data along with a variety of features for that segment. Optionally a png file plotting the data and the detected changes can also be produced.

Examples

### Load the data to segment keeping only the first quarter of the data
## library(GENEAread)
## testfile = file.path(system.file(package = "GENEAread"),
##                                  "binfile",
##                                  "TESTfile.bin")
## segData <- dataImport(binfile = testfile,
##     downsample = 100, start = 0, end = 0.25)
## head(segData)
### Run loaded data through segmentation function
## segment <- segmentation(data = segData, outputfile = NULL)
## head(segment)
## segment2 <- segmentation(data = segData, outputfile = NULL,
##     datacols = "Degrees.skew")
## head(segment2)

GENEAclassify documentation built on March 31, 2023, 9:01 p.m.