Created
August 6, 2024 02:36
-
-
Save grantmcdermott/51bb7bbde38b977b6cbb211f3abae426 to your computer and use it in GitHub Desktop.
100 m pace equivalents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Context: https://bsky.app/profile/kjhealy.bsky.social/post/3kywqjin76i2r | |
library(rvest) | |
library(tinyplot) | |
tpar(grid = TRUE, las = 1, pch = 16) | |
# read the wiki page | |
wp = read_html("https://en.wikipedia.org/wiki/List_of_world_records_in_athletics") | |
# select the table of interest | |
dat = wp |> | |
html_element("div+ .wikitable :nth-child(1)") |> ## select table element | |
html_table() ## convert to data frame | |
# subset rows of interest | |
dat = dat |> | |
subset(grepl(" m$| km$|Mile$|marathon$|^Marathon", Event)) |> | |
subset(!grepl("relay", Event)) |> | |
subset(!(Event %in% c("1000 m", "2000 m", "Mile"))) |> # non-standard events | |
subset(Pts!="N/A") | |
# futzing to convert string times into consistent second measurements | |
dat = dat |> | |
transform(sec = ifelse(!grepl(":", Perf.), paste0("0:", Perf.), Perf.)) |> | |
transform(sec = ifelse(grepl("\\.", sec), paste0("0:", sec), sec)) |> | |
transform(sec = ifelse(!grepl("\\.", sec), paste0(sec, ".00"), sec)) |> | |
transform(sec = as.numeric(as.difftime(sec, format = "%H:%M:%OS"))) | |
# convert events into consistent m(etre) increments | |
dat = dat |> | |
transform(m = as.numeric(gsub(",| m$", "", Event))) |> | |
transform(m = ifelse( | |
Event=="Mile", | |
1600, | |
ifelse( | |
grepl("Half marathon", Event), | |
42195/2, | |
ifelse( | |
grepl("Marathon", Event), | |
42195, | |
m | |
) | |
) | |
)) | |
# 100m pace | |
dat = dat |> | |
transform(pace_100m = sec/m*100) | |
# quick plot | |
plt(pace_100m ~ m, dat, type = "b") | |
# looks like a linear-log model | |
mod = lm(pace_100m ~ log(m), dat) | |
pred = predict(mod, interval = "confidence") | |
dat = cbind(dat, pred) | |
# add predictions | |
with( | |
dat, | |
plt( | |
x = m, y = fit, ymin = lwr, ymax = upr, | |
type = "ribbon", col = "hotpink", | |
log = "x", | |
xlab = "Event distance (m), log scale", | |
ylab = "Average 100m pace (sec)", | |
main = "Who is the 'fastest'?" | |
) | |
) | |
with(dat, plt(m, pace_100m, type = "b", add = TRUE)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment