diff options
| author | yuzu-eva <cafebabe@disroot.org> | 2025-07-16 22:49:13 +0200 |
|---|---|---|
| committer | yuzu-eva <cafebabe@disroot.org> | 2025-07-16 22:49:13 +0200 |
| commit | b8b3d0f22b01a74611e9c9c5fc3f8f16fa34e78f (patch) | |
| tree | 3f02169a82e9dc50d3f152721121bb312bd81b95 /config.org | |
| parent | fc3f927faeba00820a9afa2c28bd09c82e66938d (diff) | |
added function to calculate correlation coefficient between x,y
Diffstat (limited to 'config.org')
| -rw-r--r-- | config.org | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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 |
