Main Content

compact

Create compact censored linear regression model

Since R2025a

    Description

    compactMdl = compact(mdl) returns the compact censored linear regression model compactMdl, which is the compact version of the full, fitted censored linear regression model mdl.

    example

    Examples

    collapse all

    Load the censored readmissiontimes data.

    load readmissiontimes

    The variables Age, Weight, Smoker, and ReadmissionTime contain data for patient age, weight, smoking status, and time of readmission. The Censored variable contains censoring information for ReadmissionTime.

    Save Age, Weight, Smoker, and ReadmissionTime in a table, and fit a censored linear regression model to the data.

    tbl = table(Age,Weight,Smoker,ReadmissionTime);
    mdl = fitlmcens(tbl,Censoring=Censored)
    mdl = 
    Censored linear regression model
        ReadmissionTime ~ 1 + Age + Weight + Smoker
    
    Estimated Coefficients:
                       Estimate        SE        tStat        pValue  
                       _________    ________    ________    __________
    
        (Intercept)        27.74      3.4008      8.1569    1.4048e-12
        Age            -0.053476    0.059514    -0.89854       0.37117
        Weight          -0.11101    0.016823     -6.5986    2.3484e-09
        Smoker           -2.3455     0.93105     -2.5192      0.013434
    
    Sigma: 4.068
    
    Number of observations: 100, Error degrees of freedom: 95
    25 right-censored observations
    75 uncensored observations
    Likelihood ratio statistic vs. constant model: 45, p-value = 9.27e-10
    

    mdl is a CensoredLinearModel object that contains the results of fitting a linear model to the censored data.

    Compact the model.

    compactMdl = compact(mdl);

    The compact model discards the original sample data and some information related to the fitting process.

    Compare the size of the full model mdl and the compact model compactMdl.

    vars = whos("compactMdl","mdl");
    [vars(1).bytes,vars(2).bytes]
    ans = 1×2
    
            5449       14313
    
    

    The compact model uses less memory than the full model.

    Input Arguments

    collapse all

    Censored linear regression model, specified as a CensoredLinearModel object created using fitlmcens.

    Output Arguments

    collapse all

    Compact censored linear regression model, returned as a CompactCensoredLinearModel object.

    A CompactCensoredLinearModel object uses less memory than a CensoredLinearModel object because a compact model does not store the input data used to fit the model or information related to the fitting process. You can still use a compact model to predict responses using new input data, but some CensoredLinearModel object functions do not work with a compact model.

    Version History

    Introduced in R2025a