vendredi 31 août 2018

How to draw random numbers in python from a normal distribution with given mean, variance, skewness and kurtosis

I'm trying to draw random numbers from a normal distribution with given mean, variance, skewness and kurtosis.

My first attempt was to use the numpy function random.normal however to this function as far as i understand i can only pass a location (mean) and a scale (std) parameter.

Second attempt is to draw random numbers from the uniform distribution in the interval [0,1] and then pass them through the scipy.stats.norm method ppf. I see that scipy has the ability to treat skewness and kurtosis, however i cannot see how i can pass skewness and kurtosis values into the function.

If the problem should be solved in an entirely different way please let me know.

Attempt 1:

import numpy as np

def draw_normal():
    return np.random.normal(loc=0, scale=1) # how to pass skew and kurtosis (excess kurtosis) to the function 

Attempt 2

import numpy as np
from scipy.stats import norm


def draw_uniform():
    return np.random.uniform(0,1)

def draw_normal_alt():
    return norm.ppf(draw_uniform(),loc=0, scale=1) #how to pass skew and kurtosis (excess kurtosis) to func




Aucun commentaire:

Enregistrer un commentaire