【发布时间】:2018-09-06 12:11:06
【问题描述】:
我想使用自举技术(100 次重采样)计算线性回归系数的标准误差,但我得到的结果为零,这是不正常的。我认为代码的引导部分有问题。你知道如何修复我的代码吗?
x, y = np.genfromtxt("input.txt", unpack=True)
#regression part
slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
print std_err
#bootstrap part of the code
A = np.random.choice(x, size=100, replace=True)
B = np.random.choice(y, size=100, replace=True)
slope2, intercept2, r_value2, p_value2, std_err2 = stats.linregress(A,B)
print std_err2
input.txt:
-1.08 -1.07
-2.62 -2.56
-2.84 -2.79
-2.22 -2.16
-3.47 -3.55
-2.81 -2.79
-2.86 -2.71
-3.41 -3.42
-4.18 -4.21
-3.50 -3.48
-5.67 -5.55
-6.83 -6.95
-6.13 -6.13
-8.34 -8.19
-7.82 -7.83
-9.86 -9.58
-8.67 -8.62
-9.81 -9.81
-8.39 -8.30
【问题讨论】:
-
您从哪个库获得
stats?请包含您的库导入,以便其他人可以轻松运行您的代码。 -
我正在删除 matplotlib 标签。这与它无关
-
当我运行你的代码时(假设
stats来自scipy)我得到 std_err 的 0.007415 和 std_err2 的 0.099598?两者都不是零。 -
我收到了
0.00741473410217和0.105542871364。 scipy版'0.19.1'
标签: python python-2.7 statistics-bootstrap