t检验与点二列相关的异同

t检验、点二列相关
两者侧重点不同,前者重在检验两列数据的均值差异,即宏观上是否来自同一总体,后者关注两列数据的相关程度。
相同点在都是一个二分数据将一列等距或等比数据分类,且两者数值可以通过公式相互转换。

转换的Python代码如下:

import math
import numpy as np


# s1 = [10, 9, 8, 8, 8, 7]
# s2 = [5, 5, 4, 4]

# s1 = [67, 73, 74, 70, 70, 75, 73, 68, 69]
# s2 = [69, 63, 67, 64, 61, 66, 60, 63, 63]

s1 = [84, 84, 88, 90, 78, 92, 94, 96, 88, 90]
s2 = [82, 76, 60, 72, 74, 76, 80, 78, 76, 74]

xbar1 = np.mean(s1)
xbar2 = np.mean(s2)


# Calculate sum of squares(和方)
def calc_ss(s):
  return sum(map(lambda x: x * x, s)) - sum(s) ** 2 / len(s)


ss1 = calc_ss(s1)
ss2 = calc_ss(s2)

xsquare1 = ss1 / (len(s1) - 1)
xsquare2 = ss2 / (len(s2) - 1)

print('Xbar1:', xbar1)
print('Xbar2:', xbar2)

print('SS1:', ss1)
print('SS2:', ss2)

print('Xsquare1:', xsquare1)
print('Xsquare2:', xsquare2)

spsquare = (ss1 + ss2) / (len(s1) + len(s2) - 2)
# 总体方差
print('SPsquare', spsquare)

se = np.sqrt( spsquare / len(s1) + spsquare / len(s2) )

print('SE:', se)


tobs = (xbar1 - xbar2) / se

print('t_obs:', tobs)

print('---------------------')

s3 = s1 + s2

sx = np.sqrt( calc_ss(s3) / len(s3) )

print('sx:', sx)

rpb = ((xbar1 - xbar2) / sx) * np.sqrt( (len(s1) / len(s3)) * (len(s2) / len(s3)) )

print('r_pb:', rpb)
print('t_obs:', tobs)
print('Fmax:', max(xsquare1, xsquare2) / min(xsquare1, xsquare2))

print(rpb ** 2, 'is r_pb^2')
print(tobs ** 2 / (tobs ** 2 + len(s1) + len(s2) - 2), 'is t^2 / (t^2 + df)')

Output:

Xbar1: 88.4
Xbar2: 74.8
SS1: 254.39999999999418
SS2: 321.59999999999854
Xsquare1: 28.26666666666602
Xsquare2: 35.73333333333317
SPsquare 31.999999999999595
SE: 2.5298221281346875
t_obs: 5.375872022286282
---------------------
sx: 8.662563131083052
r_pb: 0.7849870641173408
t_obs: 5.375872022286282
Fmax: 1.2641509433962497
0.616204690831562 is r_pb^2
0.6162046908315598 is t^2 / (t^2 + df)

走火入魔四

通过一定方式制造出了人造生命体,并将一个天然生命体的记忆信息转存到这个新意义上的人造生命体,他们有着完全一样的思考方式、此时此刻同样的感受。这两个生命体是同一个生命吗?

- Read More -

走火入魔三

生命体与非生命体之间没有不可跨越的界限。
可以通过人工方式编码到脑中来生成生命体的记忆,信息也可以储存在人造的有机储存器中。

- Read More -

走火入魔二

生命体能够进行复杂的动作,产生复杂的想法,是由于体内复杂的有机器官。众所周知,生命体的遗传物质有DNA,部分病毒主要依靠RNA传递遗传信息,体内功能的发生依靠种类繁多、结构复杂的蛋白质。

生物学或者化学上有许多人工方法快速复制DNA、RNA,也有许多方法产生蛋白质。

- Read More -

Error installing mysql-python/mysqlclient: library not found for -lssl

macOS Mojave 安装mysqlclient时提示没有ssl库,错误如下:

Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
    Complete output from command /Users/moon/Workspace/Pycharm/env-tonghang/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/6z/3d8pkqg53r72hd3gvt71n0900000gn/T/pip-install-dk68k229/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/6z/3d8pkqg53r72hd3gvt71n0900000gn/T/pip-record-4eo9tbll/install-record.txt --single-version-externally-managed --compile --install-headers /Users/moon/Workspace/Pycharm/env-tonghang/include/site/python3.6/mysqlclient:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.13-x86_64-3.6
    copying _mysql_exceptions.py -> build/lib.macosx-10.13-x86_64-3.6
    creating build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/compat.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    creating build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.macosx-10.13-x86_64-3.6
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 -I/usr/local/opt/mysql@5.7/include/mysql -I/Users/moon/Workspace/Pycharm/env-tonghang/include -I/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c _mysql.c -o build/temp.macosx-10.13-x86_64-3.6/_mysql.o
    clang -bundle -undefined dynamic_lookup build/temp.macosx-10.13-x86_64-3.6/_mysql.o -L/usr/local/opt/mysql@5.7/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.13-x86_64-3.6/_mysql.cpython-36m-darwin.so
    ld: library not found for -lssl
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command 'clang' failed with exit status 1
    
    ----------------------------------------
Command "/Users/moon/Workspace/Pycharm/env-tonghang/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/6z/3d8pkqg53r72hd3gvt71n0900000gn/T/pip-install-dk68k229/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/6z/3d8pkqg53r72hd3gvt71n0900000gn/T/pip-record-4eo9tbll/install-record.txt --single-version-externally-managed --compile --install-headers /Users/moon/Workspace/Pycharm/env-tonghang/include/site/python3.6/mysqlclient" failed with error code 1 in /private/var/folders/6z/3d8pkqg53r72hd3gvt71n0900000gn/T/pip-install-dk68k229/mysqlclient/

Screen Shot 2019-06-19 at 14.06.27.png

解决方法可以指定ssl库

LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient

或在~/.bash_*中指定环境

export LDFLAGS="-L/usr/local/opt/openssl/lib"

To StackoverflowError installing mysql-python: library not found for -lssl