-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsteps_to_photos.Rmd
121 lines (61 loc) · 1.5 KB
/
steps_to_photos.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
title: "Photos per steps"
output: html_notebook
---
```{r}
setwd('C:/Users/vale/Google Drive/apple_health_export/')
library(tidyverse)
library(brms)
library(brmstools)
```
```{r}
data <- read_csv('steps_per_day.csv')
```
```{r}
data %>%
filter(steps > 0) %>%
filter(!is.na(photos)) ->
data
```
```{r}
data %>% gather('key', 'value', -creationDate) %>%
ggplot(aes(x = creationDate, y = value)) +
geom_bar(stat = 'identity') +
facet_grid('key ~ .', scales='free_y') +
theme_minimal() +
labs(x = 'Date', y = 'Count', title='Daily steps and photos taken', subtitle = 'Sep 2017 - Mar 2019')
ggsave('days_and_photos.png')
```
```{r}
data %>% ggplot(aes(x = steps, y = photos)) +
geom_point() +
scale_y_log10() +
scale_x_log10() +
theme_minimal()
```
```{r}
fit1 <- brm('photos ~ log(steps)', family = poisson(), data = data)
```
```{r}
fit1
```
```{r}
marginal_effects(fit1, method = 'predict')
```
```{r}
fit1.pred <- predict(fit1)
```
```{r}
jdata <- bind_cols(data, as_tibble(fit1.pred))
```
```{r}
ggplot(data = jdata, aes(x = steps, y = photos)) +
geom_point() +
geom_ribbon(aes(ymin = Q2.5, ymax = Q97.5), alpha=0.1, fill='red') +
geom_line(color='red', size=0.5, aes(x = steps, y = Estimate)) +
scale_x_log10() +
scale_y_log10() +
theme_minimal() +
labs(x = 'Steps taken', y = 'Photos taken', title = 'Poisson regression', subtitle = '~ 50 more photos for every 10,000 steps')
ggsave('steps_to_photos_regression.png')
```