(defconstant e (exp 1)) (defun sum (l) (let ((n 0)) (dolist (one l n) (incf n one)))) (defun mean (l) (let ((n 0) (sum 0)) (dolist (one l (/ sum n)) (incf sum one) (incf n)))) (defun harmonic-mean (x y) (/ (* 2 x y) (+ x y))) (defun weighted-sum (l total) (sum (mapcar #'(lambda (one) (let ((freq (first one)) (weight (rest one))) (* (/ freq total) weight))) l))) (defun stdev (n sum sumSq) (sqrt (/ (- sumSq(/ (* sum sum) n)) (- n 1)))) (defun list2stdev (l) (let ((n 0) (sum 0) (sumSq 0)) (dolist (x l (stdev n sum sumSq)) (incf n) (incf sum x) (incf sumSq (* x x ))))) (defun median (nums) (labels ((mean (x y) (/ (+ x y ) 2))) (let* ((n1 (sort nums #'<)) (l (length n1)) (mid (floor (/ l 2))) (midval (nth mid n1)) (25percent (nth (floor (* l 0.25)) n1)) (75percent (nth (floor (* l 0.75)) n1)) (50percent (if (oddp l) midval (mean midval (nth (- mid 1) n1))))) (values 50percent (- 75percent 50percent) 75percent 25percent)))) (defun between (a b c) (<= a b c)) ;(deftest test-stats () ; (let ((nums '(1 1 1 1 2 2 4 100))) ; (check ; (= 112 (sum nums)) ; (= 3/2 (median nums)) ; (= 14 (mean nums)))))