Package 'ActivityIndex'

Title: Activity Index Calculation using Raw 'Accelerometry' Data
Description: Reads raw 'accelerometry' from 'GT3X+' data and plain table data to calculate Activity Index from 'Bai et al.' (2016) <doi:10.1371/journal.pone.0160644>. The Activity Index refers to the square root of the second-level average variance of the three 'accelerometry' axes.
Authors: Jiawei Bai [cre, aut] , John Muschelli [ctb]
Maintainer: Jiawei Bai <[email protected]>
License: GPL-3
Version: 0.3.7
Built: 2024-10-31 06:32:07 UTC
Source: CRAN

Help Index


Compute Activity Index

Description

computeActivityIndex computes the Activity Index using raw accelerometry data, based on user specified parameters such as sample rate and epoch length.

Usage

computeActivityIndex(x, x_sigma0 = NULL, sigma0 = NULL, epoch = 1, hertz)

## Default S3 method:
computeActivityIndex(x, x_sigma0 = NULL, sigma0 = NULL, epoch = 1, hertz)

## S3 method for class 'GT3XPlus'
computeActivityIndex(x, x_sigma0 = NULL, sigma0 = NULL, epoch = 1, hertz)

Arguments

x

An object containing raw accelerometry data, which could either be a 4-column data frame or "GT3XPlus" object. See "Details".

x_sigma0

A 4-column data frame containing the raw accelerometry data when the device is not worn. The 1st column has the record/index number. The 2nd to 4th columns contain the tri-axial raw acceleration. The data will be used to calculate σˉi\bar{\sigma}_i.

sigma0

Specify σˉi\bar{\sigma}_i directly. At least one of x_sigma0 and sigma0 must be specified. If both existed, sigma0 will be used.

epoch

The epoch length (in second) of the Activity Index. Must be a positive integer.

hertz

The sample rate of the data.

Details

x could be either of the following two types of objects:

  1. A 4-column data frame containing the tri-axial raw accelerometry data in the 2nd to 4th column, and the associated record number (could be time) in the 1st column. ReadTable can be used to generate such data frame.

  2. An "GT3XPlus" object given by function ReadGT3XPlus.

Value

A data frame with two columns. The first column has the "record number" associated with each entry of Activity Index, while the second column has the actual value of Activity Index.

Examples

library(graphics)
fname = system.file("extdata", "sample_table.csv.gz",
package = "ActivityIndex")
sampleTable = ReadTable(fname)
AI_sampleTable_x = computeActivityIndex(
  sampleTable,
  x_sigma0 = sampleTable[1004700:1005600, ],
  epoch = 1,
  hertz = 30)
AI_sampleTable_x
plot(AI ~ RecordNo, data = AI_sampleTable_x, type = "l")

Print method for token

Description

Print method for token

Usage

## S3 method for class 'ActivityIndex'
print(x, ...)

Arguments

x

an object used to select a method.

...

further arguments passed to or from other methods

Value

No return value, called for side effects

Examples

x = data.frame(RecordNo = rnorm(100), AI = rnorm(100))
class(x) = c("ActivityIndex", class(x))
print(x)

Read the raw tri-axial accelerometry data csv file by ActiGraph GT3X+.

Description

ReadGT3XPlus reads the accelerometry data collected by ActiGraph GT3XPlus in csv files generated by ActiLife software. It automatically parses the header of the csv file to acquire the setting of the device.

Usage

ReadGT3XPlus(filename, epoch = 1)

Arguments

filename

The name of the csv file.

epoch

The epoch length (in second) of the Activity Index. Must be a positive integer. The default is 1.

Details

The function is tested on the csv files generated by ActiLife6, which have exactly 10 lines of headers, containing information about the device name, the starting and ending date/time of data collection, the sample rate, and the downloading date/time, etc. The 11th may further be omitted, if it is the header for the tri-axial acceleration time series. The function only reads the first 3 columns from then, if more are present.

Value

The ReadGT3XPlus returns an object of class "GT3XPlus". This class of object is supported by functions computeActivityIndex. A object of class "GT3XPlus" is a list containing at least the following components:

SN: Serial Number of the accelerometer

StartTime: Start time of the data collection

StartDate: Start date of the data collection

Epoch: The Epoch time of each observation. If sample rate Hertz>1, then Epoch=00:00:00

DownloadTime: Download time of the data

DownloadDate: Download date the data

Hertz: Sampling Rate

Raw: a data frame with 5 columns containing the date, time and acceleration in X, Y and Z axes for each observation.

Examples

filename = system.file("extdata","sample_GT3X+.csv.gz",package="ActivityIndex")
res = ReadGT3XPlus(filename)

Read the raw tri-axial accelerometry data csv file.

Description

ReadTable reads the raw tri-axial accelerometry data in csv files.

Usage

ReadTable(filename)

Arguments

filename

The name of the csv file.

Details

The function reads csv files containing only three columns: acceleration time series of x-, y- and z-axis.

Value

The ReadTable returns a data frame with 4 columns: Index, X, Y and Z. Index is the column for the indices of acceleration. X, Y and Z are for the acceleration time series in each direction.

Examples

filename = system.file("extdata","sample_table.csv.gz",package="ActivityIndex")
res = ReadTable(filename)

σˉi\bar{\sigma}_i computing using raw accelerometry data

Description

Sigma0 computes σˉi\bar{\sigma}_i, which is needed for the Activity Index computing in computeActivityIndex

Usage

Sigma0(x, hertz = 30)

Arguments

x

A 4-column data frame containing the raw accelerometry data when the device is not worn. The 1st column has the record/index number. The 2nd to 4th columns contain the tri-axial raw acceleration. The data will be used to calculate σˉi\bar{\sigma}_i.

hertz

The sample rate of the data.

Value

σˉi\bar{\sigma}_i, a numeric vector of length one.

Examples

filename = system.file("extdata","sample_GT3X+.csv.gz",package="ActivityIndex")
res = ReadGT3XPlus(filename)
hertz = res$Hertz
x = res$Raw[ 1:1000, c("Time", "X", "Y", "Z")]
res = Sigma0(x, hertz = hertz)
testthat::expect_equal(res, c(SD = 0.184321637135534))

Time scale vector from 00:00:00 to 23:59:59.

Description

A vector of length 86400 containing the time scale characters from 00:00:00 to 23:59:59.

Format

A vector of characters with 86400 entries.