如何解决在Python中通过最大似然获得的最合适参数周围计算稳健的95%置信区间
以下数据表示某些过程X随年龄的变化。我使用最大似然的3参数指数函数拟合这些数据:
#the variables DATA and AGE contain the data and corresponding age,respectively.
def neg_log_likelihood(params,data,age):
alpha,beta,gamma,sigma = params
L = []
for i in range(len(data)):
x = data[i]-(alpha*np.exp(-beta*age[i])+gamma)
L.append(np.log(norm.pdf(x,loc = 0,scale = sigma)))
L = np.array(L)
L = -np.sum(L)
return L
def pred_exp(params,sigma = params
pred = alpha*np.exp(-beta*age)+gamma
return pred
#define bounds for each parameter
alpha= (0,3)
beta= (0,0.8)
gamma= (0,0.8)
sigma= (0,0.5)
bounds = [alpha,sigma]
fit_RTcomp = opt.differential_evolution(neg_log_likelihood,bounds,args = (DATA,AGE))
x = np.arange(0,100)
pred_RTcomp = pred_exp(fit_RTcomp.x,x)
alp = .4
size = 9
plt.figure (1,tight_layout = True)
plt.scatter(data_indiv[:,7],data_indiv[:,0],s = size,color = 'g',label = 'data',alpha = alp)
plt.plot(x,pred_RTcomp,label = 'fit')
plt.ylabel("mean RT")
plt.xlabel("Age (years)")
plt.xlim(np.min(data_indiv[:,7])-1,np.max(data_indiv[:,7])+1)
plt.ylim(0.2,1.3)
plt.legend()
哪个给:
现在,我想围绕指数函数的3个参数分别导出95%CI。推导这些间隔的最佳(最鲁棒)方法是什么?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。