Functions to implement four ways to calculate the points awarded for a dive in a diving competition, including the way that is used in the Olympic Games.
dmean(
x,
DD = "DD",
scores = paste0("J", 1:7),
trim = 2/7,
replace = TRUE,
reorder = TRUE
)
dmedian(
x,
DD = "DD",
scores = paste0("J", 1:7),
type = 6,
replace = TRUE,
reorder = TRUE
)
dmode(x, DD = "DD", scores = paste0("J", 1:7), replace = TRUE, reorder = TRUE)
tables(x, type = 1, diverRanks = 1)
A numeric matrix or data frame, ideally of the same format as
daley
.
A character (or numeric) scalar giving the column name (or number)
of x
that contains the DD (degree of difficulty) values of each
dive. The default is set up to work with the data in
daley
.
A character (or numeric) vector giving the column names (or
numbers) of x
that contain the 7 scores for each dive. The default
is set up to work with the data in daley
.
Only relevant to divemean
. Passed to mean
.
The default, trim = 2 / 7
, corresponds to the calculation using in
diving competitions.
A logical scalar. If replace = FALSE
then a vector
of the dive points is returned. If replace = TRUE
then the
DivePoints
, DiveRank
, TotalPoints
, OverallRank
and PointsBehind
columns are updated in light of the new values of
the dive points and this data frame is returned. If any of these named
columns do not exist then the returned object is the same as the
replace = FALSE
case.
A logical scalar. If replace = TRUE
then
reorder
determines whether the order of the divers is changed
to reflect the new values of TotalPoints
at the end of the
competition.
Determines the form of a data frame returned as a summary table.
type = 0
: Rank, Name, NOCcode (Country), TotalPoints at the
end of the competition.
type = 1
: DD, J1-J7 and dive points (those already in
x
).
type = 2
: like type = 1
but gives dive points, and
points based on the mean, median and mode.
type = 3
: like type = 2
but gives only the total
points accumulated over the competition, ordered by dive points.
type = 4
: like type = 3
but totals are replaced by
ranks.
The ranks of the divers that should be included in a
table. For example, diverRanks
gives the medalists.
A numeric vector dive points if replace = FALSE
or x
does not have appropriately named columns. Otherwise, a dataframe of the
same structure as x
in which the columns DivePoints
,
DiveRank
, TotalPoints
, OverallRank
and
PointsBehind
have been updated in light of the new dive points
values.
In the default case, e.g. dmean(daley)
, the 2 smallest and
2 largest scores of the 7 scores are removed; the sum of the 3 remaining
scores is calculated; and the result is multiplied by the dive's
degree of difficulty.
Another way to think of this is that we take the sample mean of the 3 middle scores, then multiply by 3, then multiply by the degree of difficulty.
In the dmean(daley, trim = 0)
case we take the sample mean of all
7 scores, then multiply by 3, then multiply by the degree of difficulty.
That is, we do not trim the 2 smallest and 2 largest values.
Similarly, in the dmedian(daley)
and dmode(daley)
cases we
take the sample median or mode, respectively, of all 7 scores, then
multiply by 3, then multiply by the degree of difficulty. If there is more
than one sample mode then we use the sample mean of these modes.
daley
for Tokyo 2020 Olympics Diving Men's
Individual 10m platform final results
# The calculation used in competitions (trimmed sample sums)
dmean(daley, replace = FALSE)
#> [1] 102.00 81.60 97.20 97.20 101.75 102.60 90.10 94.50 89.25 91.20
#> [11] 102.60 112.75 98.60 91.20 91.80 80.50 94.35 91.80 75.20 91.80
#> [21] 85.75 81.00 94.35 86.40 68.80 91.80 91.80 73.80 83.25 86.40
#> [31] 83.20 79.20 88.20 56.10 75.00 80.00 72.00 86.40 75.85 86.40
#> [41] 35.70 75.60 57.60 61.20 74.25 76.50 72.00 88.80 68.80 72.60
#> [51] 39.60 88.80 69.70 68.40 60.80 79.20 46.20 79.55 56.10 72.00
#> [61] 67.20 59.40 48.60 69.70 66.60 72.15 67.20 59.40 59.50 42.50
#> [71] 72.15 81.00
#> attr(,"statistic")
#> [1] "DivePoints"
# An equivalent calculation without trimming
dmean(daley, replace = FALSE, trim = 0)
#> [1] 100.54286 82.28571 96.42857 97.20000 102.27857 104.14286 88.88571
#> [8] 93.00000 89.25000 92.01429 103.37143 113.33571 97.62857 91.20000
#> [15] 91.80000 81.00000 95.93571 91.80000 74.74286 90.34286 85.50000
#> [22] 79.45714 94.35000 86.40000 69.25714 93.25714 92.57143 74.05714
#> [29] 82.45714 84.08571 84.34286 78.49286 88.71429 56.10000 75.85714
#> [36] 79.54286 71.31429 87.17143 74.52857 85.62857 37.15714 74.82857
#> [43] 58.28571 61.71429 74.25000 76.50000 73.28571 91.17857 69.94286
#> [50] 72.12857 42.42857 89.59286 68.48571 68.65714 60.34286 79.90714
#> [57] 45.96429 80.07857 56.10000 71.31429 67.88571 60.94286 49.37143
#> [64] 67.02857 66.34286 73.73571 67.20000 59.40000 59.25000 43.71429
#> [71] 72.94286 79.45714
#> attr(,"statistic")
#> [1] "MeanPoints"
# An equivalent calculation based on a sample median
dmedian(daley, replace = FALSE)
#> [1] 102.00 81.60 97.20 97.20 99.90 102.60 91.80 94.50 89.25 91.20
#> [11] 102.60 110.70 96.90 91.20 91.80 78.75 94.35 91.80 76.80 91.80
#> [21] 84.00 81.00 94.35 86.40 67.20 91.80 91.80 75.60 83.25 86.40
#> [31] 81.60 79.20 86.40 56.10 76.50 81.60 72.00 86.40 77.70 86.40
#> [41] 35.70 75.60 57.60 59.40 74.25 76.50 70.20 88.80 67.20 74.25
#> [51] 39.60 88.80 71.40 70.20 62.40 79.20 44.55 77.70 56.10 72.00
#> [61] 67.20 59.40 48.60 71.40 64.80 72.15 67.20 59.40 57.75 40.80
#> [71] 72.15 81.00
#> attr(,"statistic")
#> [1] "MedianPoints"
# An equivalent calculation based on a sample mode
dmode(daley, replace = FALSE)
#> [1] 102.000 81.600 97.200 97.200 99.900 102.600 91.800 94.500 89.250
#> [10] 91.200 102.600 110.700 99.450 91.200 91.800 78.750 94.350 91.800
#> [19] 76.800 91.800 86.625 81.000 94.350 86.400 67.200 91.800 91.800
#> [28] 75.600 83.250 86.400 81.600 79.200 86.400 56.100 72.000 81.600
#> [37] 72.000 86.400 77.700 86.400 35.700 75.600 57.600 59.400 74.250
#> [46] 76.500 70.200 88.800 67.200 74.250 39.600 88.800 71.400 67.500
#> [55] 62.400 79.200 47.025 77.700 56.100 72.000 67.200 59.400 48.600
#> [64] 71.400 67.500 72.150 67.200 59.400 60.375 40.800 72.150 81.000
#> attr(,"statistic")
#> [1] "ModePoints"