Calculates the Pearson correlation coefficient between two numeric vectors, with optional case weights. Uses the standard correlation formula for unweighted data and weighted covariance for weighted data.
Arguments
- x
A numeric vector containing the first variable.
- y
A numeric vector containing the second variable. Must have the same length as
x
.- weights
An optional numeric vector of case weights. If provided, must have the same length as
x
andy
. All weights must be non-negative.- na.rm
A logical value indicating whether to remove missing values before computation. If
FALSE
(default), missing values result inNA
output.
Value
A numeric value representing the correlation coefficient between -1 and 1.
Returns NA
if either variable has zero variance.
See also
check_balance()
for computing multiple balance metrics at once
Other balance functions:
bal_ks()
,
bal_smd()
,
bal_vr()
,
check_auc()
,
check_balance()