forked from ghurault/IRR-eczema-images
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02b_irr_areawise.R
60 lines (45 loc) · 1.92 KB
/
02b_irr_areawise.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Notes -------------------------------------------------------------------
# Area-wise ICC
# - Further "compress" images (aggregate neighbouring pixels) to investigate of IRR of the "main" areas of eczema.
# NB: the original images are already compressed
# - ICC for each image as Proportion data (with mixed effect on Rater)
# - Exclude background pixels
# Initialisation ----------------------------------------------------------
rm(list = ls()) # Clear workspace (better to restart the session)
set.seed(2020)
source(here::here("analysis", "00_init.R"))
#### OPTIONS
d <- 10 # dimension of compressed image
run <- FALSE
####
# Results files
icc_file <- here("results", paste0("icc_agg", d, "_uni.rds"))
# Data processing --------------------------------------------------------
# Aggregate pixels for area-wise IRR
df <- load_masks(d = d)
img <- unique(df[["filename"]])
# Remove pixels full of background and format dataset
df <- df %>%
filter(Skin > 0) %>%
select(-BigPixel_x, -BigPixel_y) %>%
pivot_longer(cols = starts_with("rater"), names_to = "Rater", values_to = "Eczema") %>%
mutate(NotEczema = pmax(Skin - Eczema, 0)) %>%
select(-N, -Skin)
# ICC for each image -----------------------------
if (run) {
# Should take < 3' for d=10
rpt_agg_uni <- lapply(1:length(img),
function(i) {
rptProportion(cbind(Eczema, NotEczema) ~ (1 | Rater) + (1 | ID),
grname = c("ID"),
data = df %>% filter(filename == img[i]),
link = "logit",
nboot = 0, npermut = 0)
})
icc_agg_uni <- tibble(filename = img,
Model = rpt_agg_uni) %>%
mutate(ICC = map(Model, ~.x$R["R_link", ]) %>% unlist())
saveRDS(icc_agg_uni, file = icc_file)
} else {
icc_agg_uni <- readRDS(icc_file)
}