5 Running data analysis - StatisticalReinforcementLearningLab/HeartstepsV1Code GitHub Wiki

  1. Ensure your system has M+Box mounted.

  2. Start an R session.

  3. Run the following R commands, replacing LOCALPATH with the path to your local copy of the heartstepsdata git repository.

source("LOCALPATH/init.R")
load(paste0(sys.var$mbox.data, "analysis.RData")

If you do not have a local copy, run:

sys.var <- switch(Sys.info()["sysname"],
                  "Windows" = list(locale = "English",
                                   mbox = "Z:/HeartSteps/"),
                  "Darwin" = list(locale = "en_US",
                                  mbox = "/Volumes/dav/HeartSteps/"),
                  "Linux" = list(locale = "en_US.UTF-8",
                                 mbox = "~/mbox/HeartSteps/"))
sys.var$mbox.data <- paste0(sys.var$mbox, "Data/")
Sys.setlocale("LC_ALL", sys.var$locale)
Sys.setenv(TZ = "GMT")
load(paste0(sys.var$mbox.data, "analysis.RData"))

To recreate the data frame used in the main effects analysis, run the following code as well:

analysis.data <- function(days = 0:35, max.day = 41) {
  ids  <- unique(suggest$user[suggest$study.day.nogap == rev(days)[1] &
                                !is.na(suggest$study.day.nogap)])
  d <- subset(suggest, !is.na(study.day.nogap) & user %in% ids & 
           !(avail == F & send == T) & study.day.nogap <= max.day &
           !is.na(send.active),
         select = c(user, study.day.nogap, decision.index.nogap, decision.utime,
                    slot, study.date, intake.date, intake.utime, intake.slot,
                    travel.start, travel.end, exit.date, dropout.date,
                    last.date, last.utime, last.slot, recognized.activity,
                    avail, connect, send, send.active, send.sedentary, jbsteps10, 
                    jbsteps10.zero, jbsteps10.log, jbsteps30pre,
                    jbsteps30, jbsteps30pre.zero, jbsteps30.zero, 
                    jbsteps30pre.log, jbsteps30.log, jbsteps60pre,
                    jbsteps60, jbsteps60pre.zero, jbsteps60.zero, 
                    jbsteps60pre.log, jbsteps60.log, response, location.category, jbmins120, jbmins90))
  return(list(data = d, ids = ids))
}
days <- 0:35
primary <- analysis.data(days = days)
ids     <- primary$ids
primary <- primary$data