                             (reduce + (map square (sub Y (mean Y))))) 2)))
 
 (double (:scale (posterior Y (normal :mu :s2) (normal-inverse-gamma prior-mean prior-lambda prior-shape prior-scale))))
+
+
+(variance (t-distribution 4))
+(variance (t-distribution 4 0 10))
+
+(* (variance (t-distribution (* 2 prior-shape)))  (/ (* prior-scale (+ 1 prior-lambda)) (* prior-lambda prior-shape)))
+(variance (map (fn [[mu s2]] (sample (normal mu s2))) (sample (normal-inverse-gamma prior-mean prior-lambda prior-shape prior-scale) 100000)))
+(variance (marginal (normal :mu :s2) (normal-inverse-gamma prior-mean prior-lambda prior-shape prior-scale)))
+(variance (sample (marginal (normal :mu :s2) (normal-inverse-gamma prior-mean prior-lambda prior-shape prior-scale)) 10000))
+
+(* (variance (t-distribution (* 2 prior-shape))) (/ (* prior-lambda prior-shape) prior-scale))
+(variance (map first 
+               (sample (normal-inverse-gamma prior-mean prior-lambda prior-shape prior-scale) 10000)))
+
+(double (variance (inverse-gamma 10 10 )))
+(variance (sample (inverse-gamma 10 10) 100000))
+
+(def d (inverse-gamma 10 3))
+(double (variance d))
+(variance (sample d 100000))
+
+
+
+
+(variance (map (fn [[mu s2]] (sample (normal mu s2))) (sample (normal-inverse-gamma 4 2 1000 4) 100000)))
+(variance (map second (sample (normal-inverse-gamma 4 3 5 4) 10000)))
+(variance (inverse-gamma 5 4))
+(variance (sample (marginal (normal :mu :s2) (normal-inverse-gamma 4 2 1000 4)) 100000))
+(variance (marginal (normal :mu :s2) (normal-inverse-gamma 4 2 1000 4)))
+(variance (t-distribution 30000 3 10))
+
 )

         prior-location :location} prior]
    (t-distribution (* 2 prior-shape)
                    prior-location
                    (/ (* prior-scale (+ 1 prior-lambda))
                       (* prior-lambda prior-shape)))))

(comment 
(sample (marginal (normal :mu :s2) (normal-inverse-gamma 2 3 1 2)))


(defrecord NormalInverseGamma [location lambda shape scale]
  random
  (sample [d] (let [s2 (sample (inverse-gamma shape scale))
                    mu (sample (normal location (/ s2 lambda)))]
                [mu s2]))
  (sample [d n] (take n (repeatedly #(sample d))))
  probability-function
