Main Content

coefTest

Linear hypothesis test on censored linear regression model coefficients

Since R2025a

    Description

    p = coefTest(mdl) computes the p-value for an F-test that all coefficient estimates in mdl, except the intercept term, are zero.

    p = coefTest(mdl,H) performs an F-test that H × B = 0, where B represents the coefficient vector. Use H to specify the coefficients to include in the F-test.

    p = coefTest(mdl,H,C) performs an F-test that H × B = C.

    [p,F] = coefTest(___) also returns the F-test statistic F using any of the input argument combinations in previous syntaxes.

    example

    [p,F,r] = coefTest(___) also returns the numerator degrees of freedom r for the test.

    example

    Examples

    collapse all

    Load the readmissiontimes sample 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,CategoricalVars="Smoker")
    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_1         -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 the linear model to the censored data.

    The last line of the model display shows the likelihood ratio statistic for the null hypothesis that the likelihood of the constant model is equal to the likelihood of the fitted model. The small p-value for the statistic indicates that enough evidence exists to conclude that the likelihood of the fitted model is different from the likelihood of the constant model.

    Perform an F-test to test the null hypothesis that the coefficients of the fitted model are equal to zero.

    [p,F] = coefTest(mdl)
    p = 
    4.2392e-32
    
    F = 
    93.6349
    

    The small p-value for the F-test indicates that enough evidence exists to conclude that at least one coefficient is different from zero. This result is consistent with the likelihood ratio test statistics in the model display.

    Load the readmissiontimes sample data.

    load readmissiontimes

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

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

    tbl = table(Age,Weight,ReadmissionTime);
    mdl = fitlmcens(tbl,Censoring=Censored)
    mdl = 
    Censored linear regression model
        ReadmissionTime ~ 1 + Age + Weight
    
    Estimated Coefficients:
                       Estimate        SE        tStat        pValue  
                       _________    ________    ________    __________
    
        (Intercept)        28.62      3.5313      8.1047    1.7047e-12
        Age            -0.060686    0.061984    -0.97905       0.33001
        Weight          -0.11977    0.017199     -6.9638    4.1162e-10
    
    Sigma: 4.245
    
    Number of observations: 100, Error degrees of freedom: 96
    25 right-censored observations
    75 uncensored observations
    Likelihood ratio statistic vs. constant model: 39, p-value = 3.47e-09
    

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

    For each coefficient, the model display includes the t-statistic and p-value for the null hypothesis that the coefficient is zero.

    Test the significance of the Weight coefficient. According to the model display, Weight is the third predictor. Specify the coefficient by using a numeric index vector.

    [p_Weight,F_Weight,r_Weight] = coefTest(mdl,[0 0 1])
    p_Weight = 
    4.1162e-10
    
    F_Weight = 
    48.4948
    
    r_Weight = 
    1
    

    p_Weight is the p-value corresponding to the F-statistic value F_Weight, and r_Weight is the numerator degrees of freedom for the F-test. The returned p-value indicates that Weight is statistically significant in the fitted model. Note that p_Weight is equal to the p-value of t-statistic (tStat) in the model display, and F_Weight is the square of tStat.

    Input Arguments

    collapse all

    Censored linear regression model, specified as a CensoredLinearModel object created using fitlmcens, or a CompactCensoredLinearModel object created using fitlmcens and compact.

    Hypothesis matrix, specified as a full-rank numeric index matrix of size r-by-s, where r is the number of linear combinations of coefficients being tested, and s is the total number of coefficients.

    • If you specify H, then the output p is the p-value for an F-test that H × B = 0, where B represents the coefficient vector.

    • If you specify H and C, then the output p is the p-value for an F-test that H × B = C.

    Example: [1 0 0 0 0] tests the first coefficient among five coefficients.

    Data Types: single | double

    Hypothesized value for testing the null hypothesis, specified as a numeric vector with the same number of rows as H.

    If you specify H and C, then the output p is the p-value for an F-test that H × B = C, where B represents the coefficient vector.

    Data Types: single | double

    Output Arguments

    collapse all

    p-value for the F-test, returned as a numeric value in the range [0,1].

    Value of the test statistic for the F-test, returned as a numeric value.

    Numerator degrees of freedom for the F-test, returned as a positive integer. The F-statistic has r degrees of freedom in the numerator and mdl.DFE degrees of freedom in the denominator.

    Algorithms

    The p-value, F-statistic, and numerator degrees of freedom are valid under these assumptions:

    • The data comes from a model represented by the formula in the Formula property of the fitted model.

    • The observations are independent, conditional on the predictor values.

    Under these assumptions, let β represent the (unknown) coefficient vector of the linear regression. Suppose H is a full-rank numeric index matrix of size r-by-s, where r is the number of linear combinations of coefficients being tested, and s is the total number of coefficients. Let c be a column vector with r rows. The following is a test statistic for the hypothesis that  = c:

    F=(Hβ^c)(HVH)1(Hβ^c)/r.

    Here, β^ is the estimate of the coefficient vector β, stored in the Coefficients property, and V is the estimated covariance of the coefficient estimates, stored in the CoefficientCovariance property. When the hypothesis is true, the test statistic F has an F Distribution with r and u degrees of freedom, where u is the degrees of freedom for error, stored in the DFE property.

    Alternative Functionality

    The values of commonly used test statistics are available in the Coefficients property of a fitted model.

    Version History

    Introduced in R2025a