【问题标题】:Calculate ICC for multiple data simultaneity计算多个数据同时性的 ICC
【发布时间】:2020-07-29 13:51:51
【问题描述】:

我想为多个 data.frame 同时计算 ICC。我所有的 data.frame 都具有相同的结构(5 列 x 83 行)。我创建了一个生成 ICC 的函数 (my_icc) 并将结果放入表中。我在这个网站上看到,当你想同时在多个 data.frame 上应用一个函数时,你需要把你的数据放到一个列表中。 (Apply a function to multiple dataframes) 但是,我的函数似乎不支持列表元素,因为我使用了函数 select。我使用选择功能,因为我想用我的 3:5 列做 ICC。如果我当时在一个 data.frame 上应用我的函数,我没有任何问题。

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

这是我试图创建的循环以获得 ICC 同时性。我创建了一个包含 3 个 data.frame 的小列表。实际上,我想计算 1258 ICC 同时性。我所有的数据。框架,用这个函数在 R 中导入。


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.

【问题讨论】:

    标签: r csv icc


    【解决方案1】:

    在这种情况下,您不需要列表。因为你的文件名是数字,你只需要在你的 for 循环中指定代表名字的数字间隔。

    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)
    }
    
    

    此循环将返回 1258 个单独的文件。

    【讨论】:

      猜你喜欢
      • 2017-05-28
      • 1970-01-01
      • 1970-01-01
      • 2021-10-14
      • 2020-07-15
      • 2021-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多