* guile: add mu:correl, to calculate pearson's correlation coefficient between vars
This commit is contained in:
@ -25,6 +25,7 @@
|
|||||||
:export ( mu:tabulate
|
:export ( mu:tabulate
|
||||||
mu:average
|
mu:average
|
||||||
mu:stddev
|
mu:stddev
|
||||||
|
mu:correl
|
||||||
mu:max
|
mu:max
|
||||||
mu:min
|
mu:min
|
||||||
mu:weekday-numbers->names
|
mu:weekday-numbers->names
|
||||||
@ -84,6 +85,31 @@ EXPR (or #t for all). Returns #f if undefined."
|
|||||||
EXPR (or #t for all). Returns #f if undefined."
|
EXPR (or #t for all). Returns #f if undefined."
|
||||||
(apply min (map func (mu:message-list expr))))
|
(apply min (map func (mu:message-list expr))))
|
||||||
|
|
||||||
|
|
||||||
|
(define (correl lst)
|
||||||
|
"Calculate Pearson's correlation coefficient for a list LST of cons
|
||||||
|
pair, where the car and cdr of the pairs are values from data set 1
|
||||||
|
and 2, respectively."
|
||||||
|
(let ((n (length lst))
|
||||||
|
(sx (apply + (map car lst)))
|
||||||
|
(sy (apply + (map cdr lst)))
|
||||||
|
(sxy (apply + (map (lambda (cell) (* (car cell) (cdr cell))) lst)))
|
||||||
|
(sxx (apply + (map (lambda (cell) (* (car cell) (car cell))) lst)))
|
||||||
|
(syy (apply + (map (lambda (cell) (* (cdr cell) (cdr cell))) lst))))
|
||||||
|
(/ (- (* n sxy) (* sx sy))
|
||||||
|
(sqrt (* (- (* n sxx) (* sx sx)) (- (* n syy) (* sy sy)))))))
|
||||||
|
|
||||||
|
(define* (mu:correl func1 func2 #:optional (expr #t))
|
||||||
|
"Determine Pearson's correlation coefficient between the value for
|
||||||
|
functions FUNC1 and FUNC2 to all messages matching EXPR (or #t for
|
||||||
|
all). Returns #f if undefined."
|
||||||
|
(let ((data
|
||||||
|
(map (lambda (msg)
|
||||||
|
(cons (func1 msg) (func2 msg)))
|
||||||
|
(mu:message-list expr))))
|
||||||
|
(if data (correl data) #f)))
|
||||||
|
|
||||||
|
|
||||||
;; a list of abbreviated, localized day names
|
;; a list of abbreviated, localized day names
|
||||||
(define day-names
|
(define day-names
|
||||||
(map locale-day-short (iota 7 1)))
|
(map locale-day-short (iota 7 1)))
|
||||||
|
|||||||
Reference in New Issue
Block a user