Created
September 12, 2018 02:09
-
-
Save raddy/4084ade3d3a82911d43df9375f9697f4 to your computer and use it in GitHub Desktop.
Sample from a distribution with known skew and kurtosis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import statsmodels.sandbox.distributions.extras as extras | |
import scipy.interpolate as interpolate | |
import numpy as np | |
def generate_normal_four_moments(mu, sigma, skew, kurt, size=1000, sd_wide = 10): | |
f = extras.pdf_mvsk([mu, sigma, skew, kurt]) | |
x = np.linspace(mu - sd_wide * sigma, mu + sd_wide * sigma, num=500) | |
y = [f(i) for i in x] | |
yy = np.cumsum(y) / np.sum(y) | |
inv_cdf = interpolate.interp1d(yy, x, fill_value="extrapolate") | |
rr = np.random.rand(size) | |
return inv_cdf(rr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you're correct looking at the pdf_mvsk implementation:
Let me play with some numbers to sanity check!