• incanter

# sample-inv-wishart

## incanter.stats

• (sample-inv-wishart & options)

Returns a p-by-p symmetric distribution drawn from an inverse-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-inv-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/Inverse-Wishart_distribution

### Source incanter/stats.clj:986 top

```(defn sample-inv-wishart
"
Returns a p-by-p symmetric distribution drawn from an inverse-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-inv-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/Inverse-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)]
(solve (sample-wishart :p p :df df :scale scale)))))```
Vars in incanter.stats/sample-inv-wishart: defn let
Used in 0 other vars