image thumbnail

SCOPE: mulit-variate cox regression

by

 

Compute and plot cox regression fit using censored survival data stored in an excel file

xlsSeerComputeSurvivalFuntionCoxRegression(xlsfilename)
%By Dr. Rex Cheung -- Mainline, PA, USA. Fall of 2012. 
%This program is a SCOPE sub-routine to compute and plot cox regression using censored survival data stored in
%an excel file
%This download should include this code, a randomly generated excel data
%file for testing purposes, and the example output.
%This program expects four excel columns 1. follow up time and 2. failure
%indicator (1=failure has occured and 0=no failure has occurred. 3.
%Predictor1 and 4. predictor2.
%A randomly generated excel data file example is included for testing.

%Type this at the command line to run: [b,logL,H,stats]= xlsSeerComputeSurvivalFuntionCoxRegression('survivalPreditorsTestData.xls')

function [b,logL,H,stats]= xlsSeerComputeSurvivalFuntionCoxRegression(xlsfilename)
%__________________________________________________________________________
%Open the excel file and read the follow up time (futime) column from xls file
uiwait(msgbox('select the column of f/u time data')); %wait for the user to interact
[a b] =xlsread(xlsfilename,-1); %[number text]=xlsread()
columnname=a(1); %extract the name of the column, interchange a and b position in the line above to capture
                  %the information
tempinputcol=a(1:end,1); %same as a(2:end) fro string, use a(1:end,1) for numbers,

futime=tempinputcol;
%__________________________________________________________________________
%Open the excel file and read the failure indicator (failureIndicator) column from xls file
uiwait(msgbox('select the column of failure indicator data')); %wait for the user to interact
[c d] =xlsread(xlsfilename,-1); %[number text]=xlsread()
columnname=c(1); %extract the name of the column, interchange a and b position in the line above to capture
                  %the information
tempinputcol2=c(1:end,1); %same as a(2:end) fro string, use a(1:end,1) for numbers,

failureIndicator=tempinputcol2;

%compute the censored and censoredfutime
censored = 1-failureIndicator;
%__________________________________________________________________________
%Open the excel file and read the predictor2 column from xls file
uiwait(msgbox('select the column of predicator1 data')); %wait for the user to interact
[e f] =xlsread(xlsfilename,-1); %[number text]=xlsread()
columnname=e(1); %extract the name of the column, interchange a and b position in the line above to capture
                  %the information
tempinputcol3=e(1:end,1); %same as a(2:end) fro string, use a(1:end,1) for numbers,

predictor1=tempinputcol3;
%__________________________________________________________________________
%Open the excel file and read the predictor2 column from xls file
uiwait(msgbox('select the column of predicator2 data')); %wait for the user to interact
[g h] =xlsread(xlsfilename,-1); %[number text]=xlsread()
columnname=g(1); %extract the name of the column, interchange a and b position in the line above to capture
                  %the information
tempinputcol4=g(1:end,1); %same as a(2:end) fro string, use a(1:end,1) for numbers,

predictor2=tempinputcol4;
%______________________________________________________________________________
%Matlab doc: coxphfit(x,y,'censoring',CA) where CA is an array of Booleans of the same size as y.
%set y=futime
y=futime;
%set CA=censoring indicator
CA=censored;
%concatenate the predictors into x
x=horzcat(predictor1,predictor2);

%calculate the cox regression of two predictors
[b,logL,H,stats] = coxphfit(x,y,'censoring',CA);

%plot the cox proportional hazard fit to the survival data
%this could be compared with my plot using ecdf()
stairs(H(:,1),exp(-H(:,2)))


Contact us