pecon.stats.corr#
- pecon.stats.corr(x, y) CorrResult#
Compute the Pearson correlation coefficient between two variables.
The correlation coefficient measures the strength and direction of a linear relationship between two variables. Its value lies between -1 and 1.
- Parameters:
x (array-like) – One-dimensional sequence of numerical values.
y (array-like) – One-dimensional sequence of numerical values of the same length as x.
- Returns:
- Dataclass containing:
- rfloat
Pearson correlation coefficient.
- pvaluefloat
Two-tailed p-value for testing non-correlation.
- tstatfloat
t-statistic corresponding to the correlation.
- Return type:
CorrResult
Notes
A value of 1 indicates perfect positive correlation, -1 indicates perfect negative correlation, and 0 indicates no linear correlation.
Examples
>>> from pecon import stats >>> x = [2, 4, 6, 8, 10, 17, 24] >>> y = [1, 6, 12, 30, 17, 55, 40] >>> res = stats.corr(x, y) >>> print(f"Correlation Coefficient = {res.r}\n pvalue = {res.pvalue}") Correlation Coefficient = 0.8420191952099748 pvalue = 0.01746558746945201