2

I am trying to generate 1000 sets of 130 random numbers which fit with the skewed normal distribution of the numbers below:

-10.4, -9.3, -6.8, -4.8, -5.7, 5.8, -4.5, -3.4, -2, 0.3, -0.4, -4.1, -6.9, -5.9, -2.5, -2, -2.8, -3.2, -4.4, -2, -1.4, 0.9, -1, -4.1, -11.7, 0.1

The mean of these numbers is -3.99, the standard deviation is 3.17, the skew is -0.71 and the kurtosis is 0.22.

To get my 1000 sets of 130 random numbers, I've tried this:

install.packages("sn")
library(sn)

p <- rmsn(n = 130, 
          xi = rep(-3.99, 1000), 
          Omega = diag(1000), 
          alpha = rep(-0.71, 1000), 
          tau = -0.71)

I get 1000 vectors of 130 random numbers with mean -3.99. However, they don't have skew -0.71, and I have no idea how to set the standard deviation at 3.17 or the kurtosis at 0.22.

Any help would be much appreciated!

thekingzapper
  • 93
  • 1
  • 10
  • I think ```rsnorm()``` is the best option from the ```fGarch``` package, but I can't see a way to set the standard deviation or to get more than one vector. – thekingzapper Feb 28 '20 at 17:35
  • 1
    Is this a potential duplicate of https://stackoverflow.com/questions/4807398/how-to-generate-distributions-given-mean-sd-skew-and-kurtosis-in-r ? – Jim Kloet Feb 28 '20 at 17:48

1 Answers1

5

With the function cp2dp you can convert from the population mean, the population standard deviation and the population skewness to the parameters xi, omega and alpha of the skew-normal distribution.

library(sn)
params <- cp2dp(c(-3.99, 3.17, -0.71), "SN")
sims <- replicate(1000, rsn(130, dp = params))

The SN family only supports skew between -0.99527 and 0.99527. Outside of this range, the ST family is needed, which requires a fourth variable: kurtosis:

library(sn)
params <- cp2dp(c(-3.99, 3.17, -1.71, 2.37), "ST")
sims <- replicate(1000, rst(130, dp = params))

Note the use of rst instead of rsn in this case.

thekingzapper
  • 93
  • 1
  • 10
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
  • This is great, but when the skew is greater than 1 or less than -1, ```cp2dp()``` gives this error: ```gamma1 outside admissible range``` – thekingzapper Feb 28 '20 at 18:49