File: bcdemo.lsp

package info (click to toggle)
xlispstat 3.52.14-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,560 kB
  • ctags: 12,676
  • sloc: ansic: 91,357; lisp: 21,759; sh: 1,525; makefile: 521; csh: 1
file content (50 lines) | stat: -rw-r--r-- 1,542 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
;; define a function to compute the Box-Cox transformation
(defun bc (x c p)
  (let* ((x (- x c))
         (bcx (if (< (abs p) .0001)
                  (log x)
                  (/ (^ x p) p)))
         (min (min bcx))
         (max (max bcx)))
    (/ (- bcx min) (- max min))))


;; get a sorted sample from a shi-squared distribution
(def x (sort-data (chisq-rand 30 4)))

;; compute the normal quantiles of the expected uniform order statistics
(def r (normal-quant (/ (iseq 1 30) 31)))

;; construct an initial plot without transformation
(def myplot (plot-points r (bc x 0 1)))

;;;
;;; First approach: compute as needed
;;;
;; construct a dialog for scrolling through powers and recomputing the
;; plot
#|
(interval-slider-dialog (list -1 2)
                        :points 20
                        :action #'(lambda (p)
                                   (send myplot :clear nil)
                                   (send myplot 
                                         :add-points r (bc x 0 p))))
|#
;;;
;;; Second aproach: precompute
;;;
;; construct a list of powers
(def powers (rseq -1 2 16))

;; compute transformed data for each power
(def xlist (mapcar #'(lambda (p) (bc x 0 p)) powers))

;; construct a dialog for scrolling through the list of data sets
;; and redrawing the plot
(sequence-slider-dialog xlist
                        :display powers
                        :action #'(lambda (x)
                                   (send myplot :clear nil)
                                   (send myplot :add-points r x)))