summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryuzu-eva <cafebabe@disroot.org>2025-07-16 22:49:13 +0200
committeryuzu-eva <cafebabe@disroot.org>2025-07-16 22:49:13 +0200
commitb8b3d0f22b01a74611e9c9c5fc3f8f16fa34e78f (patch)
tree3f02169a82e9dc50d3f152721121bb312bd81b95
parentfc3f927faeba00820a9afa2c28bd09c82e66938d (diff)
added function to calculate correlation coefficient between x,y
-rw-r--r--config.org19
1 files changed, 19 insertions, 0 deletions
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