Rank teams in the qualifying matches of an event by a scoring variable
Source:R/get_ranking_by.R
get_ranking_by.RdAll teams are ranked (if possible) by their contribution to the scoring variable.
Details
In order to model each team's contribution, a wide data set has to be constructed, with each
team as a variable, and each row as one of the alliances in one match and their score.
An alliance in a match consists of exactly three robots. This requirement is checked before modelling
and if not fulfilled, results in a warning.
A normal model is then fitted, or, if method = "loglinear" a log-linear model is fitted, if all values in the scoring variable are non-negative.
The coefficients of this model can be interpreted as the average (log) contribution of that
team to the score of a match. The OPR (offensive power rating) corresponds
to a call to get_ranking_by with score as the variable.
Examples
# example code
# get all matches for one event:
matches <- get_records("event/2024cttd/matches")
# get the score breakdown for each of the teams in each match
match_details <- get_match_details(matches)
library(dplyr, quietly=TRUE)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
# now get the contribution to the score:
match_details %>% filter(comp_level == "qm") %>% # get the qualifying matches
get_ranking_by(score)
#> # A tibble: 42 × 3
#> team_key n `rating(score)`
#> <chr> <int> <dbl>
#> 1 frc3284 8 44.6
#> 2 frc5126 8 35.6
#> 3 frc1108 8 31.6
#> 4 frc1987 8 30.7
#> 5 frc3928 8 28.1
#> 6 frc1986 8 26.8
#> 7 frc2357 8 26.8
#> 8 frc6424 8 24.9
#> 9 frc1769 8 23.9
#> 10 frc5801 8 23.9
#> # ℹ 32 more rows
# These coefficients correspond to the OPR
# additionally get the team contributions to the score without counting the opponents' fouls:
match_details %>% filter(comp_level == "qm") %>%
get_ranking_by(score, score-foulPoints)
#> # A tibble: 42 × 4
#> team_key n `rating(score)` `rating(score - foulPoints)`
#> <chr> <int> <dbl> <dbl>
#> 1 frc3284 8 44.6 30.1
#> 2 frc5126 8 35.6 22.9
#> 3 frc1108 8 31.6 32.4
#> 4 frc1987 8 30.7 27.5
#> 5 frc3928 8 28.1 24.1
#> 6 frc1986 8 26.8 28.7
#> 7 frc2357 8 26.8 23.1
#> 8 frc6424 8 24.9 28.7
#> 9 frc1769 8 23.9 12.9
#> 10 frc5801 8 23.9 21.0
#> # ℹ 32 more rows