Python 当很少有变量只有下限时,如何对一组变量执行卡方检验?如何在这组数据和其他数据之间拟合最小平方?
我有一组变量。它们中的一些具有不对称误差条,而很少有仅具有下限,例如Python 当很少有变量只有下限时,如何对一组变量执行卡方检验?如何在这组数据和其他数据之间拟合最小平方?,python,Python,我有一组变量。它们中的一些具有不对称误差条,而很少有仅具有下限,例如 26(-5,+7) 33(-7,+10) 46(-11,+40) 400(-323,无穷大)[下限=77] 98(-52,无穷大)[下限=46] 148(-92,无穷大)[下限=56] 64(-20,+84) 我想对数据集进行卡方检验,期望值=变量的加权平均值。我为它编写了以下python代码 **import matplotlib import math temps = [26,33,46,400,98,1
- 26(-5,+7)
- 33(-7,+10)
- 46(-11,+40)
- 400(-323,无穷大)[下限=77]
- 98(-52,无穷大)[下限=46]
- 148(-92,无穷大)[下限=56]
- 64(-20,+84)
**import matplotlib
import math
temps = [26,33,46,400,98,148,64]
sigmas = [5,7,11,323,52,92,20]
dof = 7
sigmasquares = [sigma ** 2 for sigma in sigmas]
print(sigmasquares)
arcsigmas = [1/sigmasquare for sigmasquare in sigmasquares]
print(arcsigmas)
res = [i / j for i,j in zip(temps,sigmasquares )]
print("res is: " + str(res))
sumarcsigmas = sum(arcsigmas)
print(sumarcsigmas)
sumdems = sum(res)
print(sumdems)
A = sumdems/sumarcsigmas
print('weighted mean: %.3f' % A)
B = []
for temp in temps:
B.append((temp - A)**2)
print(B)
C = [k / j for k,j in zip(B,sigmasquares )]
print("C is: " + str(C))
chisquare = sum(C)
print(chisquare)
chidof = chisquare/dof
print('chisquare/dof: %.4f' % chidof)**
但我不确定这样对待下限是否合适。你能帮我找到问题吗?另外,如果我想用另一组变量(没有误差和上限)拟合这组变量之间的最小二乘线,并找到皮尔逊系数,那么怎么做呢