2
$\begingroup$

My apologies if this is a trivial question, but I am having trouble with this for a while now.

I need to use a skew-normal distribution in research in MATLAB and the only way I found after googling was to use Pearsrnd, as given in here.

Now, I did the math and wrote function skewnormal function in MATLAB as follows:

    %% The helper function calculating parameters for skew-normal using pearsrnd
function [m,s, sk, kurt] = skewnormal(a, e, w)
    c = sqrt(2/pi); % it is used a lot in what follows
    d = a/sqrt(1+a*a); % temp variable
    m = e + d*w*c; % mean 
    s = w*sqrt(1 - d^2*c^2); % variance
    sk = (4 - pi)/2*(d*c*w/s)^3; % skewness
    kurt = 3 + 2*(pi-3)*(d*c*w/s)^4; % kurtosis accounted for the matlab convention.
end

Then, when I use the above in my code and return the type of the Pearsrnd, it returns $1$ - which is apparently Four parameters Beta distribution in Pearsrnd.

I did look for answers here that could immediately answer but I did not find any.

Can anyone fix my attempt at generating Skew-Normal distribution, since I am clearly doing something wrong?

$\endgroup$
2
  • 1
    $\begingroup$ If the question is just how to use pearsrnd just drop an e-mail to MathWorks support. These are pretty much bread and butter for them. $\endgroup$
    – usεr11852
    Apr 16 '20 at 12:11
  • 1
    $\begingroup$ @dezdichado does the answer I've provided give you what you were looking for or is there additional context not in the OP? Reason I ask is b/c my answer hasn't been marked correct and we're coming up on the end of bounty period, see e.g. stats.stackexchange.com/help/bounty for policies on bounties. If I've missed something please let me know. $\endgroup$ Apr 21 '20 at 17:09
1
+50
$\begingroup$

I think you can use the following approach: First you need the command to generate a "standard normal", e.g. N(0,1)

https://www.mathworks.com/help/stats/normrnd.html

then given 2 random normals, you can use the following formula:

$$ Y = \mu + \sigma \left(\delta|T_0| + T_1\sqrt{1-\delta^2}\right), $$where

$$ \delta = \frac{\lambda}{\sqrt{1+\lambda^2}} $$ from here, where $T_0,T_1$ are both standard normal random variates. Also, the values $\mu, \sigma, \lambda$ are parameters/arguments to the function so I assume those 3 parameters are given.

In code this looks something like:

t0 = normrnd(0,1)
t1 = normrnd(0,1)
d  = _lambda / sqrt(1 + _lambda*_lambda)
y  = mu + sigma * (d * abs(t0) + t1 * sqrt(1 - d * d))

Of course, if you want to you can wrap that into a function in matlab. I don't really know matlab so if the syntax isn't the greatest, please adjust accordingly. Hopefully, the logical calculations are simple enough that you can modify appropriately for your uses.

EDIT: The $\delta$ or equivalently, the $\lambda$ is the parameter that determines the extent and nature (positive or negative) of the skew.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.