Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtimewarning: Divide By zero #60

Open
TomPCurran opened this issue Jan 20, 2018 · 1 comment
Open

Runtimewarning: Divide By zero #60

TomPCurran opened this issue Jan 20, 2018 · 1 comment

Comments

@TomPCurran
Copy link

Whenever I pass in my distribution into the function that calculates the lognormal pdf I get the following error:

def lognormal_pdf(x, sigma, mu):
    '''

    Function will create the lognormal probability density function of the given
    x values (x) based on the average and standard deviation provided through the
    sigma and mu arguments

    ----------------------------------------------------------------------------

    x:

    sigma:

    mu:
    
    '''
    pdf_values = (1/(x*sigma*np.sqrt(x*np.pi)))*np.exp(-1 * (((np.log(x)-mu)**2)/(2*sigma**2)))

#create a list of evenly spaced numbers between 0 and 150,000

income_range = np.linspace(0,150000,200)

#pass the income_range variable into the lognormal_pdf() function to get the 
#log normal disribution of incomes based on the sigma = .5 and mu = 11

sigma = .5
mu = 11

lognormal_pdf(income_range, sigma, mu)

output:

/Users/thomascurran/anaconda/lib/python3.6/site-packages/ipykernel_launcher.py:17: RuntimeWarning: divide by zero encountered in true_divide
/Users/thomascurran/anaconda/lib/python3.6/site-packages/ipykernel_launcher.py:17: RuntimeWarning: divide by zero encountered in log
/Users/thomascurran/anaconda/lib/python3.6/site-packages/ipykernel_launcher.py:17: RuntimeWarning: invalid value encountered in multiply

do I need to include the prob_notcut variable like the lognormal function as in the MLE notebook from class?

@cernhofer
Copy link
Collaborator

The values in your income_range variable are what's causing the error- instead of setting the start to zero, try a small number like 0.01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants