Fitbit Data Analysis

Fitbit Data Analysis

 You are provided fit bit data where you need to reward people from these 6 categories. You will need to identify:

  1. Most improved team over the six week period – this we will need to benchmark week on week to give a running commentary, so think of the average steps as of COB each Thursday week on week?
  1. Most improved participant in each state – should we do this on an average or on a literal basis? If we do this per participant then ask Tiff if we have a spreadsheet for which we can cross reference names and states 
  1. Most consistent individual – is it possible to calculate this from the data? It sounds hard to my non data mind 
  1. Most active participant overall – this one should be fairly easy (hopefully) is we simply sum active minutes per participant to see who is the highest?

This is only a sample data for 2 weeks. You have to build some formulas and a dashboard to identify these. Is there a way new data can be added in and it can automatically calculate the 4 requirements mentioned above.

These are what the columns means:

Column G – Steps – this should equate to what we can see in the dashboard in the challenge

Column O – Active minutes

Column R – Team name  

Solution 

Fitbit

Outputs are in bold, larger font, and bright red color.

fitbit<-read.csv(“fitbit.csv”)
fitbit<-subset(fitbit,!(is.na(Steps)))#Deleting NAs for Steps, since if no steps
#were recorded, that means there was no activity that day

groups<-levels(fitbit$Spring.Into)#Storing the various teams(column R)
k<-1
improv<-rep(NA,length(groups))#Vector where we will store improvement for each team
#We define improvement as increase in average number of steps from first day (30/10/2017)
#to last day (6/11/2017)
for(g in groups){
subs<-fitbit[which(fitbit$Spring.Into==g),]
s1<-subs[which(subs$Date==”30/10/2017″),]
low<-mean(s1$Steps)
s2<-subs[which(subs$Date==”6/11/2017″),]
high<-mean(s2$Steps)
improv[k]<-high-low
k<-k+1
}
options(warn=-1)
m<-which.max(improv)#Maximum improvement
cat(“Most improved group is”,groups[m])#Printing corresponding group name

## Most improved group is “Wealth Window Shoppers”

k<-1
part<-rep(NA,length(groups))#Participant with best improvement in respective team

for(g in groups){
subs<-fitbit[which(fitbit$Spring.Into==g),]
names<-levels(subs$UserID)
improv1<-rep(NA,length(names))
l<-1
for(n in names){ #Iterating through participants in current group
sub1<-subs[which(subs$UserID==n),]
s1<-sub1[which(sub1$Date==”30/10/2017″),]
high<-mean(s1$Steps)
s2<-sub1[which(sub1$Date==”6/11/2017″),]
low<-mean(s2$Steps)
improv1[l]<-high-low
if(is.na(improv1[l])){
improv1[l]<-0
}
l<-l+1
}
p<-which.max(improv1)#Finding participant with max improvement
part[k]<-names[p]
k<-k+1
}

out<-matrix(c(groups,part),length(groups),2)
cat(“Most improvement participants along with their groups are”)

## Most improvement participants along with their groups are

print(out)

##       [,1]                        [,2]    
##  [1,] “”                          “622DSSX”
##  [2,] “(C)olleagues.(M)ean.(B)us” “622DSSJ”
##  [3,] “Average Joes”              “622T7CX”
##  [4,] “Built for speed not dist.” “622X78D”
##  [5,] “Call me a Cab!!”           “622FFS7”
##  [6,] “Clown Town”                “622WKV8”
##  [7,] “Cool Runnings”             “622PSDS”
##  [8,] “CTMS”                      “622DG7L”
##  [9,] “DM TEAM”                   “622FJZS”
## [10,] “Drastic Steps”             “622FHHF”
## [11,] “East Coast Exercisers”     “622FNB8”
## [12,] “FANTASTIC 4”               “622TDMN”
## [13,] “Fit, Courageous and Ready” “622DG7L”
## [14,] “Foot Fetish”               “622R6FM”
## [15,] “Footloose”                 “622TDFD”
## [16,] “GB Corpse”                 “622DG7L”
## [17,] “GBMTour de fours”          “622TDPS”
## [18,] “Gee Up El CeeEmmers”      “622FJZR”
## [19,] “Happy Feet”                “622PKCJ”
## [20,] “Holywalkamolies”           “622THY5”
## [21,] “HSBC Rovers”               “622TNDZ”
## [22,] “Iron Ore-some”             “622T7DC”
## [23,] “JARS”                      “622TNDV”
## [24,] “Jeri & Co”                 “622R64N”
## [25,] “LAKSA”                     “622TRRR”
## [26,] “Mortgages 1”               “622THXK”
## [27,] “Mortgages 2”               “622DG7L”
## [28,] “Mortgages 3”               “622DG7L

## [29,] “Movers & Shakers”          “622XB28”
## [30,] “MRDN crew”                 “622TCD4”
## [31,] “NOT FAST JUST FURIOUS”     “622THWT”
## [32,] “Out of Step”               “622DG7L”
## [33,] “PC Panthers”               “622DST9”
## [34,] “Picante”                   “622TLQ9”
## [35,] “Pickleless”                “622TMN3”
## [36,] “Pratik’s Peeps”            “622TKY3”
## [37,] “Procrastinators 1”         “622W6XX”
## [38,] “Procrastinators 2”         “622DG7L”
## [39,] “Procrastinators 3”         “622SXYZ”
## [40,] “Red Hot Chilli Steppers”   “622TCD6”
## [41,] “Reservior Jogs”            “622TBYS”
## [42,] “Sole Mates”                “622FGG5”
## [43,] “Sole Survivors”            “622WKV3”
## [44,] “Stan Up and Walk”          “622F74Y”
## [45,] “Step Brothers”             “622WKVF”
## [46,] “Step Busters”              “622TLQB”
## [47,] “Step by Step”              “622TDMY”
## [48,] “Step Up Babes”             “622TJNZ”
## [49,] “Strolling Sandgropers”     “622DSRG”
## [50,] “Team FLASH”                “622X9M9”
## [51,] “The Alpha”                 “622TCKF”
## [52,] “The Bit Fits”              “622TB2M”
## [53,] “The Fittest Bits”          “622TGZR”
## [54,] “The Proclaimers”           “622TH2G”
## [55,] “The Scorpions”             “622DXNB”
## [56,] “The Trendsteppers”         “622TJQ7”
## [57,] “The Untouchables”          “622FL8Q”
## [58,] “The Walkers”               “622R6G4”
## [59,] “The Walkie Talkies”        “622THXD”
## [60,] “The Walking Shred”         “622SYYX”
## [61,] “Top Guns”                  “622THXT”
## [62,] “Un_patriot_like”           “622DG7L”
## [63,] “Unfit Misfits”             “622TDMC”
## [64,] “Walk This Way”             “622WQZW”
## [65,] “Walk to shops”             “622TS2D”
## [66,] “Walking for Wealth(+Hlth)” “622WYLG”
## [67,] “Wealth Walkers”            “622TM33”
## [68,] “Wealth Window Shoppers”    “622DG7L”
## [69,] “Weapons of Mass Reduction” “622DSSB”

## [70,] “Witness the Fitness”       “622TGZQ”
## [71,] “Wolf Pack”                 “622DG7L”

names1<-levels(fitbit$UserID)
#We define consistence as difference between max number of steps and min
#number of steps. Smaller the differnece more the consistency
const<-rep(NA,length(names1))
act<-rep(NA,length(names1))
k<-1
for(n in names1){
subs<-fitbit[which(fitbit$UserID==n),]
high<-max(subs$Steps)
low<-min(subs$Steps)
act[k]<-sum(subs$ActiveMinutes)#Activity defined as total active minutes
const[k]<-high-low
if(is.infinite((const[k]))){
const[k]<-Inf
}
k<-k+1
}
q<-which.min(const)
cat(“Most consistent individual is”,names1[q])

## Most consistent individual is “622RMZR”

r<-which.max(act)
cat(“Most active individual is”,names

[r]

)

## Most active individual is “622FL8Q”