-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmWEIGHTING.m
61 lines (59 loc) · 2.01 KB
/
mWEIGHTING.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
function [WEIGHTS] = mWEIGHTING(CATEGORIES, TYPE)
% Calculate a matrix of weights to be used while calculating agreement
%
% CATEGORIES is a numeric vector specifying the possible categories.
%
% TYPE is a parameter specifying the weighting scheme to be used for
% partial agreement. The three options are below:
% 'identity' is for unordered/nominal categories
% 'linear' is for ordered categories and is relatively strict
% 'quadratic' is for ordered categories and is relatively forgiving
%
% WEIGHTS is a q-by-q numeric matrix where q is the number of elements in
% the CATEGORIES vector. Each value in this matrix specifies the amount
% of "partial credit" that should be awarded for one rater assigning an
% object to category k and another rater assigning that object to
% category l, where k and l index rows and columns of WEIGHTS.
%
% Example usage: mWEIGHTING(1:5, 'linear')
%
% (c) Jeffrey M Girard, 2016-2021
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Calculate weights based on data scale
q = length(CATEGORIES);
if isnumeric(CATEGORIES)
cat = double(CATEGORIES);
else
cat = 1:q;
end
WEIGHTS = nan(q);
catmin = min(cat);
catmax = max(cat);
for k = 1:q
for l = 1:q
switch TYPE
case 'identity'
WEIGHTS = eye(q);
case 'linear'
if k==l
WEIGHTS(k,l) = 1;
else
dist = abs(cat(k) - cat(l));
maxdist = catmax - catmin;
WEIGHTS(k,l) = 1 - (dist / maxdist);
end
case 'quadratic'
if k==l
WEIGHTS(k,l) = 1;
else
distsq = (cat(k) - cat(l)) ^ 2;
maxdistsq = (catmax - catmin) ^ 2;
WEIGHTS(k,l) = 1 - (distsq / maxdistsq);
end
otherwise
error('Weighting must be identity, linear, or quadratic.');
end
end
end
end