Open In App

How to Calculate Intraclass Correlation Coefficient in R?

Last Updated : 17 May, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will discuss how to calculate the intraclass correlation coefficient in R Programming Language. Correlation is used to get the relationship between two variables.

  • If the value is 1, then the relationship is a positive correlation
  • If the value is -1, then the relationship is a negative correlation
  • If the value is 0, then the relationship has no correlation

An intraclass correlation coefficient is used to get if elements can be rated reliably by different raters. The range starts from 0 and ends in 1.

we can use icc() method, It is available in irr package stands for interrater reliability

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.

Example 1: Calculate icc for oneway model

In this example, we are going to create a dataframe with 4 columns and calculate icc for a oneway model with a single unit

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


Output:

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.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

Example 2: Calculate icc for two-way model

In this example, we are going to create a dataframe with 4 columns and calculate icc for a two-way model with a single unit.

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


Output:

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

Example 3: Calculate icc for an average unit

In this example, we are going to create a dataframe with 4 columns and calculate icc for two-way model with an average unit.

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


Output:

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

Example 4: Calculate icc for a single unit

In this example, we are going to create a dataframe with 4 columns and calculate icc for two-way model with a single unit

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


Output:

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads