-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadme.Rmd
293 lines (225 loc) · 12.2 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
---
title: "rweighlighting"
author: "Nathan Chaney"
date: '`r format(Sys.Date(), "%B %d, %Y")`'
output: github_document
keep_md: TRUE
---
```{r Setup, include=FALSE, echo = FALSE}
knitr::opts_chunk$set(
echo = TRUE,
comment = "#>",
fig.path = "README-"
)
my.datadir <- "~/.bin/rweightlifting/inst/extdata/"
my.imagedir <- "~/.bin/rweightlifting/images/"
```
```{r Libraries, warning=FALSE, alert=FALSE, message=FALSE, include=F}
library(tidyverse)
library(data.table)
library(zoo)
library(rweightlifting)
```
# Introduction
The rweightlifting package is designed to assist weightlifters and their coaches with creating programs and monitoring trainees' progress. The package contains functions for calculating common variables used in barbell training, such as 1-rep max, N-rep max, training maxes, tonnage, etc. The package includes an interactive shiny dashboard that allows weightlifters to visualize progress and compare common training programs against past results.
# Reading Data
This package is designed for interactive use via the dashboard in the `shiny` directory. You'll need to point the data source for both weightlifting logs and body weight logs to the right directories to use the `shiny` app.
The `load_csv_data` function reads weightlifting logs. The expected format is one CSV file for each weightlifting program. The `load_csv_data` reads all CSV files in the specified directory. The function expects an input format that includes a header row, as follows:
`date, exercise, equipment, variant, set1weight, set1reps, set2weight, set2reps, ..., setNweight, setNreps`
```{r}
weightlifting.log <- load_csv_data(datadir = my.datadir)
```
```{r read weight data, echo=F, include=F}
ifelse(
dir.exists("/data/fitness/"),
weight.dir <- "/data/fitness/",
weight.dir <- "~/.fitness/Data/"
)
# Expects a CSV with date,weight as the header row
body.weight <- read.csv(paste(weight.dir, "body_weight.csv", sep=""), stringsAsFactors = FALSE)
body.weight$date <- as.Date(body.weight$date, "%Y-%m-%d")
# We're going to calculate a rolling mean for weight
# This allows us to calculates strength for dates where there's no weight measurement
all.dates <- data.frame(date = seq.Date(from = min(body.weight$date), to = Sys.Date(), by = 1))
body.weight <- body.weight %>%
full_join(all.dates, by = "date") %>%
arrange(date)
names(body.weight) <- c("date", "actual")
body.weight$rolling.weight <- rollapply(body.weight$actual, 7, mean, by = 1, fill = NA, na.rm = TRUE, align = "right", partial = T)
body.weight <- body.weight %>%
mutate(rolling.weight = ifelse(is.na(rolling.weight), NA, round(rolling.weight, 2)))
```
The function creates a data table with one set per row, as follows:
```{r, echo=F}
knitr::kable(tail(weightlifting.log, keepnums = FALSE))
```
# Visualizing Data
The dashboard provided in the `shiny` directory contains many available visualizations for common metrics used in weightlifting. A few examples are provided below.
## Diary View
This view shows each set performed; it is a way to show progress (and consistency) at a glance, as follows:
```{r sets_reps, echo = F, fig.width=10}
weightlifting.log %>%
filter(exercise %in% c("squat", "deadlift")) %>%
ggplot(aes(date, weight, color=interaction(equipment, variant), size=reps)) +
facet_wrap( ~ exercise, ncol = 1, scales = "free_y") +
geom_point(
aes(
date,
weight,
color = interaction(equipment, variant, lex.order = TRUE, sep = ","),
shape = reps > 0
),
alpha=0.33
) +
scale_shape_manual(values = c(4, 16)) +
scale_radius(range = c(1.5, 8), breaks=c(3,6,9,12,15)) +
scale_y_continuous(
position="right",
minor_breaks=function(x){
seq(0, ceiling(max(x)), 25)
}) +
scale_x_date(
date_breaks = "6 month", date_labels = "%b %Y",
date_minor_breaks = "2 month"
) +
labs(x = "", y = "") +
theme(
axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none"
) +
geom_vline(aes(xintercept = as.numeric(Sys.Date())), color=alpha("green", 0.5), linetype="dashed")
```
In this view, you can see that a linear progression program was followed at the beginning, followed by more complex programming over time. You can also see a gaps around January 2018 (when I tore my calf playing tennis) and April 2020 (when gyms were closed due to the COVID-19 pandemic). The colors indicate different exercise, equipment, and exercise variants. Missed attempts (i.e., reps = 0) are denoted with an X shape.
## Strength View
The strength view uses a caculated one-rep max to show progress in strength over time. It is a way to compare absolute strength across different set/rep schemes.
```{r absolute strength, fig.width=10, echo = F}
top_sets(weightlifting.log, use.method = "wathan") %>%
filter(exercise %in% c("squat", "bench", "press", "deadlift")) %>%
filter(equipment %in% c("barbell")) %>%
filter(variant %in% c("high bar", "low bar", "flat", "overhead", "conventional")) %>%
ggplot(aes(date, est.max)) +
geom_point(aes(fill = program, color = program), alpha = 0.5, stroke = 0, size = 2, na.rm = TRUE) +
geom_smooth(formula = y ~ x, method = "loess", se = TRUE, span = 0.25, na.rm = TRUE) +
facet_wrap(~ exercise, scales = "free_y") +
labs(y = "", x = "") +
scale_y_continuous(
position="right",
minor_breaks=function(x){
seq(0, ceiling(max(x)), 25)
}) +
scale_x_date(
date_breaks = "6 month", date_labels = "%b %Y",
date_minor_breaks = "2 month"
) +
theme(
axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none"
)
```
Broadly speaking, this view shows a lifter with increasing absolute strength over time. Bubbles of different colors denote different programs.
A similar view in the `shiny` app shows relative strength, which is obtained by dividing a calculated 1-RM by the lifter's body weight. This view is useful for comparing a lifter's performance to [strength standards](https://www.t-nation.com/training/are-you-strong/), which commonly reference multiples of body weight (e.g., 1x, 2x, 2.5x). It is also useful for monitoring performance across bulking or cutting cycles.
```{r relative strength, fig.width=10, echo = F}
top_sets(weightlifting.log, use.method = "wathan") %>%
rename(., lift.weight = weight) %>%
filter(exercise %in% c("squat", "bench", "press", "deadlift")) %>%
filter(equipment %in% c("barbell")) %>%
filter(variant %in% c("high bar", "low bar", "flat", "overhead", "conventional")) %>%
left_join(., body.weight, by = c("date" = "date")) %>%
mutate(strength.to.weight.ratio = round(est.max / rolling.weight, 3)) %>%
mutate(intensity = round(lift.weight / est.max, 3)) %>%
ggplot(aes(date, strength.to.weight.ratio)) +
geom_point(aes(fill = program, color = program,),
alpha = 0.5, na.rm = TRUE) +
geom_smooth(formula = y ~ x, method = "loess", se = TRUE, span = 0.25, na.rm = TRUE) +
facet_wrap(~ exercise, scales = "free_y") +
labs(y = "", x = "") +
scale_y_continuous(
position="right",
minor_breaks=function(x){
seq(0, ceiling(max(x)), 25)
}) +
scale_x_date(
date_breaks = "6 month", date_labels = "%b %Y",
date_minor_breaks = "2 month"
) +
theme(
axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none"
)
```
Note that the curves for absolute and relative strength are similar but not identical. As one example, the estimated 1RM for the deadlift has hovered around 500 - 525 since December 2018. However, the absolute strength has declined from a high of around 2.5x in June 2019 to around 2.3-2.4x as of the time of writing (this is attributable primarily to the, ahem, COVID nineteen pounds). I generally use the absolute strength view during bulking cycles (for comparison against all-time strength) and the relative strength view during cutting cycles (to make sure I'm not losing ground).
## Other Views
There are many other views shown in the dashboard located in the `shiny` directory. These include:
* Personal Records (PRs) by weight, program, tonnage, reps, and reps across
* Tonnage broken down by exercise, week, and day
* Ranges for weight and tonnage broken down by program
* Calendars that show lift days, weight PRs, tonnage PRs, and rep PRs
* A competition programming view to assist in selecting lifts for weightlifting competitions
# Creating a New Program
Weightlifters change programming periodically in order to accommodate different goals, such as to increase the amount of work performed, to change set/rep ranges, or to start fresh after a layoff due to illness. The rweightlifting package contains functions designed to assist the coach or lifter in preparing a new program. The starting position for the new program is tied to a specific percentage of the lifter's previous one-rep maximum, which is called the training max. For instance, a typical starting point after a week's vacation might set the training max at 90% of the lifter's calculated 1RM over the last month. The functions contain sensible defaults; the dashboard permits a user to adjust pertinent variables in order to get the desired level of difficulty.
For the lifter identified above, the package provides the following of a new program based on Jim Wendler's basic 3-week 5-3-1 program (this is the first week only):
```{r new_program, echo = F}
knitr::kable(
head(
rweightlifting::program_schedule("wendler_531", weightlifting.log) %>%
left_join(
weightlifting.log %>%
group_by(exercise, equipment, variant, weight) %>%
summarize(max.reps = max(reps), .groups = "drop")
, by = c("exercise", "equipment", "variant", "weight"))
, 12)
)
```
For convenience, we can also add the maximum number of reps at each specific weight the trainee is supposed to lift. This assists with giving the lifter a "rep PR" to shoot for each time in the gym, which is helpful for programs that recommend an AMRAP (as many reps as possible) scheme for work sets such as Wender 5-3-1.
This information can be displayed alongside historical training information to provide a visual representation of a new program's potential for gains over time:
```{r programming_sets_reps, echo = F, fig.width=10}
deload_cycles <- 3
rweightlifting::program_schedule("wendler_531", weightlifting.log, cycles = 12, deload_every = deload_cycles) %>%
mutate(
date = Sys.Date() + (cycle - 1) * wendler_531()$duration + (wendler_531()$deload_duration * ((cycle - 1) %/% as.numeric(deload_cycles))) + (day - 1)
) %>%
bind_rows(weightlifting.log) %>%
filter(exercise %in% c("squat", "deadlift")) %>%
ggplot(aes(date, weight, color=interaction(equipment, variant), size=reps)) +
facet_wrap( ~ exercise, ncol = 1) +
geom_point(
aes(
date,
weight,
color = interaction(equipment, variant, lex.order = TRUE, sep = ","),
shape = reps > 0
),
alpha=0.33
) +
scale_shape_manual(values = c(4, 16)) +
scale_radius(range = c(1.5, 8), breaks=c(3,6,9,12,15)) +
scale_y_continuous(
position="right",
breaks = function(x) {
seq(0, ceiling(max(x)), 100)
},
minor_breaks=function(x){
seq(0, ceiling(max(x)), 25)
}
) +
scale_x_date(
date_breaks = "6 month", date_labels = "%b %Y",
date_minor_breaks = "2 month"
) +
labs(x = "", y = "") +
theme(
axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none"
) +
geom_vline(aes(xintercept = as.numeric(Sys.Date())), color=alpha("green", 0.5), linetype="dashed")
```
The vertical green line represents today (currently `r format(Sys.Date(), "%d %b %Y")`); projected performance resulting from compliance with the new program is plotted to the right of the green line. Another feature displayed here is the ability to program deload weeks every so often -- in this case after every 3 cycles. Note that the projected work doesn't necessarily include accessory or supplemental work that may appear in historical data.
The supported programs include:
```{r programs, echo = F}
program_descriptions <- c()
for (i in available_programs()) {
program_descriptions <- c(program_descriptions, eval(call(i))$name)
}
program_descriptions
```
It is desired that future versions of the package's dashboard will permit creation of custom programs on an exercise-by-exercise basis.