Reading csv files with raw data in GGIR"

knitr::include_graphics("GGIR-MASTERLOGO-RGB.png")
knitr::opts_chunk$set(echo = TRUE)

See also complementary vignettes on: General introduction to GGIR, Cut-points, Day segment analyses, GGIR parameters, and Embedding external functions (pdf).

Introduction

GGIR can automatically read data from the most-frequently used accelerometer brands in the field:

However, the accelerometer manufacturers are proliferating with an increasing number of brands in the market. For such reason, GGIR includes the read.myacc.csv function, which is able to read accelerometer raw triaxial data stored in csv files, independently of the brand. This vignette provides a general introduction on how to use GGIR to read accelerometer raw data stored in csv files.

How it works:

Internally GGIR loads csv files with accelerometer data and standardises the output format to make the data compatible with other GGIR functions. Data format standardisation includes unit of measurement, timestamp, header format, and column locations.

The read.myacc.csv function

As for the rest of GGIR functions, read.myacc.csv is intended to be used within function GGIR. All the arguments of the read.myacc.csv can be easily recognized as they all start by "rmc". The GGIR function checks whether the argument rmc.firstrow.acc is provided by the user; in such case, GGIR will derive the reading of the data to the read.myacc.csv.

Input arguments

As the read.myacc.csv function tries to read csv files with a wide variety of formats, the key arguments to specify depend on the characteristics of the csv file to process. Overall, if an argument is not relevant, it should be left in default setting (e.g., if the csv file does not contain temperature data, the arguments related to temperature settings should be left in default values).

Below we present a summary of the available input arguments. Please see the parameters vignette for a more elaborate description of these input arguments. Further, the arguments are also covered by the function documentation for the read.myacc.csv function.

General arguments

Arguments for files containing a header {#header}

Arguments for files including timestamps

Arguments for files with acceleration stored in bits

Arguments for files including temperature

Arguments for files including wear time information

Arguments to find time gaps and resampling

Usage of the read.myacc.csv function

This section shows an example real case in which the read.myacc.csv function can be used. The csv file to be read has the following structure:

dateTime | acc_x | acc_y | acc_z | ambient_temp ---|---|---|---|--- 1/1/2022 16:48:26.000|-0.42041016|0.41114536|-0.76733398|24 1/1/2022 16:48:26.009|-0.41674805|0.40919218|-0.76611328|24 1/1/2022 16:48:26.019|-0.42407227|0.40845973|-0.77539062|24 1/1/2022 16:48:26.029|-0.41894531|0.41163366|-0.77246094|24 1/1/2022 16:48:26.039|-0.4206543|0.41749321|-0.76806641|24 1/1/2022 16:48:26.049|-0.42163086|0.42091128|-0.76757812|24 1/1/2022 16:48:26.059|-0.42236328|0.41627247|-0.76391602|24 1/1/2022 16:48:26.069|-0.42431641|0.4189581|-0.76171875|24 1/1/2022 16:48:26.079|-0.42138672|0.41993469|-0.76513672|24

This file contains timestamps in the column 1 (formatted as "%d/%m/%Y %H:%M:%OS"), the acceleration signals (in g's) for the x, y, and z axis in the columns 2, 3, and 4, respectively, and temperature information in Celsius in the column 5. Also, this file has no header.

First, we test read this file using the read.myacc.csv function in GGIR as follows.

```{R,eval=FALSE} library(GGIR) read.myacc.csv(rmc.file = "C:/mystudy/mydata/datafile.csv", rmc.nrow = Inf, rmc.skip = 0, rmc.dec = ".", rmc.firstrow.acc = 2, rmc.col.acc = 2:4, rmc.col.temp = 5, rmc.col.time=1, rmc.unit.acc = "g", rmc.unit.temp = "C", rmc.unit.time = "POSIX", rmc.format.time = "%d/%m/%Y %H:%M:%OS", rmc.desiredtz = "Europe/London", rmc.sf = 100)

## Example using the shell function

If the `rmc.firstrow.acc` argument is defined within the `GGIR` function, then the data will be read through `read.myacc.csv`. GGIR needs the user to specify in which row starts the accelerometer data within the csv, so this argument must be always explicitly specified by the user. Thus, a call to the `GGIR` including the rmc arguments would look as follows (note that the `rmc.file`, `rmc.nrow`, and `rmc.skip` arguments will not be used by `GGIR` as these arguments are already defined by `datadir`, `strategy`, and [header](#header) arguments, respectively).

```{R,eval=FALSE}
library(GGIR)
GGIR(
             mode=c(1,2,3,4,5),
             datadir="C:/mystudy/mydata/datafile.csv",
             outputdir="D:/myresults",
             do.report=c(2,4,5),
             #=====================
             # read.myacc.csv arguments
             #=====================
             rmc.nrow = Inf, 
             rmc.dec = ".",
             rmc.firstrow.acc = 2, 
             rmc.col.acc = 2:4, 
             rmc.col.temp = 5, 
             rmc.col.time=1,
             rmc.unit.acc = "g", 
             rmc.unit.temp = "C", 
             rmc.unit.time = "POSIX",
             rmc.format.time = "%d/%m/%Y %H:%M:%OS",
             rmc.desiredtz = "Europe/London",
             rmc.sf = 100,
             rmc.noise = 0.013
)
knitr::include_graphics("GGIR-MASTERLOGO-RGB.png")


Try the GGIR package in your browser

Any scripts or data that you put into this service are public.

GGIR documentation built on Oct. 17, 2023, 1:12 a.m.