The weighted rank of \(X_i\) among \(X_1, \dots, X_n\) with weights \(w_1, \dots, w_n\) is defined as $$\frac 1 n \sum_{j = 1}^n w_i 1[X_j \le X_i].$$
rank_wtd(x, weights = numeric(), ties_method = "average")
a numeric vector.
a vector of weights (same length as x
).
Indicates how to treat ties; same as in R, see https://stat.ethz.ch/R-manual/R-devel/library/base/html/rank.html.
a vector of ranks.
x <- rnorm(100)
w <- rexp(100)
rank(x)
#> [1] 26 52 57 37 96 97 29 33 56 21 46 62 68 14 51 95 19 79
#> [19] 15 35 49 4 38 76 23 94 84 34 8 12 27 92 25 73 47 65
#> [37] 43 83 98 1 44 45 93 31 72 30 39 11 99 13 3 22 81 66
#> [55] 9 90 2 20 10 74 80 67 48 77 75 78 50 28 55 53 36 88
#> [73] 91 58 59 17 70 86 18 87 89 5 63 60 6 32 100 71 7 16
#> [91] 41 82 61 42 54 69 64 24 40 85
rank_wtd(x, w)
#> [1] 27.61205857 54.81319316 59.73893926 40.36396788 98.97630661
#> [6] 99.32965598 30.13372035 33.15654256 58.19530003 20.98218690
#> [11] 50.90605721 67.03765020 68.16728139 12.82647268 53.47730936
#> [16] 98.83323135 19.15562141 77.34878868 14.89189280 38.06448305
#> [21] 51.24975861 0.95328299 41.61480565 73.99855688 23.67000865
#> [26] 94.13203902 84.56614084 34.55684191 5.50403435 8.71058015
#> [31] 29.22131516 91.69500146 27.39885292 69.34398301 51.10834196
#> [36] 67.27626496 48.89814881 82.30180123 99.37643348 0.05834603
#> [41] 49.21985083 49.34247118 94.00126243 31.86501171 69.13884699
#> [46] 31.60639678 42.55091870 8.41707905 99.59262589 8.86199572
#> [51] 0.92378221 22.93081968 79.33550966 67.53305241 6.52129762
#> [56] 89.87261414 0.75031977 20.33270201 7.99898268 69.56344177
#> [61] 78.66757995 67.80027198 51.11853252 75.60302243 73.80350722
#> [66] 75.73462527 53.23775487 29.65054346 56.86486836 55.45620710
#> [71] 38.31777660 89.59931423 90.21560650 61.53035624 62.58891827
#> [76] 16.99283521 68.96085459 87.29514536 17.20496972 87.76563960
#> [81] 89.61379820 1.17011796 67.19929534 64.64953554 3.87573327
#> [86] 32.09366553 100.00000000 69.08857946 4.06495538 16.46909978
#> [91] 48.43570230 82.22035137 65.71866203 48.54656272 56.60805333
#> [96] 68.65393137 67.23755378 25.39933349 47.62437983 85.31632530