| 1 | package Statistics::Kappa::Fleiss; | ||
| 2 | 2 | ▶ | use 5.026; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | |||
| 4 | 2 | our $VERSION = '0.03'; | |
| 5 | |||
| 6 | 2 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 2 | ▶ | use experimental qw{ signatures }; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 2 | ▶ | use List::Util qw{ sum }; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 2 | ▶ | use namespace::clean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | 2 | has data => (is => 'ro', required => 1); | |
| 13 | 2 | has kappa => (is => 'lazy', init_arg => undef); | |
| 14 | 2 | has proportion => (is => 'lazy', init_arg => undef); | |
| 15 | 2 | has extent => (is => 'lazy', init_arg => undef); | |
| 16 | 2 | has category_count => (is => 'lazy', init_arg => undef); | |
| 17 | 2 | has mean => (is => 'lazy', init_arg => undef); | |
| 18 | 2 | has pe => (is => 'lazy', init_arg => undef); | |
| 19 | |||
| 20 | |||
| 21 | 1 | ▶ | sub _build_category_count($self) { |
|
Subroutine
_build_category_count: called CC=1 SCAR=0.0
| |||
| 22 | 1 | sum(@{ $self->data->[0] }) | |
| 23 | } | ||
| 24 | |||
| 25 | 1 | ▶ | sub _build_proportion($self) { |
|
Subroutine
_build_proportion: called CC=2 SCAR=6.9
| |||
| 26 | 1 | my %p; | |
| 27 | 1 | for my $j (0 .. $#{ $self->data->[0] }) { | |
| 28 | 5 | $p{$j} = sum(map $self->data->[$_][$j], 0 .. $#{ $self->data }) | |
| 29 | 5 | / (@{ $self->data } * $self->category_count); | |
| 30 | } | ||
| 31 | 1 | return \%p | |
| 32 | } | ||
| 33 | |||
| 34 | 1 | ▶ | sub _build_extent($self) { |
|
Subroutine
_build_extent: called CC=2 SCAR=6.9
| |||
| 35 | 1 | my %p; | |
| 36 | 10 | $p{$_} = (sum(map $_ ** 2, @{ $self->data->[$_] }) - $self->category_count) | |
| 37 | / $self->category_count / ($self->category_count - 1) | ||
| 38 | 1 | for 0 .. $#{ $self->data }; | |
| 39 | 1 | return \%p | |
| 40 | } | ||
| 41 | |||
| 42 | 1 | ▶ | sub _build_mean($self) { |
|
Subroutine
_build_mean: called CC=1 SCAR=0.0
| |||
| 43 | 1 | sum(values %{ $self->extent }) / @{ $self->data } | |
| 44 | } | ||
| 45 | |||
| 46 | 1 | ▶ | sub _build_pe($self) { |
|
Subroutine
_build_pe: called CC=1 SCAR=0.0
| |||
| 47 | 1 | sum(map $_ ** 2, values %{ $self->proportion }) | |
| 48 | } | ||
| 49 | |||
| 50 | 1 | ▶ | sub _build_kappa($self) { |
|
Subroutine
_build_kappa: called CC=1 SCAR=0.0
| |||
| 51 | 1 | ($self->mean - $self->pe) / (1 - $self->pe) | |
| 52 | } | ||
| 53 | |||
| 54 | |||
| 55 | |||
| 56 | |||
| 57 | =head1 NAME | ||
| 58 | |||
| 59 | Statistics::Kappa::Fleiss - Calculate inter-annotator agreement. | ||
| 60 | |||
| 61 | =head1 VERSION | ||
| 62 | |||
| 63 | Version 0.03 | ||
| 64 | |||
| 65 | =head1 SYNOPSIS | ||
| 66 | |||
| 67 | use Statistics::Kappa::Fleiss; | ||
| 68 | |||
| 69 | my @data = ([0, 0, 0, 0, 14], | ||
| 70 | [0, 2, 6, 4, 2], | ||
| 71 | [0, 0, 3, 5, 6]); | ||
| 72 | my $fk = 'Statistics::Kappa::Fleiss'->new(data => \@data); | ||
| 73 | my $kappa = $fk->kappa; | ||
| 74 | |||
| 75 | =head1 METHODS | ||
| 76 | |||
| 77 | =head2 'Statistics::Kappa::Fleiss'->new(data => \@data) | ||
| 78 | |||
| 79 | The constructor. It takes a named argument C<data> which should contain an | ||
| 80 | array reference. Each element of the array represents a rated item by another | ||
| 81 | anonymous array, which on position C<j> contains the number of raters that | ||
| 82 | assigned the category C<j> to the item. Therefore, the format of the data is | ||
| 83 | I<different> to other L<Statistics::Kappa> modules. | ||
| 84 | |||
| 85 | =head2 data | ||
| 86 | |||
| 87 | =head1 AUTHOR | ||
| 88 | |||
| 89 | E. Choroba <choroba@matfyz.cz> | ||
| 90 | |||
| 91 | =head1 BUGS | ||
| 92 | |||
| 93 | Please report any bugs or feature requests to the L<GitHub | ||
| 94 | repository|https://github.com/choroba/statistics-kappa>. | ||
| 95 | |||
| 96 | =head1 SUPPORT | ||
| 97 | |||
| 98 | You can find documentation for this module with the perldoc command. | ||
| 99 | |||
| 100 | perldoc Statistics::Kappa::Fleiss | ||
| 101 | |||
| 102 | You can also look for information at: | ||
| 103 | |||
| 104 | =over 4 | ||
| 105 | |||
| 106 | =item * GitHub issue tracker (report bugs here) | ||
| 107 | |||
| 108 | L<https://github.com/choroba/Statistics-Kappa/issues> | ||
| 109 | |||
| 110 | =item * Search CPAN | ||
| 111 | |||
| 112 | L<https://metacpan.org/release/Statistics-Kappa> | ||
| 113 | |||
| 114 | =back | ||
| 115 | |||
| 116 | =head1 SEE ALSO | ||
| 117 | |||
| 118 | Other modules from L<Statistics::Kappa>: L<Statistics::Kappa::Cohen> and | ||
| 119 | L<Statistics::Kappa::Weighted>. Another inter-rater agreement statistics: | ||
| 120 | L<Statistics::Krippendorff>. | ||
| 121 | |||
| 122 | =head1 LICENSE AND COPYRIGHT | ||
| 123 | |||
| 124 | This software is Copyright (c) 2026 by E. Choroba <choroba@matfyz.cz>. | ||
| 125 | |||
| 126 | This is free software, licensed under: | ||
| 127 | |||
| 128 | The Artistic License 2.0 (GPL Compatible) | ||
| 129 | |||
| 130 | =cut | ||
| 131 | |||
| 132 | 2 | __PACKAGE__ | |