;; some tests for statistics package (require-extension srfi-42) (require-extension srfi-78) (require-extension statistics) ;; -- to help the tests (define (to-4-dp f) (/ (round (* f 10000)) 10000)) (define (to-5-dp f) (/ (round (* f 100000)) 100000)) (define (=4 n1 n2) (= (to-4-dp n1) (to-4-dp n2))) (define (=5 n1 n2) (= (to-5-dp n1) (to-5-dp n2))) ;; -- tests of utilities (check (average-rank 3 '(1 2 3 4 5)) => 3) (check (average-rank 3 '(1 2 3 3 4 5)) => 7/2) (check (beta-incomplete 0.2 0.1 0.3) (=> =5) 0.28367) (check (bin-and-count '(1 2 3 4 5 6 7 8 9 10) 2) => (vector 5 5)) (check (bin-and-count '(1 2 3 4 5 6 7 8 9 10) 5) => (vector 2 2 2 2 2)) (check (bin-and-count '(1 2 2 2 3 9) 2) => (vector 5 1)) (check (combinations 10 3) => 120) (check (factorial 10) => 3628800) ; find-critical-value (check (fisher-z-transform 0.1) (=> =5) 0.10034) (check (fisher-z-transform 0.5) (=> =5) 0.54931) (check (let-values (((a b) (gamma-incomplete 2.0 1.5))) (list (to-5-dp a) b)) => (list 0.44217 0.0)) (check (gamma-ln 0.5) (=> =5) 0.57236) (check (permutations 10 3) => 720) ; random-normal: unsure how to test (check (random-pick '(1 2 3 4 5)) (=> member) '(1 2 3 4 5)) (check (random-sample 3 '(1 2 3 4 5)) (=> (lambda (result expected) (= (length result) expected))) 3) (check (sign 3.5) => 1) (check (sign -3.5) => -1) (check (sign 0) => 0) (check (square 10) => 100) ;; -- tests of descriptive statistics (check (mean '()) => 0) (check (mean '(1)) => 1) (check (mean '(1 2 3 4 5)) => 3) (check (median '(1)) => 1) (check (median '(1 2 3 4 5)) => 3) (check (median '(1 1 2 3 4 5 6 7 8)) => 4) (check (let-values (((modes counts) (mode '(1 1 1 2 3 4 5)))) (list modes counts)) => '((1) 3)) (check (let-values (((modes counts) (mode '(1 1 1 2 3 4 4 4 5)))) (list modes counts)) => '((1 4) 3)) (check (geometric-mean '(1 100)) => 10.0) (check (geometric-mean '(1 2 3 4 5)) (=> =5) 2.60517) (check (range '(1 2 3 4 5)) => 4) (check (range '(1 1 1 2 3 4 10)) => 9) (check (percentile '(1 2 3 4 5 6) 50) => 7/2) (check (percentile '(1 2 3 4 5 6) 30) => 2) (check (variance '(1 2 3 4 5)) => 5/2) (check (standard-deviation '(1 2 3 4 5)) (=> =5) 1.58113883) (check (coefficient-of-variation '(1 2 3 4 5)) (=> =5) 52.704627) (check (standard-error-of-the-mean '(1 2 3 4 5)) (=> =5) 0.707106781186548) (let-values (((mean sd n) (mean-sd-n '(1 2 3 4 5)))) (check mean => 3) (check sd (=> =5) 1.58113883008419) (check n => 5)) ;; -- tests of distributional functions (check-ec (: pair '((0 0.0009765625) (1 0.009765625) (2 0.0439453125) (3 0.1171875) (4 0.205078125) (5 0.24609375) (6 0.205078125) (7 0.1171875) (8 0.0439453125) (9 0.009765625) (10 0.0009765625))) (binomial-probability 10 (car pair) 0.5) (=> =5) (cadr pair)) (check-ec (: pair '((0 0.0) (1 0.0009765625) (2 0.0107421875) (3 0.0546875) (4 0.171875) (5 0.376953125) (6 0.623046875) (7 0.828125) (8 0.9453125) (9 0.9892578125) (10 0.9990234375))) (binomial-cumulative-probability 10 (car pair) 0.5) (=> =5) (cadr pair)) (check-ec (: pair '((0 0.0000) (1 0.0005) (2 0.0023) (3 0.0076) (4 0.0189) (5 0.0378) (6 0.0631) (7 0.0901) (8 0.1126) (9 0.1251) (10 0.1251) (11 0.1137) (12 0.0948) (13 0.0729) (14 0.0521) (15 0.0347) (16 0.0217) (17 0.0128) (18 0.0071) (19 0.0037))) (poisson-probability 10 (car pair)) (=> =4) (cadr pair)) ;; -- tests of confidence intervals ;; -- tests of hypothesis testing ;; -- tests of sample size estimates ;; -- tests of correlation and regression ;; -- tests of significance tests ;; -- summarise results of tests ;(check-report) ;; uncomment for released version - replace N with number of tests (if (check-passed? 43) 'ok (error "failed test suite"))