concordance correlation coefficient

ccc.numeric R Documentation

Description

The ccc()-function computes the simple and weighted concordance correlation coefficient between the two vectors of predicted and observed <numeric> values. The weighted.ccc() function computes the weighted Concordance Correlation Coefficient. If correction is TRUE \(\sigma^2\) is adjusted by \(\frac{1-n}{n}\) in the intermediate steps.

Usage

## S3 method for class 'numeric'
ccc(actual, predicted, correction = FALSE, ...)

## S3 method for class 'numeric'
weighted.ccc(actual, predicted, w, correction = FALSE, ...)

ccc(...)

weighted.ccc(...)

Arguments

actual

A <numeric>-vector of length \(n\). The observed (continuous) response variable.

predicted

A <numeric>-vector of length \(n\). The estimated (continuous) response variable.

correction

A <logical> vector of length \(1\) (default: FALSE). If TRUE the variance and covariance will be adjusted with \(\frac{1-n}{n}\)

Arguments passed into other methods.

w

A <numeric>-vector of length \(n\). The weight assigned to each observation in the data.

Value

A <numeric> vector of length 1.

Calculation

The metric is calculated as follows,

\[ \rho_c = \frac{2 \rho \sigma_x \sigma_y}{\sigma_x^2 + \sigma_y^2 + (\mu_x - \mu_y)^2} \]

Where \(\rho\) is the \(\text{pearson correlation coefficient}\), \(\sigma\) is the \(\text{standard deviation}\) and \(\mu\) is the simple mean of actual and predicted.

Examples

# 1) fit a linear
# regression
model <- lm(
  mpg ~ .,
  data = mtcars
)

# 1.1) define actual
# and predicted values
# to measure performance
actual    <- mtcars$mpg
predicted <- fitted(model)

# 2) evaluate in-sample model
# performance
cat(
  "Concordance Correlation Coefficient", ccc(
    actual     = actual,
    predicted  = predicted,
    correction = FALSE
  ),
  "Concordance Correlation Coefficient (corrected)", ccc(
    actual     = actual,
    predicted  = predicted,
    correction = TRUE
  ),
  "Concordance Correlation Coefficient (weigthed)", weighted.ccc(
    actual     = actual,
    predicted  = predicted,
    w          = mtcars$mpg/mean(mtcars$mpg),
    correction = FALSE
  ),
  sep = "\n"
)