简体   繁体   English

从Wishart分布中取样,其中p为1 <df <p

[英]Sampling from Wishart distribution with p-1 < df < p in R

I need to sample a matrix from a Wishart distribution with degrees of freedom smaller than the dimensionality of the scale matrix. 我需要从Wishart分布中采样矩阵,其自由度小于比例矩阵的维数。 I'm struggling to find an R function that allows it. 我很难找到允许它的R功能。

For a Wishart distribution, the degrees of freedom (call them df or v) must be greater than the dimensionality of the scale matrix (say p) minus 1 (ie df > p - 1 ) (see https://en.wikipedia.org/wiki/Wishart_distribution or any manual on the Wishart distribution). 对于Wishart分布,自由度(称为df或v) 必须大于比例矩阵的维度(比如p)减1(即df> p - 1 )(参见https://en.wikipedia。 org / wiki / Wishart_distribution或Wishart发行版的任何手册)。 However, when I try to sample from a wishart distribution with p-1 < df < p , say W(df = 1.1, I_p), where I_p is a pxp identity matrix, I get errors stating inconsistency of the degrees of freedom . 然而,当我尝试从具有p-1 <df <p的Wishart分布中进行采样时,比如W(df = 1.1,I_p),其中I_p是pxp单位矩阵,我得到错误,表明自由度的不一致

Say that p = 2, I want to sample from different Wishart distributions with df between 1 and 2 (excluded) but 假设p = 2,我想从不同的Wishart分布中采样,df在1和2之间(排除)但是

stats::rWishart(n = 1, df = 1.1, Sigma = diag(2)) # does not work
MCMCpack::rwish(v = 1.1, S = diag(2)) # does not work

do not work. 不工作。

I thought the problem might have been the non-integer degrees of freedom, but 我认为问题可能是非整数自由度,但是

stats::rWishart(n = 1, df = 2.1, Sigma = diag(2))
MCMCpack::rwish(v = 2.1, S = diag(2))

work without any problem. 工作没有任何问题。

I did find 我找到了

  rWishart::rWishart(1, df = 1.1, Sigma = diag(2)) # works

which works, but then it doesn't if 1.5 =< df < 2 哪个有效,但如果1.5 = <df <2则不然

  rWishart::rWishart(1, df = 1.5, Sigma = diag(2)) # does not works

I would like to find way in R to sample from a Wishart distribution which has any degrees of freedom bigger than p-1 but smaller than p (p-1 < df < p). 我想在R中找到从Wishart分布中采样的方法,该分布具有大于p-1但小于p(p-1 <df <p)的任何自由度。 And it doesn't strictly matter to me whether the sampled matrix is singular or not. 对我来说,采样矩阵是否是单数并不严格。

As far as I know, matrixsampling is the only package offering this possibility (I am its author). 据我所知, matrixsampling是唯一提供这种可能性的软件包(我是它的作者)。

library(matrixsampling)
rwishart(3, nu = 1.1, Sigma = diag(2))
# , , 1
# 
#            [,1]      [,2]
# [1,]  0.7679333 -1.051319
# [2,] -1.0513191  1.439281
# 
# , , 2
# 
#            [,1]       [,2]
# [1,]  1.8536154 -0.9059983
# [2,] -0.9059983  0.4449708
# 
# , , 3
# 
#           [,1]      [,2]
# [1,] 0.9309460 0.6026472
# [2,] 0.6026472 0.3901232

If you really want to sample with the identity matrix as the scale matrix Sigma , you can do: 如果您真的想使用单位矩阵作为比例矩阵Sigma进行采样,您可以:

matrixsampling:::rwishart_I(3, nu = 1.1, p = 2)

(to be honnest, I don't remember what I've done, but this should be more efficient). (说实话,我不记得我做过什么,但这应该更有效率)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM