r - icc 在数据帧上,每个评估者都有一行
问题描述
让我首先说我对 R 完全陌生,并试图弄清楚如何在我的特定数据集上运行 icc,这可能与通常情况有所不同。
数据集如下所示
+------------+------------------+--------------+--------------+--------------+
| date | measurement_type | measurement1 | measurement2 | measurement3 |
+------------+------------------+--------------+--------------+--------------+
| 25-04-2020 | 1 | 15.5 | 34.3 | 43.2 |
| 25-04-2020 | 2 | 21.2 | 12.3 | 2.2 |
| 25-04-2020 | 3 | 16.2 | 9.6 | 43.3 |
| 25-04-2020 | 4 | 27 | 1 | 6 |
+------------+------------------+--------------+--------------+--------------+
现在我想对所有这些行进行 icc ,因为每一行代表不同的评估者。它应该将date
andmeasurement_type
列排除在外。
有人能指出我正确的方向吗,我完全不知道该怎么做。
------- 编辑 -------
我导出了实际数据集,该数据集将包含一些测试数据。可在此处获得
这里有两张重要的纸是第一张和第三张。第一个包含研究的所有参与者,第三个包含每个参与者的所有 4 份不同的报告。到目前为止,我的代码只是将每个报告与正确的参与者联系起来;
library("XLConnect")
library("sqldf")
library("irr")
library("dplyr")
library("tidyr")
# Load in Workbook
wb = loadWorkbook("Measuring.xlsx")
# Load in Worksheet
# Sheet 1 = Study Results
# Sheet 3 = Meetpunten
records = readWorksheet(wb, sheet=1)
reports = readWorksheet(wb, sheet=3)
for (record in 1:nrow(records)) {
recordId = records[record, 'Record.Id']
participantReports = sqldf(sprintf("select * from reports where `Record.Id` = '%s'", recordId))
baselineReport = sqldf("select * from participantReports where measurement_type = '1'")
drinkReport = sqldf("select * from participantReports where measurement_type = '2'")
regularReport = sqldf("select * from participantReports where measurement_type = '3'")
exerciseReport = sqldf("select * from participantReports where measurement_type = '4'")
}
解决方案
由于在您的数据中,每一行代表不同的评估者,但 irr 包中的 icc 函数需要将评估者作为列,您可以忽略表的前两列,转置并运行 icc。
所以,假设这张表:
+------------+------------------+--------------+--------------+--------------+
| date | measurement_type | measurement1 | measurement2 | measurement3 |
+------------+------------------+--------------+--------------+--------------+
| 25-04-2020 | 1 | 15.5 | 34.3 | 43.2 |
| 25-04-2020 | 2 | 21.2 | 12.3 | 2.2 |
| 25-04-2020 | 3 | 16.2 | 9.6 | 43.3 |
| 25-04-2020 | 4 | 27 | 1 | 6 |
+------------+------------------+--------------+--------------+--------------+
存储在一个名为 的变量中data
,我会这样做:
data2 = data.matrix(data[,-c(1,2)]) # generates the dataset without the first two columns
data2
这张表是:
+--------------+--------------+--------------+
| measurement1 | measurement2 | measurement3 |
+--------------+--------------+--------------+
| 15.5 | 34.3 | 43.2 |
| 21.2 | 12.3 | 2.2 |
| 16.2 | 9.6 | 43.3 |
| 27 | 1 | 6 |
+--------------+--------------+--------------+
然后:
data2 = t(data2) # transpose data2 so as to have raters in the columns and their ratings in each line
icc(data2) # here i'm not bothering with the parameters, but you should explore the appropriate icc parameters for your needs.
应该生成正确的运行。
推荐阅读
- javascript - FindIndex() 从 redux 存储中删除项目
- php - Wordpress 更改未显示在我的网站上
- android - OpenGL checkGlError("glDrawArrays") 抛出 UncaughtExceptionHandler
- regex - 正则表达式在第 n 个特殊字符和字符串之间进行选择
- javascript - 在 chrome 开发工具上访问 iframe 上下文
- angular - 尝试在 Ionic v4 中的模型上提交表单
- arrays - 从数组条目计算特定字段的总和
- javascript - 如何在具有最大字符长度的许多其他字符串中拆分唯一字符串
- javascript - React 没有在我的状态下识别对象
- reporting-services - 如何查询 SSRS 数据驱动订阅明细