-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathREADME.Rmd
156 lines (119 loc) · 5.27 KB
/
README.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
---
output: github_document
---
# trackeR <img src="README_files/hex_trackeR.svg" width="320" align="right">
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/trackeR)](https://cran.r-project.org/package=trackeR)
[![Travis-CI Build Status](https://travis-ci.org/trackerproject/trackeR.svg?branch=master)](https://travis-ci.org/trackerproject/trackeR)
[![Coverage Status](https://coveralls.io/repos/github/trackerproject/trackeR/badge.svg?branch=master)](https://coveralls.io/github/trackerproject/trackeR?branch=master)
[![Licence](https://img.shields.io/badge/licence-GPL--3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html)
### Description
The purpose of this package is to provide infrastructure for handling
running, cycling, and swimming data from GPS-enabled tracking devices.
The formats that are currently supported for the training activity
files are .tcx (Training Center XML), Strava .gpx, .db3 and [Golden
Cheetah](http://goldencheetah.org) .json files. After extraction and
appropriate manipulation of the training or competition attributes,
the data are placed into session-based and unit-aware data objects of
class trackeRdata (S3 class). The information in the resultant data
objects can then be visualised, summarised, and analysed through
corresponding flexible and extensible methods.
### Current capabilities
Read:
- Read data from .tcx, Strava .gpx, .db3 or [Golden Cheetah](http://goldencheetah.org) .json files.
- Read all supported files in a specified directory.
Sports supported:
- Running
- Cycling
- Swimming
Data processing:
- Automatically identify sessions from timestamps.
- Imputation of data to characterise times when the device is paused or remains stationary.
- Correction of GPS-measured distances using elevation data.
- Basic data cleaning capabilities e.g., no negative speeds or distances.
- Specify and conveniently change units of measurement.
- Organise data into session-based and unit-aware data objects of class trackeRdata.
Analysis:
- Session summaries: distance, duration, time moving, average speed/pace/heart
rate/cadence/power (overall and moving), work to rest ratio, temperature.
- Time spent exercising in user-supplied zones, e.g., heart rate zones or speed zones.
- Work capacity above critical power (W', W prime)
- Distribution profiles: time spent exercising above thresholds of training attributes.
- Concentration profiles: negative derivatives of distribution profiles.
- Functional principal components analysis of distribution and concentration profiles.
Visualisation:
- Plot session progression in, e.g., pace, heart rate, etc.
- Plot route covered during session on static and interactive maps from various providers.
- Plot session summary statistics.
- Plot date time of sessions in timeline plots.
- Plot time spent exercising in zones.
- Plot distribution/concentration profiles.
- Plot principal components of distribution/concentration profiles.
- Ridgeline (or joy) plots for distribution/concentration profiles.
### Installation
Install the released version from CRAN:
```{r, eval = FALSE}
install.packages("trackeR")
```
Or the development version from github:
```{r, eval = FALSE}
# install.packages("devtools")
devtools::install_github("trackerproject/trackeR")
```
### Example
Plot workout data
```{r, plots, message = FALSE, fig.height = 6.5}
data(runs, package = "trackeR")
plot(runs, session = 1:5, what = c("speed", "pace", "altitude"))
```
Change the units
```{r, plots_new, message = FALSE, fig.height = 6.5}
data(runs, package = "trackeR")
runs0 <- change_units(runs,
variable = c("speed", "altitude"),
unit = c("km_per_h", "ft"),
sport = c("running", "running"))
plot(runs0, session = 1:5, what = c("speed", "pace", "altitude"))
```
Summarise sessions
```{r, summary, message = FALSE, fig.height = 6.5}
library("trackeR")
runs_summary <- summary(runs)
plot(runs_summary, group = c("total", "moving"),
what = c("avgSpeed", "distance", "duration", "avgHeartRate"))
```
Generate distribution and concentration profiles
```{r, cprofile, fig.width = 9}
runsT <- threshold(runs)
dp_runs <- distribution_profile(runsT, what = c("speed", "heart_rate"))
dp_runs_smooth <- smoother(dp_runs)
cp_runs <- concentration_profile(dp_runs_smooth)
plot(cp_runs, multiple = TRUE, smooth = FALSE)
```
A ridgeline plot of the concentration profiles
```{r, cprofile-ridges, warning = FALSE, fig.width = 9}
ridges(cp_runs, what = "speed")
```
```{r, cprofile-ridges-hr, warning = FALSE, fig.width = 9}
ridges(cp_runs, what = "heart_rate")
```
Explore concentration profiles for speed, e.g., via functional principal
components analysis (PCA)
```{r, funPCA, fig.width = 7, fig.height = 7}
## fit functional PCA
cp_PCA <- funPCA(cp_runs, what = "speed", nharm = 4)
## pick first 2 harmonics/principal components
round(cp_PCA$varprop, 2)
## plot harmonics
plot(cp_PCA, harm = 1:2)
```
```{r, scores}
## plot scores vs summary statistics
scores_SP <- data.frame(cp_PCA$scores)
names(scores_SP) <- paste0("speed_pc", 1:4)
d <- cbind(runs_summary, scores_SP)
library("ggplot2")
## pc1 ~ session duration (moving)
ggplot(d) + geom_point(aes(x = as.numeric(durationMoving), y = speed_pc1)) + theme_bw()
## pc2 ~ avg speed (moving)
ggplot(d) + geom_point(aes(x = avgSpeedMoving, y = speed_pc2)) + theme_bw()
```