From b8b3d0f22b01a74611e9c9c5fc3f8f16fa34e78f Mon Sep 17 00:00:00 2001 From: yuzu-eva Date: Wed, 16 Jul 2025 22:49:13 +0200 Subject: added function to calculate correlation coefficient between x,y --- config.org | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'config.org') diff --git a/config.org b/config.org index 5308bad..e3d24ec 100644 --- a/config.org +++ b/config.org @@ -959,6 +959,25 @@ Inserts a newline above or below, like O and o in vim 0 (sqrt (/ (float sum-squared-diffs) n))))) (message "%.2f" stddev))) + + (defun ccoef (xvector yvector) + "Calculate the correlation coefficient between x and y" + (interactive "xEnter independant vector: \nxEnter dependant vector: ") + (let* ((xset xvector) + (yset yvector) + (n (length xset)) + (prodxy (cl-mapcar (lambda (x y) (* x y)) xset yset)) + (sumx (sum xset)) + (sumy (sum yset)) + (sumprodxy (sum prodxy)) + (sumsqx (sum (mapcar (lambda (x) (expt x 2)) xset))) + (sumsqy (sum (mapcar (lambda (y) (expt y 2)) yset))) + (denominator (float (sqrt (* (- (* n sumsqx) (expt sumx 2)) + (- (* n sumsqy) (expt sumy 2))))))) + (if (zerop denominator) + (message "Correlation coefficient: NaN (denominator is zero)") + (let ((r (/ (- (* n sumprodxy) (* sumx sumy)) denominator))) + (message "Correlation coefficient: %.2f" r))))) #+end_src * Custom keybinds and re-binds -- cgit v1.2.3