## 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(...)
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
Arguments
actual
|
A |
predicted
|
A |
correction
|
A |
…
|
Arguments passed into other methods. |
w
|
A |
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
<- lm(
model ~ .,
mpg data = mtcars
)
# 1.1) define actual
# and predicted values
# to measure performance
<- mtcars$mpg
actual <- fitted(model)
predicted
# 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"
)