IBM Support

Can SPSS Statistics produce Harrell's C or Somers' D following a Cox regression?

Troubleshooting


Problem

I'm fitting a Cox regression model and want to compute Harrell's C statistic or Somers' D. Can SPSS Statistics produce either of these?

Resolving The Problem

SPSS Statistics does not have a procedure designed to produce either Harrell's C or Somers' D following a Cox regression model, but the following commands contain a macro that will compute both.

The following commands compute Harrell's C statistic and Somers' d following fitting of a Cox regression model. They are not optimized for efficiency, but should produce accurate results. Save the XBETA values from COXREG, type in the appropriate variable names in the call to the hc macro at the bottom of this file, then run all commands. This macro assumes that the status variable is coded such that the value 1 indicates occurrence of an event. If there are more than 10001 cases in the data file, an additional subcommand will be needed in the call in order to specify a larger maximum on the allowable number of loops to be executed. Add "/n=" to the call, without the quotes, and follow the = with an integer larger than the number of cases in the file.

The following commands define the hc macro, perform the computations and produce the results. They should be run from a syntax file directly, or copied into a file that is then called using INSERT. They should not be used with INCLUDE.

preserve.
define hc (time=!charend('/')
/status=!charend('/')
/pred=!charend('/')
/n=!default(10000) !charend('/')).
set mxloops=!n.
matrix.
get data /var=!time !status !pred
/missing=omit.
compute time=data(:,1).
compute status=data(:,2).
compute pred=data(:,3).
compute concord=0.
compute discord=0.
computed tied=0.
loop i=1 to nrow(time)-1.
do if status(i)=1.
loop j=i+1 to nrow(time).
do if time(i)<time(j).
do if pred(i)>pred(j).
compute concord=concord+2.
else if pred(i)<pred(j).
compute discord=discord+2.
else if pred(i)=pred(j).
compute tied=tied+2.
end if.
else if time(i)=time(j).
do if status(j)<>1.
do if pred(i)>pred(j).
compute concord=concord+2.
else if pred(i)<pred(j).
compute discord=discord+2.
else if pred(i)=pred(j).
compute tied=tied+2.
end if.
end if.
else if time(i)>time(j).
do if status(j)=1.
do if pred(i)>pred(j).
compute discord=discord+2.
else if pred(i)<pred(j).
compute concord=concord+2.
else if pred(i)=pred(j).
compute tied=tied+2.
end if.
end if.
end if.
end loop.
else if status(i)<>1.
loop j=i+1 to nrow(time).
do if status(j)=1 and time(i)>=time(j).
do if pred(i)>pred(j).
compute discord=discord+2.
else if pred(i)<pred(j).
compute concord=concord+2.
else if pred(i)=pred(j).
compute tied=tied+2.
end if.
end if.
end loop.
end if.
end loop.
compute n_cases=nrow(time).
compute total=concord+discord+tied.
compute c=(concord+tied/2)/total.
compute d=2*c-1.
print n_cases.
print total.
print concord.
print discord.
print tied.
print c.
print d.
end matrix.
!enddefine.
restore.

The following commands call the macro defined by the prior commands, assuming that you add after each equals sign the appropriate variable name.

hc time=
/status=
/pred= .

Here is an example of the macro call with the default name for the first XBETA variable saved from COXREG, with time and status variables named "time" and "status":

hc time=time
/status=status
/pred=XBE_1 .

[{"Product":{"code":"SSLVMB","label":"IBM SPSS Statistics"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"Not Applicable","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"Not Applicable","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Historical Number

77397

Document Information

Modified date:
16 April 2020

UID

swg21478383