##
## Example 1: Loading the activity counts data using readCounts function
##
## Not run:
# library(acc)
# infile <- "DataName.dat"
# counts <- readCounts(infile)
#
#
# ##
# ## Example 2: Summarizing accelerometer data for a sedentary individual"
# ##
#
# # For this example, data is generated using a Hidden Markov model
# # First, a sequence of time is generated
# randomTime <- seq(ISOdate(2015,4,1),ISOdate(2015,4,3),"min")
# # Load the mhsmm package to generate data using a Hidden Makov model
# library(mhsmm)
# # It is assumed that the counts are generated from a Hidden Markov model
# # with three states, being non-wear, sedentary, and moderate-vigorous activity
# J <- 3; initial <- rep(1/J, J)
# # Set up a transition matrix for the Hidden Markov model.
# P <- matrix(c(0.95, 0.04, 0.01,
# 0.09, 0.9, 0.01,
# 0.1, 0.2, 0.7), byrow='TRUE',nrow = J)
# # It is assumed that the counts are realized from a mixture of
# # two normal distributions (for sedentary activity and mvpa)
# # and a constant at zero (for non-wear time).
# b <- list(mu = c(0, 30, 2500), sigma = c(0, 30, 1000))
# model <- hmmspec(init = initial, trans = P, parms.emission = b,dens.emission = dnorm.hsmm)
# # Generate data!
# train <- simulate.hmmspec(model, nsim = (60*24*2), seed = 1234, rand.emis = rnorm.hsmm)
# # Now set up a dataset that mimicks the accelerometry data
# counts <- data.frame(TimeStamp = randomTime[1:length(train$x)], counts = train$x)
# library(acc)
# # summarize the data using the acc function.
# # Sedentary and moderate-vigorous activity is summarized, using Freedson's cut points by default.
# # Option returnbout='TRUE' returns a more detailed information on how the summary was calculated.
# summary1 <- accSummary(data=counts, tri='FALSE', axis=NULL,
# spuriousDef=20, nonwearDef=60, minWear=600,
# patype='MVPA',pacut=c(1952,Inf),
# boutsize=10, tolerance='TRUE',returnbout='TRUE')
# summary1$validDates # This returns the same summary as when returnbout='FALSE'
# # summary1$PA # This returns the activity classification and bout information
#
# ##
# ## Example 3: Summarizing accelerometer data for an active individual.
# ##
#
# randomTime <- seq(ISOdate(2015,4,1),ISOdate(2015,4,3),"min")
# library(mhsmm)
# J <- 3; initial <- rep(1/J, J)
# P <- matrix(c(0.95, 0.04, 0.01,
# 0.09, 0.7, 0.21,
# 0.1, 0.1, 0.8), byrow='TRUE',nrow = J)
# b <- list(mu = c(0, 30, 2500), sigma = c(0, 30, 1000))
# model <- hmmspec(init = initial, trans = P, parms.emission = b,dens.emission = dnorm.hsmm)
# train <- simulate.hmmspec(model, nsim = (60*24*2), seed = 1234, rand.emission = rnorm.hsmm)
#
# counts <- data.frame(TimeStamp = randomTime[1:length(train$x)], counts = train$x)
# library(acc)
# # Option returnbout='TRUE' returns a more detailed information on how the summary was calculated.
# summary2 <- accSummary(data=counts, tri='FALSE', axis=NULL,
# spuriousDef=20, nonwearDef=60, minWear=600,
# patype='MVPA',pacut=c(1952,Inf),
# boutsize=10, tolerance='TRUE',returnbout='TRUE')
# summary2$validDates # This returns the same summary as when returnbout='FALSE'
# # summary2$PA # This returns the activity classification and bout information
#
# ## End(Not run)
Run the code above in your browser using DataLab