(defstruct dist (min most-positive-double-float) (max most-negative-double-float) (bars '()) (sum 0) (sumsq 0) (n 0) (sorted t) (fuzz 1) (fat nil) (all '()) ) (defun dist-compare (d1 d2 &key (conf 95)) "compares means of two independent samples d1 d2" (ttest (dist-sum d1) (dist-sumsq d1) (dust-n d1) (dist-sum d2) (dist-sumsq d2) (dust-n d2) :conf conf)) (defun as-dist (l) "Return a dist with all the numbers of l" (if (eq 'dist (type-of l)) l (dist-adds l))) (defun dist-adds (l &optional (d (make-dist))) "Add the numbers in the list 'l' to a dist." (dolist (x l d) (dist-add x d))) (defun dist-mean (d) (/ (dist-sum d) (dist-n d))) (defun dist-sd (d) (stdev (dist-n d) (dist-sum d) (dist-sumsq d))) (defun dist-add (num &optional (d (make-dist))) (incf (dist-n d)) (incf (dist-sum d) num) (incf (dist-sumsq d) (* num num)) (if (dist-fat d) (push num (dist-all d))) (if (< num (dist-min d)) (setf (dist-min d) num)) (if (> num (dist-max d)) (setf (dist-max d) num)) (let* ((fuzz (dist-fuzz d)) (num1 (* fuzz (round (/ num fuzz)))) (val (cdr (assoc num1 (dist-bars d))))) (if val (setf (cdr (assoc num1 (dist-bars d))) (1+ val)) (push (cons num1 1) (dist-bars d))) (setf (dist-sorted d) nil)) d) (defun dist-sort (d) (labels ((car< (a b) (< (car a ) (car b)))) (unless (dist-sorted d) (setf (dist-bars d) (sort (dist-bars d) #'car<) (dist-sorted d) t)) d))