我目前正在尝试使用引导方法对某些参数实施置信区间。但是,我有一个小问题。即使我使用 3000 个样本,我的置信区间也有很大差异。
情况如下:
我有一个大约 300 个点的数据集,以传统方式 y=f(x) 定义。我知道适合数据的模型。所以我用curve_fit找到参数,并尝试为每个参数建立置信区间。我试图混合这里描述的方法:
和这里:
http://www.variousconsequences.com/2010/02/visualizing-confidence-intervals.html
这是我使用的代码:
def model(t, Vs, Vi, k):
"""
Fitting model, following a Burst kinetics.
t is the time
Vs is the steady velocity
Vi is the initial velocity
k is the Burst rate constant
"""
y = Vs * t - ((Vs - Vi) * (1 - np.exp(-k * t)) / k)
return y
[some code]
bootindex = np.random.random_integers
nboot = 3000
local_t = np.array(local_t)
local_fluo = np.array(local_fluo)
concentration = np.array(concentration)
#Initializing time values in hours
local_scaled_t = [ index /3600 for index in local_t ]
local_scaled_t = np.array(local_scaled_t)
conc_produit = [ concentration[0] - value_conc for value_conc in concentration ]
conc_produit = np.array(conc_produit)
popt, pcov = curve_fit(model, local_scaled_t, conc_produit, maxfev=3000)
popt = [ popt[0] / 3600, popt[1] / 3600 , popt[2] / 3600 ]
ymod = list()
for each in local_t:
ymod.append(model(each, popt[0], popt[1], popt[2]))
ymod = np.array(ymod)
r = conc_produit - ymod
list_para = list()
# loop over n bootstrap samples from the resids
for i in range(nboot):
pc, pout = curve_fit(model, local_scaled_t, ymod + r[bootindex(0, len(r)-1, len(r))], maxfev=3000)
pc = [ pc[0] / 3600, pc[1] / 3600 , pc[2] / 3600 ]
list_para.append(pc)
ymod = list()
for each in local_t:
ymod.append(model(each, pc[0], pc[1], pc[2]))
ymod = np.array(ymod)
list_para = np.array(list_para)
mean_params = np.mean(list_para,0)
std_params = np.std(list_para,0)
print(popt)
for true_para, para, std in zip(popt, mean_params, std_params):
print("{0} between {1} and {2}".format(round(true_para, 6), round(para - std * 1.95996, 6), round(para + std * 1.95996, 6)))
print("{0} between {1} and {2}".format(round(true_para, 6), round(para - std * 1.95996, 6), round(para + std * 1.95996, 6)))
这里没有什么复杂的,只需注意我重新调整了时间以规范化我的数据并拥有更好的参数。
最后,对于相同的代码,这里有 2 个输出:
[1.9023455671995163e-05, 0.01275941716148471, 0.026540319119773129]
1.9e-05 between 1.6e-05 and 2.1e-05
0.012759 between -0.042697 and 0.092152
0.02654 between -0.073456 and 0.159983
[1.9023455671995163e-05, 0.01275941716148471, 0.026540319119773129]
1.9e-05 between 1.5e-05 and 2.9e-05
0.012759 between -0.116499 and 0.17112
0.02654 between -0.186011 and 0.27797
如您所见,差异非常大。这是预期的还是我做错了什么?例如,我真的不明白为什么我必须将标准差乘以 1.95996。