The average value of the dispersion of the sample and the dispersion are not close to the average value of the distribution and dispersion

I answered the question regarding the creation of samples with positive support and the known value and variance using gamma distribution in NumPy . I thought I would try the same at Incanter . But unlike the results that I got with NumPy , I could not get a sample mean and variance close to the average of the distribution and variance.

(defproject incanter-repl "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.6.0"]
                 [incanter "1.5.4"]])

(require '[incanter 
           [core] 
           [distributions :refer [gamma-distribution mean variance draw]] 
           [stats :as stats]])

(def dist 
  (let [mean 0.71 
        variance 2.89 
        theta (/ variance mean) 
        k (/ mean theta) ] 
    (gamma-distribution k theta)))

Incanter calculates the mean and variance of the distribution

(mean dist) ;=> 0.71
(variance dist) ;=> 2.89

I calculate the sample mean and variance based on none of this distribution

(def samples (repeatedly 10000 #(draw dist)))

(stats/mean samples) ;=> 0.04595208774029654
(stats/variance samples) ;=> 0.01223348345651905

, , , . ?

Incanter , Parallel Colt. Parallel Colt. . https://github.com/incanter/incanter/issues/245.

+4
1

numpy.random.gamma, (k) (theta) , clojures gamma-distribution (k) (1/theta) . . (doc gamma-distribution) http://en.wikipedia.org/wiki/Gamma_distribution

, , dist

(def dist 
  (let [mean 0.71 
        variance 2.89 
        r (/ mean variance) 
        k (* mean r) ] 
    (gamma-distribution k r)))

(def samples (repeatedly 10000 #(draw dist)))
#'incanter-test.core/samples
incanter-test.core=> (stats/mean samples)
0.7163908381930312
incanter-test.core=> (stats/variance samples)
2.940867216122528
+4

Source: https://habr.com/ru/post/1537177/


All Articles