美文网首页
Bland-Altman Plots(一致性评价)在python

Bland-Altman Plots(一致性评价)在python

作者: 北欧森林 | 来源:发表于2021-02-01 16:45 被阅读0次

    假设有reader1 和reader2,分别对一定数量病人的某一影像指标进行评分,现在想看一下这两位研究者评分的一致性,绘制Bland-Altman图是一种较为直观、简单的方式。python代码实现方法如下:

    首先读入数据

    folderPath = "/Users/.../ICC/features4ICC/"
    
    data1 = pd.read_excel(os.path.join(folderPath,"reader1_ap.xlsx"))
    data2 = pd.read_excel(os.path.join(folderPath,"reader2_ap.xlsx"))
    
    data1.insert(0,"reader",np.ones(data1.shape[0]))
    data2.insert(0,"reader",np.ones(data2.shape[0])*2)
    
    data1.insert(0,"target",range(data1.shape[0]))
    data2.insert(0,"target",range(data2.shape[0]))
    
    data = pd.concat([data1,data2])
    print(data)
    
    input_data.png
    Method 1
    import numpy as np
    import pingouin as pg
    
    ax = pg.plot_blandaltman(data1['original_shape_Elongation'], data2['original_shape_Elongation'])
    
    method_1.png
    Method 2
    # pip install pyCompare # for the first time
    import pyCompare
    
    pyCompare.blandAltman(data1['original_shape_Elongation'], data2['original_shape_Elongation'], 
                          percentage=False, 
                          title='Bland-Altman Plot 2',
                          limitOfAgreement=1.96)
    
    method_2.png
    pyCompare.blandAltman(data1['original_shape_Elongation'], data2['original_shape_Elongation'],
                savePath='SavedFigure.tiff',
                figureFormat='tiff')
    
    Method 3
    import matplotlib.pyplot as plt
    import numpy as np
    
    def bland_altman_plot(data1, data2, *args, **kwargs):
        data1     = np.asarray(data1)
        data2     = np.asarray(data2)
        mean      = np.mean([data1, data2], axis=0)
        diff      = data1 - data2                   # Difference between data1 and data2
        md        = np.mean(diff)                   # Mean of the difference
        sd        = np.std(diff, axis=0)            # Standard deviation of the difference
    
        plt.scatter(mean, diff, *args, **kwargs)
        plt.axhline(md,           color='gray', linestyle='-')
        plt.axhline(md + 1.96*sd, color='gray', linestyle='--')
        plt.axhline(md - 1.96*sd, color='gray', linestyle='--')
    
    from numpy.random import random
    
    bland_altman_plot(data1['original_shape_Elongation'], data2['original_shape_Elongation'])
    plt.title('Bland-Altman Plot 3')
    plt.show()
    
    method_3.png

    参考资料:
    Pingouin official documentation
    Why & How to use the Bland-Altman plot for A/B testing | Python + code
    Bland-Altman plot with confidence interval boundary in python

    相关文章

      网友评论

          本文标题:Bland-Altman Plots(一致性评价)在python

          本文链接:https://www.haomeiwen.com/subject/apcftltx.html