Skip to contents

Compute the correlation of observed and predicted data.

Usage

corr(obs, pred, ...)

Arguments

obs

A vector, data.frame or data.table with observed data.

pred

A vector, data.frame or data.table with predicted (model) data.

...

Optional parameters sent to cor.

Value

The correlation of input data as a numeric.

Details

This is a convenience function to the stats::cor() function. See cor documentation for further details.

Optional parameters are sent to cor. The most important are:

  • use an optional character giving a method for computing covariances in the presence of missing values. This must be one of the strings "everything", "all.obs", "complete.obs", "na.or.complete", or "pairwise.complete.obs". See cor documentation for further details.

  • method a character string indicating which correlation coefficient to be computed. One of "pearson" (default), "kendall" or "spearman".

Examples

# Generate two random temperature series in the range of 20, 30 (for testing purpose):
x <- runif(n = 10, min = 20, max = 30)
y <- runif(n = 10, min = 20, max = 30)
corr(x, y)
#> [1] 0.542282

if (FALSE) {

# temperature is a data.frame is obs and pred columns:
corr(temperature$obs, temperature$pred, use = "complete.obs")

# temperature is a data.table with obs and pred columns:
temperature[, .(corr(obs, pred, use = "complete.obs")), by = cod_brace]
}