Main Content

discardResiduals

Remove residuals from Cox model

Description

example

compactCoxMdl = discardResiduals(coxMdl) creates a Cox proportional hazards model with an empty Residuals property. For models trained on many data points, removing the residuals yields a significantly more compact object.

Examples

collapse all

Create a Cox proportional hazards model from the lightbulb data set. For details of this data set, see Survivor Functions for Two Groups.

load('lightbulb.mat');
bulbmodel = fitcox(lightbulb(:,2),lightbulb(:,1),...
    'Censoring',lightbulb(:,3));

Examine the memory used by bulbmodel.

S1 = whos('bulbmodel');
disp(S1.bytes)
       13912

Remove the residuals from bulbmodel and examine the memory savings.

bulbmodel = discardResiduals(bulbmodel);
S2 = whos('bulbmodel');
disp(S2.bytes/S1.bytes)
    0.4986

Removing the residuals lowers the memory usage by about half.

Input Arguments

collapse all

Fitted Cox proportional hazards model, specified as a CoxModel object. Create coxMdl using fitcox.

Output Arguments

collapse all

Cox proportional hazards model without residuals, returned as a CoxModel object. Typically, set compactCoxMdl to the same name as coxMdl to obtain the original object without the residuals:

coxMdl = discardResiduals(coxMdl);

Version History

Introduced in R2022b