From 13f83ab2446351f3dcd0a5c1b4ad9811b1a0277c Mon Sep 17 00:00:00 2001 From: AJ Rossini Date: Wed, 4 Feb 2009 17:58:49 +0100 Subject: [PATCH] summary stats in demo -- need to move to descriptives and make generic. Signed-off-by: AJ Rossini --- ls-demo.lisp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/ls-demo.lisp b/ls-demo.lisp index 0c1d8d0..4a56d46 100644 --- a/ls-demo.lisp +++ b/ls-demo.lisp @@ -3,7 +3,7 @@ ;;; See COPYRIGHT file for any additional restrictions (BSD license). ;;; Since 1991, ANSI was finally finished. Edited for ANSI Common Lisp. -;;; Time-stamp: <2008-12-08 08:10:41 tony> +;;; Time-stamp: <2009-02-04 17:58:19 tony> ;;; Creation: sometime in 2006... ;;; File: ls-demo.lisp ;;; Author: AJ Rossini @@ -622,6 +622,32 @@ my.lib (progn (defparameter *x* (make-vector 5 :initial-contents '((1d0 2d0 3d0 4d0 5d0)))) + ;; estimating a mean, simple way. (/ (loop for i from 0 to (- (nelts *x*) 1) summing (vref *x* i)) - (nelts *x*))) + (nelts *x*)) + + (defun mean (x) + (checktype x 'vector-like) + (/ (loop for i from 0 to (- (nelts *x*) 1) + summing (vref *x* i)) + (nelts *x*))) + + ;; estimating variance, Moments + (let ((meanx (mean *x*)) + (n (nelts *x*))) + (/ (loop for i from 0 to (- n 1) + summing (* (- (vref *x* i) meanx) + (- (vref *x* i) meanx) )) + n)) + + ;; estimating variance, Moments + (let ((meanx (mean *x*)) + (nm1 (1- (nelts *x*)))) + (/ (loop for i from 0 to nm1 + summing (* (- (vref *x* i) meanx) + (- (vref *x* i) meanx) )) + nm1)) + + ) + -- 2.11.4.GIT