Overview of the Quantified Self movement

quant_self

quant_self


The Quantified Self (QS) is a movement motivated to leverage the synergy of wearables, analytics, and “Big Data”. This movement exploits the ease and convenience of data acquisition through the internet of things (IoT) to feed the growing obsession of personal informatics and quotidian data. The website http://quantifiedself.com/ is a great place to start to understand more about the QS movement.

Watch once as attention to time a tool is everyone indispensable, but with the popularity of mobile phones, many people began to use a mobile phone to replace the watch time, however, the mobile phone function more complete, the watch still has its irreplaceability, due to the smaller, you can easily wear on your wrist and watches seem to be more convenient to carry, also because of this feature, it is endowed with new functions, born out of the smart watch this category. The smartwatch comes in a variety of rich, optional looks and has become a reliable fitness tracker. Now Smartwatch can do more and more things, like tracing user’s heart rate, sleep hour, activity, overall fitness level, playing music and so on.

Data preparation

Sample raw data of sleep data
Start_Time Minutes_Asleep Number_of_Awakenings Time_in_Bed Minutes_REM_Sleep Minutes_Light_Sleep Minutes_Deep_Sleep
2019-09-01 660 67 754 141 415 104
2019-09-02 394 44 438 93 245 56
2019-09-03 362 30 427 75 236 51
2019-09-05 731 62 838 169 406 156
2019-09-07 198 11 239 39 118 41
2019-09-08 484 44 551 111 290 83
2019-09-09 763 71 857 158 414 191
2019-09-10 345 30 421 28 272 45
2019-09-11 421 26 473 112 252 57
2019-09-12 419 28 490 76 266 77
2019-09-13 404 35 452 89 226 89
2019-09-14 446 36 497 110 301 35
2019-09-15 132 1 140 0 0 0
2019-09-16 209 23 247 10 150 49
2019-09-17 702 45 831 125 409 168

I have used the Fitbit versa in three months. I would like to know more about my sleep situation, so I downloaded my 2019 sleep data from fitbit.com. The data includes Start Time, End Time, Minutes Asleep, Minutes Awake, Number of Awakenings, Time in Bed, Minutes REM Asleep, Minutes Light Sleep, and Minutes Deep Sleep. Graph: https://arstechnica.com/gadgets/2019/09/fitbit-versa-2-review-a-solid-replacement-but-not-totally-remade/

Sleep minutes in last Three minutes


In the last three months, the average of sleep is 455 minutes and standard deviation is 176 minutes. The graph also show, the min. sleep time is 65 minutes and max. is 802.

Asleep VS Time in Bed

Minutes Asleep/REM/Deep/Light

Time in Bed Vs Deep_Sleep

linear graph for Time in Bed Vs Deep_Sleep

Conclusion

Based above analysis, I can know my sleep average is in the last three month, 455 minutes, standard deviation is 176 minutes, the min. sleep time is 65 minutes and max. is 802 minutes. If I spend more time on the bed, my deep sleep time will be longer.

---
title: "Sleep Time Analysis"
author: "Jia Zhao"
output: 
  flexdashboard::flex_dashboard:
    storyboard: true
    social: menu
    source: embed
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(flexdashboard)
library(dplyr)
library(tidyr)
library(sqldf)
library(ggplot2)
library(formattable)
library(knitr)
setwd("/Users/JZ/Desktop")
```

### Overview of the Quantified Self movement
![quant_self](/Users/JZ/Desktop/Fitbit.png)


***
The Quantified Self (QS) is a movement motivated to leverage the synergy of wearables, analytics, and “Big Data”. This movement exploits the ease and convenience of data acquisition through the internet of things (IoT) to feed the growing obsession of personal informatics and quotidian data. The website http://quantifiedself.com/ is a great place to start to understand more about the QS movement.

Watch once as attention to time a tool is everyone indispensable, but with the popularity of mobile phones, many people began to use a mobile phone to replace the watch time, however, the mobile phone function more complete, the watch still has its irreplaceability, due to the smaller, you can easily wear on your wrist and watches seem to be more convenient to carry, also because of this feature, it is endowed with new functions, born out of the smart watch this category. The smartwatch comes in a variety of rich, optional looks and has become a reliable fitness tracker. Now Smartwatch can do more and more things, like tracing user’s heart rate, sleep hour, activity, overall fitness level, playing music and so on.



```{r echo = FALSE,  message= FALSE}
data1 <- as.data.frame(read.csv("~/Desktop/fitbit_export_20191204 (1).csv"))
data2 <- as.data.frame(read.csv("~/Desktop/fitbit_export_20191204 (2).csv"))
data3 <- as.data.frame(read.csv("~/Desktop/fitbit_export_20191204 (3).csv"))
data <- merge(data1,data2, all = TRUE)
data <- merge(data, data3, all = TRUE)

names(data) <- c("Start_Time","End_Time","Minutes_Asleep" ,"Minutes_Awake","Number_of_Awakenings","Time_in_Bed", "Minutes_REM_Sleep", "Minutes_Light_Sleep","Minutes_Deep_Sleep")
```

### Data preparation

```{r echo = FALSE,  message= FALSE}
#sapply(data, class)
data[,1] <- as.character(data[,1])
data[,2] <- as.character(data[,2])

data[,1] <- substr(data[,1], 1, 10)
data[,2] <- substr(data[,2], 1, 10)


data <- data[,c(1,3:9)]

data <- sqldf("select Start_Time,
                        sum(Minutes_Asleep) as Minutes_Asleep,
                        sum(Number_of_Awakenings) as Number_of_Awakenings,
                        sum(Time_in_Bed) as Time_in_Bed,
                        sum(Minutes_REM_Sleep) as Minutes_REM_Sleep,
                        sum(Minutes_Light_Sleep) as Minutes_Light_Sleep,
                        sum(Minutes_Deep_Sleep) as Minutes_Deep_Sleep
                 from data
                 group by Start_Time
                ")

kable(data[1:15,], caption="Sample raw data of sleep data")
```
***
I have used the Fitbit versa in three months. I would like to know more about my sleep situation, so I downloaded my 2019 sleep data from fitbit.com. The data includes Start Time, End Time, Minutes Asleep, Minutes Awake, Number of Awakenings, Time in Bed, Minutes REM Asleep, Minutes Light Sleep, and Minutes Deep Sleep. Graph: https://arstechnica.com/gadgets/2019/09/fitbit-versa-2-review-a-solid-replacement-but-not-totally-remade/


### Sleep minutes in last Three minutes
```{r echo = FALSE,  message= FALSE}
data[,1] <- as.Date(data[,1])
ggplot(data = data, aes(x = Start_Time, y = Minutes_Asleep) ) + 
  geom_line(linetype = "dashed", color = "blue")+
  geom_point(color = "darkblue")
```


```{r echo = FALSE,  message= FALSE}
mean <- mean(data$Minutes_Asleep)
standard_deviation <- sd(data$Minutes_Asleep)
min. <- min(data$Minutes_Asleep)
max. <- max(data$Minutes_Asleep)
Summary <- cbind(mean,standard_deviation,min., max.)
```
***
In the last three months, the average of sleep is 455 minutes and standard deviation is 176 minutes. The graph also show, the min. sleep time is 65 minutes and max. is 802.

### Asleep VS Time in Bed

```{r echo = FALSE,  message= FALSE}
data2 <- data[,c(1,2,4)]
data3 <- data2 %>% gather(key = SleepType, minuts,2:3) 

ggplot(data = data3, aes(x = Start_Time, y = minuts, group = SleepType ) )+ 
  geom_line(aes(color = SleepType), linetype = "dashed")+
  geom_point(aes(color = SleepType))+
  theme(legend.position = "bottom") 
```

```{r echo = FALSE,  message= FALSE}
data2 <- data[,c(1,2,4)]
data3 <- data2 %>% gather(key = SleepType, minuts,2:3) 

ggplot(data = data3, aes(minuts, fill = SleepType ) )+ 
  geom_histogram(aes(color = SleepType))+
  theme(legend.position = "bottom")
```

### Minutes Asleep/REM/Deep/Light

```{r echo = FALSE,  message= FALSE}
data2 <- data[,c(1,2,5,6,7)]
data3 <- data2 %>% gather(key = SleepType, minuts,2:5) 

ggplot(data = data3, aes(x = Start_Time, y = minuts, group = SleepType ) )+ 
  geom_line(aes(color = SleepType), linetype = "dashed")+
  geom_point(aes(color = SleepType))+
  theme(legend.position = "bottom") 
```

### Time in Bed Vs Deep_Sleep

```{r echo = FALSE,  message= FALSE}
data2 <- data[,c(1,4,7)]
data3 <- data2 %>% gather(key = SleepType, minuts,2:3) 

ggplot(data = data3, aes(x = Start_Time, y = minuts, group = SleepType ) )+ 
  geom_line(aes(color = SleepType), linetype = "dashed")+
  geom_point(aes(color = SleepType))+
  theme(legend.position = "bottom") 
```

### linear graph for Time in Bed Vs Deep_Sleep

```{r echo = FALSE,  message= FALSE}
data2 <- data[,c(1,4,7)]

ggplot(data = data2, aes(x = Time_in_Bed, y = Minutes_Deep_Sleep) )+ 
  geom_point()+
  geom_smooth(method = "lm", se = TRUE)
```

### Conclusion

Based above analysis, I can know my sleep average is in the last three month, 455 minutes, standard deviation is 176 minutes, the min. sleep time is 65 minutes and max. is 802 minutes. If I spend more time on the bed, my deep sleep time will be longer.