Fede O.
Fede O.

Reputation: 21

scipy AttributeError, cant seem to fix it

I'm doing some statistics with t and z, z is working fine, but when I run with an AttributeError with t, specifically: AttributeError: 'float' object has no attribute 'sf'

Now, this is the code that is giving me this error:

    if n >= 30: #i've tried with n being an int and float, error still
        z()
    else:
        gl = n - 1 
        t()

 t = ((xmuestral - mu) / (desv / (math.sqrt(n)))) #i've tried making this into int, error still
 p_value = t.sf(t, gl)

Of course, xmuestral, mu, desv and n are float to get an accurate result, and gl, no matter if Float or Integer gives me the same problem, now, if I try to convert everything into an Integer, now it simply throws AttributeError: 'int' object has no attribute 'sf'

honestly i'm stuck, i dont know how to make it work

Upvotes: 0

Views: 75

Answers (1)

Siong Thye Goh
Siong Thye Goh

Reputation: 3586

t is a float, hence you can't call t.sf. Naming matters.

>>> from scipy import stats
>>> import math
>>> mu = 5
>>> desv = 0.03
>>> n = 8
>>> xmuestral = 5.1
>>> s = ((xmuestral - mu) / (desv / (math.sqrt(n))))
>>> pval = stats.t.sf(s, n-1)
>>> pval
1.5749970000865015e-05

Remark: Also, it seems that you are using t as a function as well. It might not be a good practice.

Upvotes: 2

Related Questions