Kappa/Cohen.pm

filter: Statementstmt 100% 46 / 46 Branchbran n/a Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 12 / 12 Podpod 100% 1 / 1 totaltotal 96.9% 63 / 65 CC 4 SCAR 3.4
CC
4
Cov
98%
_build_observed_agreement
2.0
_build_confusion
2.0
_build_expected_agreement
2.0
CRAP 1.4
« Kappa/Weighted.pm ↑ Summary Kappa/Fleiss.pm »
1 package Statistics::Kappa::Cohen;
2 3 ▶use 5.026;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 3 our $VERSION = '0.03';
5  
6 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use experimental qw{ signatures };
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use List::Util qw{ sum };
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 has data => (is => 'ro', required => 1);
13 3 has kappa => (is => 'lazy', init_arg => undef);
14 3 has confusion => (is => 'lazy', init_arg => undef);
15 3 has expected_agreement => (is => 'lazy', init_arg => undef);
16 3 has observed_agreement => (is => 'lazy', init_arg => undef);
17 3 has standard_error => (is => 'lazy', init_arg => undef);
18 3 has _categories => (is => 'lazy', init_arg => undef);
19  
20 2 ▶sub confidence_interval($self, $level) {
Subroutine confidence_interval: called CC=1 SCAR=0.0
Pod documented
21 2 [$self->kappa - (1 + $level) * $self->standard_error,
22 $self->kappa + (1 + $level) * $self->standard_error]
23 }
24  
25 7 ▶sub _build__categories($self) {
Subroutine _build__categories: called CC=1 SCAR=0.0
26 7 my %c;
27 7 @c{ map @$_, @{ $self->data } } = ();
28 7 return [sort keys %c]
29 }
30  
31 2 ▶sub _build_standard_error($self) {
Subroutine _build_standard_error: called CC=1 SCAR=0.0
32 sqrt($self->observed_agreement * (1 - $self->observed_agreement)
33 2 / @{ $self->data } / (1 - $self->expected_agreement) ** 2)
34 }
35  
36 7 ▶sub _build_kappa($self) {
Subroutine _build_kappa: called CC=1 SCAR=0.0
37 7 return ($self->observed_agreement - $self->expected_agreement)
38 / (1 - $self->expected_agreement)
39 }
40  
41 7 ▶sub _build_confusion($self) {
Subroutine _build_confusion: called CC=2 SCAR=6.9
42 7 my %c;
43 7 for my $pair (@{ $self->data }) {
44 708 ++$c{ $pair->[0] }{ $pair->[1] }
45 }
46 7 return \%c
47 }
48  
49 7 ▶sub _build_observed_agreement($self) {
Subroutine _build_observed_agreement: called CC=2 SCAR=7.1
50 7 return sum(map $self->confusion->{$_}{$_} // 0, keys %{ $self->confusion })
51 7 ▶ / @{ $self->data }
Condition50%1/2
$self->confusion->{$_}{$_} // 0
l!l
160
MC/DC0%0/1
$self->confusion->{$_}{$_} // 0
$self->confusion->{$_}{$_}
Truth table50%1/2
A
A= $self->confusion->{$_}{$_}
Aresult
11
00
52 }
53  
54 7 ▶sub _build_expected_agreement($self) {
Subroutine _build_expected_agreement: called CC=2 SCAR=6.9
55 16 return sum(map { my $c = $_;
56 16 ▶ sum(values %{ $self->confusion->{$c} })
Condition100%2/2
$self->confusion->{$_}{$c} // 0
l!l
353
MC/DC100%1/1
$self->confusion->{$_}{$c} // 0
$self->confusion->{$_}{$c}
Truth table100%2/2
A
A= $self->confusion->{$_}{$c}
Aresult
11
00
57 * sum(map $self->confusion->{$_}{$c} // 0,
58 16 @{ $self->_categories })
59 7 } @{ $self->_categories }
60 7 ) / @{ $self->data } ** 2
61 }
62  
63 =head1 NAME
64  
65 Statistics::Kappa::Cohen - Calculate inter-annotator agreement.
66  
67 =head1 VERSION
68  
69 Version 0.03
70  
71 =head1 SYNOPSIS
72  
73 use Statistics::Kappa::Cohen;
74  
75 my @data = ([1, 1], [1, 0], [1, 0], [0, 0], [1, 1], [0, 1]);
76 my $ck = 'Statistics::Kappa::Cohen'->new(data => \@data);
77 my $kappa = $ck->kappa;
78  
79 =head1 METHODS
80  
81 =head2 'Statistics::Kappa::Cohen'->new(data => \@data)
82  
83 The constructor. It takes a named argument C<data> which should contain an
84 array reference. The elements of the array should be anonymous arrays of two
85 elements, representing answers by the two raters we are comparing.
86  
87 =head2 $self->confidence_interval($p)
88  
89 Return the confidence interval as an anonymous array with two elements. The
90 argument is the required percentage, typically 0.95 or 0.99.
91  
92 =head2 data
93  
94 =head1 AUTHOR
95  
96 E. Choroba <choroba@matfyz.cz>
97  
98 =head1 BUGS
99  
100 Please report any bugs or feature requests to the L<GitHub
101 repository|https://github.com/choroba/statistics-kappa>.
102  
103 =head1 SUPPORT
104  
105 You can find documentation for this module with the perldoc command.
106  
107 perldoc Statistics::Kappa::Cohen
108  
109  
110 You can also look for information at:
111  
112 =over 4
113  
114 =item * GitHub issue tracker (report bugs here)
115  
116 L<https://github.com/choroba/Statistics-Kappa/issues>
117  
118 =item * Search CPAN
119  
120 L<https://metacpan.org/release/Statistics-Kappa>
121  
122 =back
123  
124 =head1 SEE ALSO
125  
126 Other modules from L<Statistics::Kappa>: L<Statistics::Kappa::Fleiss> and
127 L<Statistics::Kappa::Weighted>. Another inter-rater agreement statistics:
128 L<Statistics::Krippendorff>.
129  
130 =head1 LICENSE AND COPYRIGHT
131  
132 This software is Copyright (c) 2026 by E. Choroba <choroba@matfyz.cz>.
133  
134 This is free software, licensed under:
135  
136 The Artistic License 2.0 (GPL Compatible)
137  
138  
139 =cut
140  
141 3 __PACKAGE__
« Kappa/Weighted.pm ↑ Summary Kappa/Fleiss.pm »