Changeset 40389 in project


Ignore:
Timestamp:
08/24/21 21:27:18 (4 weeks ago)
Author:
Kon Lovett
Message:

simplify condition expression, reorder

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/5/micro-stats/trunk/micro-stats.scm

    r40388 r40389  
    299299(: yates-chi-square-component (real real --> real))
    300300
     301(define (yates-chi-square-component o e)
     302  (let ((r (- (abs (- o e)) 0.5)))
     303    (/ (* r r) e) ) )
     304
     305(define (chi-square-component o e)
     306  (let ((r (- o e)))
     307    (/ (* r r) e) ) )
     308
     309(define (chi-components component observed expected)
     310  (if (seq:sequence? expected)
     311    (seq:smap*
     312      *empty-vector*
     313      (lambda (s it) (component (seq:elt s it) (seq:elt expected (seq:index it))))
     314      observed)
     315    (seq:smap *empty-vector* (cut component <> expected) observed) ) )
     316
     317(define (chi-sample component observed expected)
     318  (seq:foldl + 0 (chi-components component observed expected)) )
     319
    301320(define (chi-square observed expected #!optional yates?)
    302321  (unless (seq:sequence? observed)
     
    311330    (chi-sample component observed expected) ) )
    312331
    313 (define (chi-sample component observed expected)
    314   (define (chi-components)
    315     (cond
    316       ((not (seq:sequence? expected))
    317         (seq:smap *empty-vector* (cut component <> expected) observed) )
    318       (else
    319         (seq:smap*
    320           *empty-vector*
    321           (lambda (s it) (component (seq:elt s it) (seq:elt expected (seq:index it))))
    322           observed))) )
    323   ;
    324   (seq:foldl + 0 (chi-components)) )
    325 
    326 (define (yates-chi-square-component o e)
    327   (let ((r (- (abs (- o e)) 0.5)))
    328     (/ (* r r) e) ) )
    329 
    330 (define (chi-square-component o e)
    331   (let ((r (- o e)))
    332     (/ (* r r) e) ) )
    333 
    334332) ;module micro-stats
Note: See TracChangeset for help on using the changeset viewer.