开发者

how to generate random numbers that follow skew normal distribution in matlab

I have probability de开发者_开发技巧nsity function of skew normal distribution.I want to generate random number that follow the skew normal distribution in matlab.


Can't vouch for their performance/adequacy, but http://azzalini.stat.unipd.it/SN/ says the following, and has a link to a .zip file of MATLAB functions:

The library has been ported to Matlab by Nicola Sartori. So far, this refers to update 0.21; hence facilities for the skew-t distribution are not included. A portion of the facilities for the skew-t distribution is however available via a set of Matlab functions which have been written and made available by Enrique Batiz (Enrique.Batiz [at] postgrad.mbs.ac.uk)

Also see this code which is in visual Basic, but should be easily portable. Relevant excerpt shown below. This uses RandNorm (also in the linked webpage) which is a pair of numbers from a unit normal distribution, and in MATLAB you should be able to use randn(2,1).

Function RandSkew(fAlpha As Single, _
                  Optional fLocation As Single = 0, _
                  Optional fScale As Single = 1, _
                  Optional bVolatile As Boolean = False) As Single

    ' shg 2008-0919
    ' http://azzalini.stat.unipd.it/SN/faq.html

    ' Returns a random variable with skewed distribution
    '       fAlpha      = skew
    '       fLocation   = location
    '       fScale > 0  = scale

    Dim sigma   As Single
    Dim afRN()  As Single
    Dim u0      As Single
    Dim v       As Single
    Dim u1      As Single

    If bVolatile Then Application.Volatile
    Randomize (Timer)

    sigma = fAlpha / Sqr(1 + fAlpha ^ 2)

    afRN = RandNorm()
    u0 = afRN(1)
    v = afRN(2)
    u1 = sigma * u0 + Sqr(1 - sigma ^ 2) * v

    RandSkew = IIf(u0 >= 0, u1, -u1) * fScale + fLocation
End Function
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜