1.2.3-SNAPSHOT Arrow_down_16x16

sample-wishart

incanter.stats

  • (sample-wishart & options)

Returns a p-by-p symmetric distribution drawn from a Wishart distribution

Options:
:p (default 2) -- number of dimensions of resulting matrix
:df (default p) -- degree of freedoms (aka n), df <= p
:scale (default (identity-matrix p)) -- positive definite matrix (aka V)

Examples:
(use 'incanter.stats)
(sample-wishart :df 10 :p 4)

;; calculate the mean of 1000 wishart matrices, should equal (mult df scale)
(div (reduce plus (for [_ (range 1000)] (sample-wishart :p 4))) 1000)


References:
http://en.wikipedia.org/wiki/Wishart_distribution#

0 Examples top

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:949 top

(defn sample-wishart
"
  Returns a p-by-p symmetric distribution drawn from a Wishart distribution

  Options:
    :p (default 2) -- number of dimensions of resulting matrix
    :df (default p) -- degree of freedoms (aka n), df <= p
    :scale (default (identity-matrix p)) -- positive definite matrix (aka V)

  Examples:
    (use 'incanter.stats)
    (sample-wishart :df 10  :p 4)

    ;; calculate the mean of 1000 wishart matrices, should equal (mult df scale)
    (div (reduce plus (for [_ (range 1000)] (sample-wishart :p 4))) 1000)


  References:
    http://en.wikipedia.org/wiki/Wishart_distribution#

"
  ([& options]
    (let [opts (when options (apply assoc {} options))
          scale (or (:scale opts) (when (:p opts) (identity-matrix (:p opts))))
          p (count scale)
          df (or (:df opts) p)
          diagonal (for [i (range 1 (inc p))]
                     (pow (sample-chisq 1 :df (inc (- df i))) 1/2))
          mat (diag diagonal)
          indices (for [i (range p) j (range p) :when (< j i)] [i j])
          _ (doseq [indx indices] (.set mat (first indx) (second indx) (sample-normal 1)))
          chol (decomp-cholesky scale)
          x (mmult chol mat (trans mat) (trans chol))]
        x)))
Vars in incanter.stats/sample-wishart: defn let
Used in 0 other vars

Comments top

No comments for sample-wishart. Log in to add a comment.