0
num_runs = 100000
p_values = []

for i in range(1, num_runs+1):
    ornek1 = 2*np.random.normal(0,1,5)
    ornek2 = 3*np.random.normal(0,2,5)
    ornek3 = 10*np.random.normal(0,5,5)
    

    
    levene = sp.levene(ornek1,ornek2,ornek3, center = 'mean')
    
    if levene[1] < 0.05:
    
        ornek1 = np.log10(ornek1)
        ornek2 = np.log10(ornek2)
        ornek3 = np.log10(ornek3)
        
    else: 
        continue
    
    anova = sp.f_oneway(ornek1,ornek2,ornek3)
    p_values.append(anova[1])
    
hesap = sum(map(lambda x: x<0.05, p_values))
print(hesap/100000)


RuntimeWarning: invalid value encountered in log10
  ornek1 = np.log10(ornek1)

How can I fix this problem ? I can't find anything. I want to transform my samples after levene test but ı can't. Is it about to numpy ?

1
  • Is this scipy related? Where is the import libs? -- what's sp Commented Jul 21, 2022 at 20:50

1 Answer 1

1

Just as a sample:

>>> np.random.normal(0, 1, 5)
array([ 1.68127583, -0.82660143, -1.82465141,  0.60495851, -0.90369304])

You're taking the log of negative numbers. What are you expecting to happen?

Sign up to request clarification or add additional context in comments.

2 Comments

I know. It occurs when the datas are positive.
How do you know the numbers are positive? You're getting 15 random numbers with a mean of 0. So the probabilities that all of them are positive is extremely low. You're also getting precisely the warning message that numpy generates for a negative number (and it returns the value NaN).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.