Standard Deviation with Racket

Diaspora* comments introduced me to Howard Wainer's statistics articles and inspired me to learn some statistics. (fn:1) A WikiHow page helped me, (fn:2) and got back into the Racket documentation. (fn:3) But since I was talking with a statistics teacher about getting students ready for his class by establishing a base with DrRacket and algebra, it seemed like a good idea to do all the WikiHow steps in Racket, before using the convenience functions from math/statistics

DrRacket Code

#lang racket
;; https://www.wikihow.com/Calculate-Standard-Deviation
(define data-set (list 10 8 10 8 8 4))
(display "data-set")(newline)
data-set

(define n (length data-set))
n

(define d-s-sum (apply + data-set))
d-s-sum


(define mean-average (/ d-s-sum n))
mean-average

(define mean-difs
  (map (lambda (x) (- x mean-average)) data-set))
mean-difs

(define squared-difs
  (map (lambda (x) (* x x))
      mean-difs))
squared-difs

(define sum-of-squares
  (apply + squared-difs))
sum-of-squares

(define d-s-variance (/ sum-of-squares (- n 1)))
d-s-variance
(exact->inexact d-s-variance)

(define d-s-standard-deviation
    (sqrt d-s-variance))
d-s-standard-deviation

(require math/statistics)
;; https://docs.racket-lang.org/math/stats.html
(display "math/statistics")
(newline)
(variance data-set)
(stddev data-set)
(stddev data-set #:bias #t)

footnotes

#DrRacket #statistics #math #WikiHow