Talk:Welch's t-test: Difference between revisions

→‎cannot run python libraries: move to Hailholyghost's talk page (the problem was unrelated to this task)
(→‎cannot run python libraries: move to Hailholyghost's talk page (the problem was unrelated to this task))
 
(12 intermediate revisions by 2 users not shown)
Line 1,203:
 
[[User:Eoraptor|Eoraptor]] ([[User talk:Eoraptor|talk]]) 21:31, 28 December 2017 (UTC)
 
==cannot run python libraries==
 
current numpy/scipy/scipy.stats will not run on my Ubuntu VM:
 
<lang python>
true
Traceback (most recent call last):
File "numpy_scipy_pvalue.py", line 3, in <module>
import scipy.stats
File "/usr/lib/python2.7/dist-packages/scipy/stats/__init__.py", line 344, in <module>
from .stats import *
File "/usr/lib/python2.7/dist-packages/scipy/stats/stats.py", line 173, in <module>
import scipy.special as special
File "/usr/lib/python2.7/dist-packages/scipy/special/__init__.py", line 643, in <module>
from ._ellip_harm import ellip_harm, ellip_harm_2, ellip_normal
File "/usr/lib/python2.7/dist-packages/scipy/special/_ellip_harm.py", line 7, in <module>
from ._ellip_harm_2 import _ellipsoid, _ellipsoid_norm
File "scipy/special/_ellip_harm_2.pyx", line 5, in init scipy.special._ellip_harm_2 (scipy/special/_ellip_harm_2.c:7330)
File "/usr/lib/python2.7/dist-packages/scipy/integrate/__init__.py", line 59, in <module>
from ._bvp import solve_bvp
File "/usr/lib/python2.7/dist-packages/scipy/integrate/_bvp.py", line 10, in <module>
from scipy.sparse.linalg import splu
File "/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/__init__.py", line 112, in <module>
from .isolve import *
File "/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/isolve/__init__.py", line 6, in <module>
from .iterative import *
File "/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/isolve/iterative.py", line 84, in <module>
def bicg(A, b, x0=None, tol=1e-5, maxiter=None, xtype=None, M=None, callback=None):
File "/usr/lib/python2.7/dist-packages/scipy/_lib/_threadsafety.py", line 59, in decorator
return lock.decorate(func)
File "/usr/lib/python2.7/dist-packages/scipy/_lib/_threadsafety.py", line 47, in decorate
return scipy._lib.decorator.decorate(func, caller)
File "/usr/lib/python2.7/dist-packages/scipy/_lib/decorator.py", line 241, in decorate
evaldict, __wrapped__=func)
File "/usr/lib/python2.7/dist-packages/scipy/_lib/decorator.py", line 224, in create
self = cls(func, name, signature, defaults, doc, module)
File "/usr/lib/python2.7/dist-packages/scipy/_lib/decorator.py", line 120, in __init__
formatvalue=lambda val: "", *argspec[:-2])[1:-1])
File "/usr/lib/python2.7/inspect.py", line 871, in formatargspec
return '(' + string.join(specs, ', ') + ')'
AttributeError: 'module' object has no attribute 'join'
</lang>
 
these libraries seem promising, but I can't use them.
 
--[[User:Hailholyghost|Hailholyghost]] ([[User talk:Hailholyghost|talk]]) 15:11, 16 March 2018 (UTC)
:Can you post your own program that attempts to use these libraries? Does it fail when you only import the lib? If not, does the following fail?
 
<pre>
import numpy as np
a = np.array([1,2,3],dtype=float)
np.sum(a)
</pre>
 
[[User:Eoraptor|Eoraptor]] ([[User talk:Eoraptor|talk]]) 17:54, 16 March 2018 (UTC)
 
Hi Eoraptor,
 
I'm trying the same script that you're running, the problem is in scipy.stats I think:
 
<lang python>
import numpy as np
import scipy as sp
import scipy.stats
def welch_ttest(x1, x2):
n1 = x1.size
n2 = x2.size
m1 = np.mean(x1)
m2 = np.mean(x2)
v1 = np.var(x1, ddof=1)
v2 = np.var(x2, ddof=1)
t = (m1 - m2) / np.sqrt(v1 / n1 + v2 / n2)
df = (v1 / n1 + v2 / n2)**2 / (v1**2 / (n1**2 * (n1 - 1)) + v2**2 / (n2**2 * (n2 - 1)))
p = 2 * sp.stats.t.cdf(-abs(t), df)
return t, df, p
welch_ttest(np.array([3.0, 4.0, 1.0, 2.1]), np.array([490.2, 340.0, 433.9]))
(-9.559497721932658, 2.0008523488562844, 0.01075156114978449)</lang>
 
I've installed numpy and scipy, but if I run only the top 3 lines (importing) I get the error as well.--[[User:Hailholyghost|Hailholyghost]] ([[User talk:Hailholyghost|talk]]) 18:18, 16 March 2018 (UTC)
 
Running the short script you mentioned above, with just numpy, produces the following:
 
<lang bash>
con@con-vb:~/Scripts$ python numpy.py
Traceback (most recent call last):
File "numpy.py", line 1, in <module>
import numpy as np
File "/home/con/Scripts/numpy.py", line 2, in <module>
a = np.array([1,2,3],dtype=float)
AttributeError: 'module' object has no attribute 'array'
</lang>
 
:Mmm. It looks like you are giving your programs the same names as the modules you are importing. Bad idea: Python will look first in the current directory, and guess what it will import when you do "import numpy"? [[User:Eoraptor|Eoraptor]] ([[User talk:Eoraptor|talk]]) 21:20, 16 March 2018 (UTC)
 
I've changed the file names, and I'm still getting the same errors :( there are no files in this directory matching num* or sci* --[[User:Hailholyghost|Hailholyghost]] ([[User talk:Hailholyghost|talk]]) 22:03, 16 March 2018 (UTC)
:Any chance a directory in the PYTHONPATH variable contains such files? The errors mean Python does not find the functions in modules 'string' and 'numpy' respectively. The file are found (otherwise you would get for instance ''ModuleNotFoundError: No module named 'string'''), but they do not contain what they should. There is another possibility: in Python 2, the 'string' module has a 'join' function, but not in Python 3. It should never happen, but if for some obscure reason you are running the Python 3 executable with a Python 2 library, it's not surprising you get errors. You could do 'python --version' in the console to see what you are actually running. But usually, this could not happen because Python will automatically look for the correct version of its library (may be possible to fool Python by setting some symlinks, or some other weird trick). You may also ask for help on Stack Overflow, where users of both Linux and Python may have a better answer than me (I work on Windows currently, and have not used Python 2 for years). If you try Stack Overflow, you may help by providing some information on your install, in addition to the error message: which Linux distribution, how you installed Python and numpy... [[User:Eoraptor|Eoraptor]] ([[User talk:Eoraptor|talk]]) 23:27, 16 March 2018 (UTC)
1,336

edits