1.2.3-SNAPSHOT Arrow_down_16x16

pdf-binomial

incanter.stats

  • (pdf-binomial x & options)
Returns the Bionomial pdf of the given value of x. It will return a sequence
of values, if x is a sequence. Same as R's dbinom

Options:
:size (default 1)
:prob (default 1/2)

See also:
cdf-binomial and sample-binomial

References:
http://incanter.org/docs/parallelcolt/api/cern/jet/random/tdouble/Binomial.html
http://en.wikipedia.org/wiki/Binomial_distribution
http://en.wikipedia.org/wiki/Probability_density_function

Example:
(pdf-binomial 10 :prob 1/4 :size 20)

1 Example top

  • # Compute P(45 < X < 55) for X Binomial(100,0.5)
    # see http://stat.ethz.ch/R-manual/R-patched/library/stats/html/Binomial.html
    
    ; In Clojure
    (map #(pdf-binomial % :size 100 :prob 0.5) (range 46 55))                                                                                                                            
    ;(0.05795839814029805 0.066590499990982 0.07352701040670805 0.07802866410508287 0.0795892373871834 0.07802866410508287 0.07352701040670805 0.066590499990982 0.05795839814029805)           
    
    (reduce + (map #(pdf-binomial % :size 100 :prob 0.5) (range 46 55))) 
    ; 0.6317983826733252
    
    
    ; In R
    ; > dbinom(46:54, 100, 0.5)
    ;[1] 0.05795840 0.06659050 0.07352701 0.07802866 0.07958924 0.07802866 0.07352701 0.06659050
    ;[9] 0.05795840
    ;> sum(dbinom(46:54, 100, 0.5))
    ;[1] 0.6317984
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source incanter/stats.clj:1068 top

(defn pdf-binomial
" Returns the Bionomial pdf of the given value of x. It will return a sequence
  of values, if x is a sequence. Same as R's dbinom

  Options:
    :size (default 1)
    :prob (default 1/2)

  See also:
      cdf-binomial and sample-binomial

  References:
      http://incanter.org/docs/parallelcolt/api/cern/jet/random/tdouble/Binomial.html
      http://en.wikipedia.org/wiki/Binomial_distribution
      http://en.wikipedia.org/wiki/Probability_density_function

  Example:
      (pdf-binomial 10 :prob 1/4 :size 20)
"
  ([x & options]
    (let [opts (when options (apply assoc {} options))
          n (or (:size opts) 1)
          p (or (:prob opts) 1/2)
          dist (Binomial. n p (DoubleMersenneTwister.))]
      (if (coll? x)
        (map #(.pdf dist %) x)
        (.pdf dist x)))))
Vars in incanter.stats/pdf-binomial: coll? defn let map
Used in 0 other vars

Comments top

No comments for pdf-binomial. Log in to add a comment.