Add functions to calc stats
This commit is contained in:
parent
1400e25ef4
commit
7e4b92e459
1 changed files with 23 additions and 0 deletions
|
@ -0,0 +1,23 @@
|
||||||
|
(defun evenp (number)
|
||||||
|
(if (= 0 (% number 2))
|
||||||
|
t
|
||||||
|
nil))
|
||||||
|
|
||||||
|
(defun oddp (number)
|
||||||
|
(not (evenp number)))
|
||||||
|
|
||||||
|
(defun stats:mean (list)
|
||||||
|
(/ (apply #'+ list) (float (length list))))
|
||||||
|
|
||||||
|
(defun stats:median (list)
|
||||||
|
(let* ((sorted (sort (copy-sequence list) #'<))
|
||||||
|
(len (length sorted))
|
||||||
|
(mid (floor (/ len 2))))
|
||||||
|
(if (evenp len)
|
||||||
|
(/ (+ (nth mid sorted) (nth (1- mid) sorted)) 2.0)
|
||||||
|
(nth mid sorted))))
|
||||||
|
|
||||||
|
(defun stats:standard-deviation (list)
|
||||||
|
(let ((m (stats:mean list)))
|
||||||
|
(sqrt (/ (seq-reduce (lambda (x acc) (+ x (expt (- x m) 2))) list 0)
|
||||||
|
(length list)))))
|
Loading…
Add table
Reference in a new issue