Skip to contents

Computes Lin's Concordance Correlation Coefficient (CCC) between observed and predicted values. Also returns Pearson's correlation coefficient and root mean squared error (RMSE). If the input is a grouped data frame (grouped_df), the function will return results for each group.

Usage

ccc(data, real, predito)

Arguments

data

A data frame containing the columns for observed and predicted values.

real

The column name (unquoted) corresponding to the observed values.

predito

The column name (unquoted) corresponding to the predicted values.

Value

A data frame with the following columns:

  • r: Pearson correlation coefficient

  • ccc: Lin's Concordance Correlation Coefficient

  • rmse: Root mean squared error

Details

The CCC is defined as:

$$\rho_c = \frac{2 \cdot \text{Cov}(x, y)}{\text{Var}(x) + \text{Var}(y) + (\bar{x} - \bar{y})^2}$$

where:

  • \(\text{Cov}(x, y)\) is the covariance between observed and predicted values

  • \(\text{Var}(x)\) and \(\text{Var}(y)\) are the variances of the observed and predicted values

  • \(\bar{x}\) and \(\bar{y}\) are the means of the observed and predicted values

Examples

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following object is masked from 'package:pliman':
#> 
#>     %>%
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(pliman)
df <- data.frame(
  group = rep(c("A", "B"), each = 5),
  real = c(1:5, 2:6),
  predicted = c(1.1, 2, 2.9, 4.1, 5, 2.2, 3.1, 4, 4.8, 6.1)
)

# Without grouping
ccc(df, real, predicted)
#>          r       ccc      rmse
#> 1 0.997498 0.9970678 0.1140175

# With grouping
df |>
  group_by(group) |>
  ccc(real, predicted)
#> # A tibble: 2 × 4
#>   group     r   ccc   rmse
#>   <chr> <dbl> <dbl>  <dbl>
#> 1 A     0.999 0.999 0.0775
#> 2 B     0.996 0.995 0.141