首页 文章

假设未知分布,从样本数据计算置信区间

提问于
浏览
2

我有样本数据,我想计算一个置信区间,假设分布不正常且未知 . 基本上,看起来分布是Pareto
Distribution histogram
但我不确定 .

正态分布的答案:

Compute a confidence interval from sample data

Correct way to obtain confidence interval with scipy

3 回答

  • 0

    如果您不知道底层分布,那么我首先想到的是使用bootstrapping:https://en.wikipedia.org/wiki/Bootstrapping_(statistics)

    在伪代码中,假设 x 是包含数据的numpy数组:

    import numpy as np
    N = 10000
    mean_estimates = []
    for _ in range(N):
        re_sample_idx = np.random.randint(0, len(x), x.shape)
        mean_estimates.append(np.mean(x[re_sample_idx]))
    

    mean_estimates 现在是10000个分布均值估计的列表 . 取这10000个值的2.5和97.5百分位数,你有一个围绕数据均值的置信区间:

    sorted_estimates = np.sort(np.array(mean_estimates))
    conf_interval = [sorted_estimates[int(0.025 * N)], sorted_estimates[int(0.975 * N)]]
    
  • 3

    从对另一个答案的讨论中,我假设你想要一个人口均值的置信区间,是吗? (对于某些数量,您必须有一个置信区间,而不是分布本身 . )

    对于具有有限矩的所有分布,均值的采样分布渐近趋于正态分布,均值等于总体均值,方差等于总体方差除以n . 因此,如果你有大量的数据,$ \ mu \ pm \ Phi ^ { - 1}(p)\ sigma / \ sqrt $应该是人口均值的p-置信区间的一个很好的近似值,甚至如果分配不正常 .

  • 0

    当前的解决方案不起作用,因为randint似乎已被弃用

    np.random.seed(10)
    point_estimates = []         # Make empty list to hold point estimates
    
    for x in range(200):         # Generate 200 samples
        sample = np.random.choice(a= x, size=x.shape)
        point_estimates.append( sample.mean() )
    sorted_estimates = np.sort(np.array(point_estimates))
    conf_interval = [sorted_estimates[int(0.025 * N)], sorted_estimates[int(0.975 * N)]]
    print(conf_interval, conf_interval[1] - conf_interval[0])
    pd.DataFrame(point_estimates).plot(kind="density", legend= False)
    

相关问题