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?
Best Answer
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:
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.