Search code examples
rcsvicc

Calculate ICC for multiple data simultaneity


I want to calculate ICC for multiple data.frame simultaneity. All my data.frame have the same structure (5 columns by 83 rows). I created a function (my_icc) that generated the ICC and put the result in a table. I saw in this web site that when you want to apply a function on multiple data.frame at the same time, you need to put your data into a list. (Apply a function to multiple dataframes) However, my function doesn’t seem to support list element, because I use the function select. I use select function because, I want to do the ICC with my 3:5 columns. If I apply my function on one data.frame at the time, I don’t have any problem.

my_icc <- function(data) {
  data %>%
    select(3:4) %>%       # select just the rating columns             
    irr::icc() %>%        # calculate the ICC
    unlist() %>%          # turn the output list into a vector
    t() %>%               # transpose this vector
    as_tibble() %>%       # turn the vector into a table 
    select(               # select just the columns you want
      icc = value,        # rename value to icc
      F.value=Fvalue,
      df1,
      df2,
      p.value,
      conf.level,
      lower.bound=lbound, 
      uper.ubound=ubound
    ) 
}

my_icc(Radiomics.CSV[[1]])

Icc Result

This is the loop a I tried to create to obtain the ICC simultaneity. I created a small list with 3 data.frame. In reality, I want to calculate 1258 ICC simultaneity. All my data. Frame, are import in R with this function.


library(dplyr)

files <- list.files(path = "Tableau des features/", pattern="*.csv")
 Radiomics.CSV <- lapply(files, function(x) {
    read.csv(paste0("Tableau des features/", x))
})


my_list <- c(Radiomics.CSV[[1]], Radiomics.CSV[[2]],Radiomics.CSV[[3]])
for(i in my_list){
 my_icc <- function(i) {
  i %>%
    select(3:4) %>%       # select just the rating columns             
    irr::icc() %>%        # calculate the ICC
    unlist() %>%          # turn the output list into a vector
    t() %>%               # transpose this vector
    as_tibble() %>%       # turn the vector into a table 
    select(               # select just the columns you want
      icc = value,        # rename value to icc
      F.value=Fvalue,
      df1,
      df2,
      p.value,
      conf.level,
      lower.bound=lbound, 
      uper.ubound=ubound
    ) 
} 
}
my_icc(my_list)
Error: `select()` doesn't handle lists.

Solution

  • In this case, you don’t need a list. Because your files name are numbers, you just need to specify in your for loop the interval of number that represent the names.

    my_icc <- function(i) {
      i %>%
        select(3:5) %>%       # select just the rating columns             
        irr::icc() %>%        # calculate the ICC
        unlist() %>%          # turn the output list into a vector
        t() %>%               # transpose this vector
        as_tibble() %>%       # turn the vector into a table 
        select(               # select just the columns you want
          icc = value,        # rename value to icc
          F.value=Fvalue,     # un peu enlever les paramètres que nous ne voulons pas
          df1,
          df2,
          p.value,
          conf.level,
          lower.bound=lbound, 
          uper.ubound=ubound
        ) 
    } 
    
    for (x in 1:1258) { 
      write.csv(data.frame(my_icc(Data[[x]])), paste0('/Users/T/Desktop/Rstudio/ICCs/',x,'.csv'), row.names = T)
    }
    
    

    This loop will return you 1258 separated files.