Concordance index loop optimization

2 views (last 30 days)
Andre
Andre on 6 Jun 2014
Answered: Julio Chirinos on 14 Aug 2018
Hello, I'm implementing de concordance index measure (<http://biomet.oxfordjournals.org/content/92/4/965.abstract>) to compare a regression model with tru labels, and I attempted to do a loop based implementation that is currently very slow (see below). Does anybody know a good implementation of this measure, or how to optimize this code?
Thanks in advance
CODE:
function [ci] = acan_concordance_index(targets, predicts)
[~,i] = sort(targets,'descend');
predicts = predicts(i);
n = length(targets);
total = 0;
norm_z = 0;
for j=1:n
for k=j:n
if j ~= k
h = step_function(predicts(j) - predicts(k));
total = total + h;
norm_z = norm_z + 1;
end
end
end
ci = total / norm_z;
end
function h = step_function(diff)
if diff > 0
h = 1;
elseif diff == 0
h = 0.5;
else
h = 0;
end
end
  2 Comments
Geoff Hayes
Geoff Hayes on 6 Jun 2014
In the above code, the outer for loop is iterating over j and the inner for loop is iterating over k. Yet h is being calculated as
h = step_function(predicts(i) - predicts(j));
Do you mean to be using i which is a vector returned from the sort function?
Andre
Andre on 7 Jun 2014
Yes Geoff, I misstyped it, and already edited. I also changed the inner loop to begin with j, as the list is already ordered. I found a nice definition of the c-index here: https://stat.ethz.ch/pipermail/r-help/2008-December/182565.html The code seems to match mine, but it is also non optimized.
Thanks for the reply.

Sign in to comment.

Answers (1)

Julio Chirinos
Julio Chirinos on 14 Aug 2018
does anybody have a function to compute the Harrel c index in Matlab? I have reached out to the Mathworks to no avail. Any help would be greatly appreciated. Alternatively, in the function above, what is targets and predicts? how do I go from the output of coxphfit to these 2 arguments in order to use the function? Thank you!

Categories

Find more on Problem-Based Optimization Setup in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!