-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathf1score.m
67 lines (58 loc) · 2.28 KB
/
f1score.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function [F1,hitrate,errorrate] = f1score(x,rtmin,rtmax,nresp,ntarget)
%f1score F1 score of a test's detection accuracy.
% F1 = F1SCORE(X,RTMIN,RTMAX,NRESP,NSTIM) returns the F1 score of a
% test's detection accuracy using the RTs contained in X. RTs below RTMIN
% are considered false alarms and RTs above RTMAX are considered misses.
% The total number of responses NRESP should include all false alarms and
% double-presses. Misses, whereby no response was registered, can be
% included in X as missing values (NaNs). The F1 score is computed as the
% harmonic mean of precision and recall (Van Rijsbergen, 1979).
%
% [...,HITRATE] = F1SCORE(...) returns the hit rate based on the ratio of
% hits to targets without consideration of false alarms.
%
% [...,ERRORRATE] = F1SCORE(...) returns the error rate based on the
% ratio of false alarms to targets.
%
% [...] = F1SCORE(...,NTARGET) computes the F1 score by specifying the
% exact number of targets NTARGET. This is useful if NTARGET does not
% equal the number of elements in X because misses were not included in
% X as NaNs, or if RTs were removed due to outlier correction procedures.
%
% See also ORCAPACITY, ANDCAPACITY, TPERMTEST, EFFECTSIZE.
%
% RaceModel https://github.com/mickcrosse/RaceModel
% References:
% [1] Crosse MJ, Foxe JJ, Molholm S (2019) RaceModel: A MATLAB
% Package for Stochastic Modelling of Multisensory Reaction
% Times (In prep).
% [2] Van Rijsbergen CJ (1979) Information Retrieval: Butterworth-
% Heinemann.
% Author: Mick Crosse
% Email: [email protected]
% Cognitive Neurophysiology Laboratory,
% Albert Einstein College of Medicine, NY
% Apr 2017; Last Revision: 4-Apr-2019
% Set default values
if nargin < 5 || isempty(ntarget)
ntarget = length(x);
end
% Find number of hits and misses
noRT = isnan(x) | x>rtmax;
misses = sum(noRT)+ntarget-length(x);
hits = ntarget-misses;
% Compute number of false alarms
falarms = sum(nresp)-hits+sum(x<rtmin);
% Compute precision and recall
precis = hits./(hits+falarms);
recall = hits./(hits+misses);
% Compute F1 score
F1 = 2*(precis.*recall)./(precis+recall);
% Compute hit rate
if nargout > 1
hitrate = hits/ntarget;
end
% Compute error rate
if nargout > 2
errorrate = falarms/ntarget;
end