-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathbias_skill.m
More file actions
46 lines (42 loc) · 1.34 KB
/
bias_skill.m
File metadata and controls
46 lines (42 loc) · 1.34 KB
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
function b = bias_skill(predicted,reference)
%BIAS Calculate the bias between two variables (B)
%
% B = BIAS_SKILL(PREDICTED,REFERENCE) calculates the bias between two variables
% PREDICTED and REFERENCE. The bias is calculated using the
% formula:
%
% B = mean(p) - mean(r)
%
% where p is the predicted values, and r is the reference values. Note
% that p & r must have the same number of values.
%
% Input:
% PREDICTED : predicted field
% REFERENCE : reference field
%
% Output:
% B : bias between predicted and reference
% Validate input args
narginchk(2,2);
% Check that dimensions of predicted and reference fields match
pdims= size(predicted);
rdims= size(reference);
if length(pdims) ~= length(rdims)
error(['Number of predicted and reference field dimensions do not' ...
' match.\n' ...
'length(predicted)= ' num2str(length(size(predicted))) ...
', length(reference)= ' num2str(length(size(reference))) ...
],class(pdims));
end
for i=1:length(pdims)
if pdims(i) ~= rdims(i)
error(['Predicted and reference field dimensions do not' ...
' match.\n' ...
'size(predicted)= ' num2str(size(predicted)) ...
', size(reference)= ' num2str(size(reference)) ...
],class(pdims));
end
end
% Calculate means
b = mean(predicted) - mean(reference);
end