【问题标题】:Is there a PHP Fleiss' Kappa implementation?是否有 PHP Fleiss 的 Kappa 实现?
【发布时间】:2011-10-20 05:17:51
【问题描述】:

我正在寻找可公开获得的Fleiss' Kappa 的 PHP 实现。到目前为止,我发现了一些用Java, Perl, Ruby and Python 编写的类,但没有用PHP 编写。

您有什么想法或建议吗?

谢谢!

【问题讨论】:

  • 我猜你的时间可能会花在自己写一篇文章上,而不是继续搜索。使用您引用的所有现有实现,应该不会花很长时间。

标签: php statistics classification


【解决方案1】:

因为我也需要,所以写了这个函数:

function fleissKappa($table){

    /*
    *   author Tom Aizenberg
    *   
    *   $table is an n x m array containing the classification counts
    *   
    *   adapted from the example in en.wikipedia.org/wiki/Fleiss'_kappa 
    * 
    */

    $subjects = count($table);
    $classes = count($table[0]);
    $raters = array_sum($table[0]);

    for($q = 1; $q < count($table); $q++){

        if(count($table[$q])!=$classes){

            print("no equal number of classes.");
            exit(0);
        }

        if(array_sum($table[$q])!=$raters){

            print("no equal number of raters.");
            exit(0);
        }

    }

    $pj = array();
    $pi = array();

    for($j = 0; $j < $subjects; $j++){

        $pi[$j] =0;
    }

    for($i = 0; $i < $classes; $i++){

        $tpj = 0;

        for($j = 0; $j < $subjects; $j++){

            $tpj += $table[$j][$i];
            $pi[$j] +=  $table[$j][$i]*$table[$j][$i];

        }

        $pj[$i] = $tpj/($raters*$subjects);

    }

    for($j = 0; $j < $subjects; $j++){
        $pi[$j] = $pi[$j]-$raters;
        $pi[$j] = $pi[$j]*(1/($raters*($raters-1)));
    }

    $pcarret = array_sum($pi)/$subjects;
    $pecarret = 0;

    for($i = 0; $i < count($pj);$i++){

        $pecarret += $pj[$i]*$pj[$i];

    }

    $kappa = ($pcarret-$pecarret)/(1-$pecarret);

    return $kappa;

}

测试一下:

$test = array(
        array(0,0,0,0,14),
        array(0,2,6,4,2),
        array(0,0,3,5,6),
        array(0,3,9,2,0),
        array(2,2,8,1,1),
        array(7,7,0,0,0),
        array(3,2,6,3,0),
        array(2,5,3,2,2),
        array(6,5,2,1,0),
        array(0,2,2,3,7));

print(fleissKappa($test));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-05
    • 2011-01-18
    • 1970-01-01
    • 2012-03-10
    • 2021-10-24
    • 2016-03-16
    • 2017-12-27
    • 1970-01-01
    相关资源
    最近更新 更多