Riditスコアリング(https://en.wikipedia.org/wiki/Ridit_scoring)は、相対的な頻度(ある値以下の場合の割合とその値の半分の割合)に序数変数を変換するためによく使用されます。ridit transform序数変数R
R
ではどのようにしますか?
Riditスコアリング(https://en.wikipedia.org/wiki/Ridit_scoring)は、相対的な頻度(ある値以下の場合の割合とその値の半分の割合)に序数変数を変換するためによく使用されます。ridit transform序数変数R
R
ではどのようにしますか?
UPDATE 削除むしろ愚かなコードされるだろう変換行列を構築関わる、私は(CUMSUMについて忘れて)
# Convert vector of counts to ridits
to.ridit <- function(v) {
(cumsum(v) - .5 * v)/sum(v)
}
# Calculate mean ridit for vector of counts relative to reference group
mean.ridit <- function(v, ref) {
sum(to.ridit(ref) * v)/sum(v)
}
# Calculate mean ridits for several groups
# x is matrix of counts
# margin is 1 for groups in rows, 2 for groups in columns
# If ref is omitted, totals across groups are used as reference group
# If ref is a vector of counts, it's used as reference group
# Otherwise, ref is the number (or name if it exists) of the group to use as reference
ridits <- function(x, margin, ref=NULL) {
if (length(ref) > 1) {
refgroup <- ref
} else if (length(ref) == 1) {
if (margin==1) {
refgroup <- x[ref,]
} else {
refgroup <- x[, ref]
}
} else {
refgroup <- apply(x, 3-margin, sum)
}
apply(x, margin, mean.ridit, refgroup)
}
例(Fleiss、1981:車のACの重症度cidents):私のコードは別の答えで述べたRidit :: riditパッケージよりもやや小さい柔軟ではあるが
to.ridit(c(17, 54, 60, 19, 9, 6, 14))
[1] 0.04748603 0.24581006 0.56424581 0.78491620 0.86312849 0.90502793 0.96089385
注 は、かなり速いと思わ:
# Influenza subtypes by age as of week ending 2/24/18 (US CDC)
> flu.age
BY BV BU H3 H1
0-4 274 91 92 1808 500
5-24 1504 274 698 5090 951
25-64 1665 101 567 7538 1493
65+ 1476 35 330 9541 515
# Using CRAN package
> system.time(ridit(flu.age,2))
user system elapsed
3.746 0.007 3.756
# Using my code
> system.time(ridits(flu.age,2))
user system elapsed
0.001 0.000 0.000
次のパッケージで問題を解決できる場合があります。特に、コマンドRidit::ridit
は以下のように記述されているので便利です。
任意の参照グループを指定できるKruskal-Wallisテストの拡張。また、グループごとに Mean Riditも提供してください。グループの平均Riditは、そのグループからのランダムな観測値 が参照グループからのランダムな観測値以上である確率の推定値です。
https://cran.r-project.org/web/packages/Ridit/Ridit.pdf
別のアプローチは、プロビット、ロジットまたは正確なロジットなどのバイナリ選択モデルを用いた予測独立変数を抽出、すなわち0または1