小编osm*_*mak的帖子

如何从curve_fit获得置信区间

我的问题涉及统计和python,我是两者的初学者.我正在运行模拟,并且对于自变量(X)的每个值,我为因变量(Y)生成1000个值.我所做的是,我计算了X的每个值的平均Y,并使用scipy.optimize.curve_fit拟合这些平均值.曲线非常适合,但我想绘制置信区间.我不确定我所做的是否正确或者我想做什么都可以完成,但我的问题是如何从curve_fit产生的协方差矩阵中获得置信区间.代码首先从文件中读取平均值然后只使用curve_fit.

import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit


def readTDvsTx(L, B, P, fileformat):
    # L should be '_Fixed_' or '_'
    TD = []
    infile = open(fileformat.format(L, B, P), 'r')
    infile.readline()  # To remove header
    for line in infile:
        l = line.split()  # each line contains TxR followed by CD followed by TD
        if eval(l[0]) >= 70 and eval(l[0]) <=190:
            td = eval(l[2])
            TD.append(td)
    infile.close()
    tdArray = np.array(TD)

    return tdArray


def rec(x, a, b):
    return a …
Run Code Online (Sandbox Code Playgroud)

python statistics curve-fitting scipy python-3.x

9
推荐指数
1
解决办法
4430
查看次数

标签 统计

curve-fitting ×1

python ×1

python-3.x ×1

scipy ×1

statistics ×1