`check_outliers()`: Cook's distances land on the wrong rows when the model skips or reorders rows
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 22/100
Hướng nghiên cứu
Start in check_outliers() in the performance package, where Cook's distances are numbered by fitted-row position and joined to insight::get_data() rows. Compare that with model.frame() and cooks.distance() for the subset, zero-weight and na.exclude cases in the reproduction. There is no agreed fix yet, so first settle how to map each distance to its data row, then check the four cases return NA for unused rows.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
check_outliers() numbers the Cook's distances 1, 2, 3, ... in the order of the rows the model was fitted on. It then joins them to the rows of the data (from insight::get_data()) by that number. If the model did not use every data row, or used the rows in another order, each distance lands on the wrong row. No warning is given.
This happens with subset, with prior weights of 0, and with na.action = na.exclude. It affects method = "cook" alone and combined with other methods.
library(performance)
# 1. subset: rows 1 to 4 are not in the model, but they get distances
m <- lm(mpg ~ disp + drat, data = mtcars, subset = 5:32)
out <- as.data.frame(check_outliers(m, method = c("cook", "zscore_robust")))
out[1:5, c("Row", "Distance_Cook")]
#> Row Distance_Cook
#> 1 1 0.0408896798
#> 2 2 0.0028593118
#> 3 3 0.0003970294
#> 4 4 0.0019153130
#> 5 5 0.0036171642
round(cooks.distance(m)[1:2], 4)
#> Hornet Sportabout Valiant
#> 0.0409 0.0029
# row 1 (Mazda RX4) shows the distance of row 5 (Hornet Sportabout)
# 2. a subset in another order: the distances come out reversed
m2 <- lm(mpg ~ disp + drat, data = mtcars, subset = 32:1)
out2 <- as.data.frame(check_outliers(m2, method = "cook"))
round(out2$Distance_Cook[1:3], 4)
#> [1] 0.0289 0.0102 0.0263
round(cooks.distance(m2)[c("Mazda RX4", "Mazda RX4 Wag", "Datsun 710")], 4)
#> Mazda RX4 Mazda RX4 Wag Datsun 710
#> 0.0071 0.0071 0.0110
# 3. weights of 0: the distances shift up by two rows
w <- rep(1, 32)
w[1:2] <- 0
m3 <- lm(mpg ~ disp + drat, data = mtcars, weights = w)
out3 <- as.data.frame(check_outliers(m3, method = c("cook", "zscore_robust")))
out3[c(1:3, 31:32), c("Row", "Distance_Cook")]
#> Row Distance_Cook
#> 1 1 0.01401184
#> 2 2 0.02684947
#> 3 3 0.03754641
#> 31 31 NA
#> 32 32 NA
round(cooks.distance(m3)["Datsun 710"], 4)
#> Datsun 710
#> 0.014
# row 1 shows the distance of row 3 (Datsun 710)
The expected result: rows that the model did not use have no Cook's distance (NA), and every other row has its own distance.
A fix by row name is not enough, because the row names of insight::get_data() do not always name the model's rows. For tibble data with missing values, it numbers the complete rows 1 to n. For data.table data with a logical subset, it numbers the rows by their position after the subset:
d <- data.table::as.data.table(mtcars)
d$mpg[5] <- NA
m4 <- lm(mpg ~ disp + drat, data = d, subset = drat > 3)
head(rownames(insight::get_data(m4)))
#> [1] "1" "2" "3" "4" "6" "7"
head(rownames(model.frame(m4)))
#> [1] "1" "2" "3" "4" "7" "8"
Do you have ideas for a reliable way to tell which data row each Cook's distance belongs to?
Versions: performance 0.18.2.20 (main), insight 1.5.4.32, data.table 1.18.6.1.
- Ngôn ngữ chính
- R
- Star
- 1.2k
- Fork
- 113
- Merge trung bình
- 9 giờ 8 phút
- Pull request đã merge (30 ngày)
- 27
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của easystats/performance
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
easystats/performance#1038 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Waiting for response :love_letter:
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
easystats/performance#1005 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
misleading subtitle with check_heteroscedasticity with binomial data?Có thể đã có người làm @jmgirard đã nhận 26 ngày trước. Đang mởConsistency :green_apple: :apple: Docs :books:
easystats/performance#1003 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Proposal] Support for glmtoolbox glmgee objects (glmgee or gnmgee models) / interim warningsĐang mởDocs :books: Enhancement :boom:
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 45/100
easystats/performance#901 · 2 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Enhancement :boom:
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
easystats/performance#891 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của easystats/performance
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ThinkR-open/mordew#89 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
epiforecasts/EpiNow2#1694 · 2 reaction ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
easystats/correlation#403 ·
-
add temporal concepts vignetteĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
mitchelloharawild/mixtime#111 ·
-
Unpin CCCL for 3.5.0+ supportĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
conda-forge/xgboost-feedstock#313 ·