Skip to content

Commit

Permalink
Use consistent names for correlation coefs
Browse files Browse the repository at this point in the history
  • Loading branch information
clane9 committed Apr 3, 2023
1 parent e01766a commit 067cb3b
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions cpac_correlations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
Axis = Union[int, Tuple[int, ...]]

class CorrValue(NamedTuple):
ccc: np.ndarray
rho: np.ndarray
concor: np.ndarray
pearson: np.ndarray


def read_yml_file(yml_filepath):
Expand Down Expand Up @@ -170,17 +170,15 @@ def batch_correlate(
y_std = np.sqrt(y_var)
y_norm = (y - y_mean) / y_std

# Pearson correlation
rho = np.mean(x_norm * y_norm, axis=axis, keepdims=True)

# Concordance correlation
ccc = 2 * rho * x_std * y_std / (x_var + y_var + (x_mean - y_mean) ** 2)
# Correlation coefficients
pearson = np.mean(x_norm * y_norm, axis=axis, keepdims=True)
concor = 2 * pearson * x_std * y_std / (x_var + y_var + (x_mean - y_mean) ** 2)

# Squeeze reduced singleton dimensions
if axis is not None:
ccc = np.squeeze(ccc, axis=axis)
rho = np.squeeze(rho, axis=axis)
return CorrValue(ccc, rho)
concor = np.squeeze(concor, axis=axis)
pearson = np.squeeze(pearson, axis=axis)
return CorrValue(concor, pearson)


def correlate_text_based(txt1, txt2):
Expand Down

0 comments on commit 067cb3b

Please sign in to comment.