如何计算R中的类内相关系数?
在本文中,我们将讨论如何在 R 编程语言中计算类内相关系数。相关性用于获得两个变量之间的关系。
- 如果值为1,则关系为正相关
- 如果值为-1,则关系为负相关
- 如果值为0,则关系没有相关性
类内相关系数用于确定元素是否可以被不同的评分者可靠地评分。范围从 0 开始,以 1 结束。
我们可以使用 icc() 方法,它在 irr 包中可用,代表 interrater 可靠性
Syntax: icc(data, model, type, unit)
where,
- data is the input dataframe
- model is the type of model to use. there are two types oneway and twoway.
- type is the relationship to calculate between raters. Options include “consistency” or “agreement”
- unit is for analysis , which is a single or average
Return: It will return the following:
- model – The type of model – oneway or twoway
- type – The type of model which is agreement
- Subjects- Total number of data in each column of the dataframe
- Raters – The number of columns of the dataframe
- ICC value – Intra correlation coefficient value
- Ftest – F value and P value
- CI – Confidence Interval of the Correlated values.
示例 1:计算单向模型的 icc
在此示例中,我们将创建一个具有 4 列的数据框,并为具有单个单元的单向模型计算 icc
R
# load the library
library(irr)
# create dataframe with 4 columns
data = data.frame(col1=c(1:10), col2=c(34:43),
col3=c(20:29), col4=c(56:65))
# calculate icc for oneway model
icc(data, model = "oneway",
type = "agreement",
unit = "single")
R
# load the library
library(irr)
# create dataframe with 4 columns
data = data.frame(col1 = c(1:10),
col2 = c(34:43),
col3 = c(20:29),
col4 = c(56:65))
# calculate icc for twoway model
icc(data, model = "twoway",
type = "agreement",
unit = "single")
R
# load the library
library(irr)
# create dataframe with 4 columns
data = data.frame(col1 = c(1:10),
col2 = c(34:43),
col3 = c(20:29),
col4 = c(56:65))
# calculate icc for twoway model with average unit
icc(data, model = "twoway", type = "agreement",
unit = "average")
R
# load the library
library(irr)
# create dataframe with 4 columns
data = data.frame(col1 = c(1:10),
col2 = c(34:43),
col3 = c(20:29),
col4 = c(56:65))
# calculate icc for twoway
# model with single unit
icc(data, model = "twoway", type = "agreement",
unit = "single")
输出:
In this output, As mentioned in the code , The model is oneway and Type is agreement
As there are four columns columns in the dataframe , so the Raters=4
In each column, the number of rows are 10 , so the Subjects = 10
The Intra correlation Coefficient (ICC) is -0.304
The F-test value we got is 0,0692 and the p value is 1
Finally, we got the 95% Confidence Interval level is in between -0.332 to -0.233
示例 2:计算双向模型的 icc
在此示例中,我们将创建一个具有 4 列的数据框,并为具有单个单元的双向模型计算 icc。
R
# load the library
library(irr)
# create dataframe with 4 columns
data = data.frame(col1 = c(1:10),
col2 = c(34:43),
col3 = c(20:29),
col4 = c(56:65))
# calculate icc for twoway model
icc(data, model = "twoway",
type = "agreement",
unit = "single")
输出:
In this output, As mentioned in the code, The model is two-way and Type is agreement
As there are four columns in the dataframe , so the Raters=4
In each column, the number of rows are 10 , so the Subjects = 10
The Intra correlation Coefficient (ICC) is -0.0168
The F-test value we got is -5.44 exponent and the p value is 1
Finally, we got the 95% Confidence Interval level is in between 0.001 to 0.00
示例 3:计算平均单位的 icc
在此示例中,我们将创建一个具有 4 列的数据框,并为具有平均单位的双向模型计算 icc。
R
# load the library
library(irr)
# create dataframe with 4 columns
data = data.frame(col1 = c(1:10),
col2 = c(34:43),
col3 = c(20:29),
col4 = c(56:65))
# calculate icc for twoway model with average unit
icc(data, model = "twoway", type = "agreement",
unit = "average")
输出:
In this output, As mentioned in the code, The model is oneway and Type is agreement
As there are four columns in the dataframe , so the Raters=4
In each column, the number of rows are 10 , so the Subjects = 10
The Intra correlation Coefficient (ICC) is 0.0639
The F-test value we got is -5.44 exp and the p value is 1
Finally, we got the 95% Confidence Interval level is in between 0.005 to 0.257
示例 4:计算单个单元的 icc
在此示例中,我们将创建一个具有 4 列的数据框,并为具有单个单元的双向模型计算 icc
R
# load the library
library(irr)
# create dataframe with 4 columns
data = data.frame(col1 = c(1:10),
col2 = c(34:43),
col3 = c(20:29),
col4 = c(56:65))
# calculate icc for twoway
# model with single unit
icc(data, model = "twoway", type = "agreement",
unit = "single")
输出:
In this output, As mentioned in the code, The model is twoway and Type is an agreement.
As there are four columns in the dataframe, so the Raters=4
In each column, the number of rows are 10, so the Subjects = 10
The Intra Correlation Coefficient (ICC) is 0.0168
The F-test value we got is -5.44 exp and the p value is 1
Finally, we got the 95% Confidence Interval level is in between 0.001 to 0.00