]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calc-stat.el
(calc-arctan, calc-tanh, calc-arctanh): Removed extra definitions.
[gnu-emacs] / lisp / calc / calc-stat.el
index 155be891c5d3907be40095727e591e33c4a0012c..9fdd634027e59879da7734759b2a7d04d53b1443 100644 (file)
@@ -1,6 +1,9 @@
-;; Calculator for GNU Emacs, part II [calc-stat.el]
-;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
-;; Written by Dave Gillespie, daveg@synaptics.com.
+;;; calc-stat.el --- statistical functions for Calc
+
+;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
+
+;; Author: David Gillespie <daveg@synaptics.com>
+;; Maintainer: Jay Belanger <belanger@truman.edu>
 
 ;; This file is part of GNU Emacs.
 
 ;; file named COPYING.  Among other things, the copyright notice
 ;; and this notice must be preserved on all copies.
 
+;;; Commentary:
 
+;;; Code:
 
 ;; This file is autoloaded from calc-ext.el.
-(require 'calc-ext)
 
+(require 'calc-ext)
 (require 'calc-macs)
 
-(defun calc-Need-calc-stat () nil)
-
-
 ;;; Statistical operations on vectors.
 
 (defun calc-vector-count (arg)
   (interactive "P")
   (calc-slow-wrapper
-   (calc-vector-op "coun" 'calcFunc-vcount arg))
-)
+   (calc-vector-op "coun" 'calcFunc-vcount arg)))
 
 (defun calc-vector-sum (arg)
   (interactive "P")
   (calc-slow-wrapper
    (if (calc-is-hyperbolic)
        (calc-vector-op "vprd" 'calcFunc-vprod arg)
-     (calc-vector-op "vsum" 'calcFunc-vsum arg)))
-)
+     (calc-vector-op "vsum" 'calcFunc-vsum arg))))
 
 (defun calc-vector-product (arg)
   (interactive "P")
   (calc-hyperbolic-func)
-  (calc-vector-sum arg)
-)
+  (calc-vector-sum arg))
 
 (defun calc-vector-max (arg)
   (interactive "P")
   (calc-slow-wrapper
    (if (calc-is-inverse)
        (calc-vector-op "vmin" 'calcFunc-vmin arg)
-     (calc-vector-op "vmax" 'calcFunc-vmax arg)))
-)
+     (calc-vector-op "vmax" 'calcFunc-vmax arg))))
 
 (defun calc-vector-min (arg)
   (interactive "P")
   (calc-invert-func)
-  (calc-vector-max arg)
-)
+  (calc-vector-max arg))
 
 (defun calc-vector-mean (arg)
   (interactive "P")
         (calc-vector-op "medn" 'calcFunc-vmedian arg))
      (if (calc-is-inverse)
         (calc-vector-op "meae" 'calcFunc-vmeane arg)
-       (calc-vector-op "mean" 'calcFunc-vmean arg))))
-)
+       (calc-vector-op "mean" 'calcFunc-vmean arg)))))
 
 (defun calc-vector-mean-error (arg)
   (interactive "P")
   (calc-invert-func)
-  (calc-vector-mean arg)
-)
+  (calc-vector-mean arg))
 
 (defun calc-vector-median (arg)
   (interactive "P")
   (calc-hyperbolic-func)
-  (calc-vector-mean arg)
-)
+  (calc-vector-mean arg))
 
 (defun calc-vector-harmonic-mean (arg)
   (interactive "P")
   (calc-invert-func)
   (calc-hyperbolic-func)
-  (calc-vector-mean arg)
-)
+  (calc-vector-mean arg))
 
 (defun calc-vector-geometric-mean (arg)
   (interactive "P")
   (calc-slow-wrapper
    (if (calc-is-hyperbolic)
        (calc-binary-op "geom" 'calcFunc-agmean arg)
-     (calc-vector-op "geom" 'calcFunc-vgmean arg)))
-)
+     (calc-vector-op "geom" 'calcFunc-vgmean arg))))
 
 (defun calc-vector-sdev (arg)
   (interactive "P")
         (calc-vector-op "var" 'calcFunc-vvar arg))
      (if (calc-is-inverse)
         (calc-vector-op "psdv" 'calcFunc-vpsdev arg)
-       (calc-vector-op "sdev" 'calcFunc-vsdev arg))))
-)
+       (calc-vector-op "sdev" 'calcFunc-vsdev arg)))))
 
 (defun calc-vector-pop-sdev (arg)
   (interactive "P")
   (calc-invert-func)
-  (calc-vector-sdev arg)
-)
+  (calc-vector-sdev arg))
 
 (defun calc-vector-variance (arg)
   (interactive "P")
   (calc-hyperbolic-func)
-  (calc-vector-sdev arg)
-)
+  (calc-vector-sdev arg))
 
 (defun calc-vector-pop-variance (arg)
   (interactive "P")
   (calc-invert-func)
   (calc-hyperbolic-func)
-  (calc-vector-sdev arg)
-)
+  (calc-vector-sdev arg))
 
 (defun calc-vector-covariance (arg)
   (interactive "P")
           (calc-enter-result n "pcov" (cons 'calcFunc-vpcov
                                             (calc-top-list-n n)))
         (calc-enter-result n "cov" (cons 'calcFunc-vcov
-                                         (calc-top-list-n n)))))))
-)
+                                         (calc-top-list-n n))))))))
 
 (defun calc-vector-pop-covariance (arg)
   (interactive "P")
   (calc-invert-func)
-  (calc-vector-covariance arg)
-)
+  (calc-vector-covariance arg))
 
 (defun calc-vector-correlation (arg)
   (interactive "P")
   (calc-hyperbolic-func)
-  (calc-vector-covariance arg)
-)
+  (calc-vector-covariance arg))
 
 (defun calc-vector-op (name func arg)
   (setq calc-aborted-prefix name
        arg (prefix-numeric-value arg))
   (if (< arg 0)
       (error "Negative arguments not allowed"))
-  (calc-enter-result arg name (cons func (calc-top-list-n arg)))
-)
+  (calc-enter-result arg name (cons func (calc-top-list-n arg))))
 
 
 
 ;;; non-vectors.
 
 (defun calcFunc-vsum (&rest vecs)
-  (math-reduce-many-vecs 'calcFunc-add 'calcFunc-vsum vecs 0)
-)
+  (math-reduce-many-vecs 'calcFunc-add 'calcFunc-vsum vecs 0))
 
 (defun calcFunc-vprod (&rest vecs)
-  (math-reduce-many-vecs 'calcFunc-mul 'calcFunc-vprod vecs 1)
-)
+  (math-reduce-many-vecs 'calcFunc-mul 'calcFunc-vprod vecs 1))
 
 (defun calcFunc-vmax (&rest vecs)
   (if (eq (car-safe (car vecs)) 'sdev)
     (if (eq (car-safe (car vecs)) 'intv)
        (nth 3 (math-fix-int-intv (car vecs)))
       (math-reduce-many-vecs 'calcFunc-max 'calcFunc-vmax vecs
-                            '(neg (var inf var-inf)))))
-)
+                            '(neg (var inf var-inf))))))
 
 (defun calcFunc-vmin (&rest vecs)
   (if (eq (car-safe (car vecs)) 'sdev)
     (if (eq (car-safe (car vecs)) 'intv)
        (nth 2 (math-fix-int-intv (car vecs)))
       (math-reduce-many-vecs 'calcFunc-min 'calcFunc-vmin vecs
-                            '(var inf var-inf))))
-)
+                            '(var inf var-inf)))))
 
 (defun math-reduce-many-vecs (func whole-func vecs ident)
   (let ((const-part nil)
          (if symb-part
              (funcall func const-part (cons whole-func symb-part))
            const-part))
-      (if symb-part (cons whole-func symb-part) ident)))
-)
+      (if symb-part (cons whole-func symb-part) ident))))
 
 
 ;;; Return the number of data elements among the arguments.
                                    (symbol-value (nth 2 (car vecs)))))
                        (math-reject-arg (car vecs) 'numvecp))))
            vecs (cdr vecs)))
-    count)
-)
+    count))
 
 (defun math-count-elements (vec)
   (let ((count 0))
       (setq count (if (Math-vectorp (car vec))
                      (+ count (math-count-elements (car vec)))
                    (1+ count))))
-    count)
-)
+    count))
 
 
 (defun math-flatten-many-vecs (vecs)
                                                     (nth 2 (car p))))
                             (math-reject-arg (car p) 'numvecp)))))
            p (cdr p)))
-    vec)
-)
+    vec))
 
 (defun calcFunc-vflat (&rest vecs)
-  (math-flatten-many-vecs vecs)
-)
+  (math-flatten-many-vecs vecs))
 
 (defun math-split-sdev-vec (vec zero-ok)
   (let ((means (list 'vec))
                      exact t))
            (setq means (cons p means)))))
       (list (nreverse means)
-           (and wts (nreverse wts)))))
-)
+           (and wts (nreverse wts))))))
 
 
 ;;; Return the arithmetic mean of the argument numbers or vectors.
                                           (calcFunc-map '(var div var-div)
                                                         means sqrwts))
                          suminvsqrwts))
-           (math-div (calcFunc-reduce '(var add var-add) means) len))))))
-)
+           (math-div (calcFunc-reduce '(var add var-add) means) len)))))))
 
 (defun math-fix-int-intv (x)
   (if (math-floatp x)
       x
     (list 'intv 3
          (if (memq (nth 1 x) '(2 3)) (nth 2 x) (math-add (nth 2 x) 1))
-         (if (memq (nth 1 x) '(1 3)) (nth 3 x) (math-sub (nth 3 x) 1))))
-)
+         (if (memq (nth 1 x) '(1 3)) (nth 3 x) (math-sub (nth 3 x) 1)))))
 
 ;;; Compute the mean with an error estimate.
 (defun calcFunc-vmeane (&rest vecs)
                                                           means
                                                           (math-neg mean)))
                                            2))
-                            (math-mul len (1- len))))))))))
-)
+                            (math-mul len (1- len)))))))))))
 
 
 ;;; Compute the median of a list of values.
        (setq flat (sort flat 'math-lessp))
        (if (= (% len 2) 0)
            (math-div (math-add (nth (1- hlen) flat) (nth hlen flat)) 2)
-         (nth hlen flat)))))
-)
+         (nth hlen flat))))))
 
 
 (defun calcFunc-vgmean (&rest vecs)
        (let ((x (calcFunc-reduce '(var mul math-mul) flat)))
          (if (= len 2)
              (math-sqrt x)
-           (math-pow x (list 'frac 1 len)))))))
-)
+           (math-pow x (list 'frac 1 len))))))))
 
 
 (defun calcFunc-agmean (a b)
               (setq mean (math-mul-float (math-add-float a b) '(float 5 -1))
                     b (math-sqrt-float (math-mul-float a b))
                     a mean))
-            a))))
-)
+            a)))))
 
 
 (defun calcFunc-vhmean (&rest vecs)
       (math-with-extra-prec 2
        (math-div len
                  (calcFunc-reduce '(var add math-add)
-                                  (calcFunc-map '(var inv var-inv) flat))))))
-)
+                                  (calcFunc-map '(var inv var-inv) flat)))))))
 
 
 
       (if (eq (car-safe (car vecs)) 'intv)
          (math-intv-variance (car vecs) nil)
        (math-sqr (nth 2 (car vecs))))
-    (math-covariance vecs nil nil 0))
-)
+    (math-covariance vecs nil nil 0)))
 
 (defun calcFunc-vsdev (&rest vecs)
   (if (and (= (length vecs) 1)
                        (math-sqrt-12))
            (math-sqrt (calcFunc-vvar (car vecs))))
        (nth 2 (car vecs)))
-    (math-sqrt (math-covariance vecs nil nil 0)))
-)
+    (math-sqrt (math-covariance vecs nil nil 0))))
 
 ;;; Compute the population variance or std deviation of numbers or vectors.
 (defun calcFunc-vpvar (&rest vecs)
       (if (eq (car-safe (car vecs)) 'intv)
          (math-intv-variance (car vecs) t)
        (math-sqr (nth 2 (car vecs))))
-    (math-covariance vecs nil t 0))
-)
+    (math-covariance vecs nil t 0)))
 
 (defun calcFunc-vpsdev (&rest vecs)
   (if (and (= (length vecs) 1)
                        (math-sqrt-12))
            (math-sqrt (calcFunc-vpvar (car vecs))))
        (nth 2 (car vecs)))
-    (math-sqrt (math-covariance vecs nil t 0)))
-)
+    (math-sqrt (math-covariance vecs nil t 0))))
 
 (defun math-intv-variance (x pop)
   (or (math-constp x) (math-reject-arg x 'constp))
                  (calcFunc-sum '(^ (- (var X var-X) (/ 1 2)) 2)
                                '(var X var-X)
                                (math-neg hlen) (math-add hlen 1)))
-               (if pop (math-add len 1) len))))
-)
+               (if pop (math-add len 1) len)))))
 
 ;;; Compute the covariance and linear correlation coefficient.
 (defun calcFunc-vcov (vec1 &optional vec2)
-  (math-covariance (list vec1) (list vec2) nil 1)
-)
+  (math-covariance (list vec1) (list vec2) nil 1))
 
 (defun calcFunc-vpcov (vec1 &optional vec2)
-  (math-covariance (list vec1) (list vec2) t 1)
-)
+  (math-covariance (list vec1) (list vec2) t 1))
 
 (defun calcFunc-vcorr (vec1 &optional vec2)
-  (math-covariance (list vec1) (list vec2) nil 2)
-)
+  (math-covariance (list vec1) (list vec2) nil 2))
 
 
 (defun math-covariance (vec1 vec2 pop mode)
               (if pop
                   suminvsqrwts
                 (math-div (math-mul suminvsqrwts (1- len)) len))
-            (if pop len (1- len))))))))
-)
-
-
+            (if pop len (1- len)))))))))
 
+(provide 'calc-stat)
 
+;;; arch-tag: 423858e9-8513-489c-9f35-710cd9d9c307
+;;; calc-stat.el ends here