Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.

anova

Clase: CompactLinearModel

Analysis of variance for linear model

Sintaxis

tbl = anova(mdl)
tbl = anova(mdl,anovatype)
tbl = anova(mdl,anovatype,sstype)

Description

tbl = anova(mdl) returns a table with summary ANOVA statistics.

tbl = anova(mdl,anovatype) returns ANOVA statistics of the chosen type.

tbl = anova(mdl,anovatype,sstype) computes ANOVA statistics using the chosen type of sum of squares.

Argumentos de entrada

expandir todo

Linear model object, specified as a full LinearModel object constructed using fitlm or stepwiselm, or a compacted CompactLinearModel object constructed using compact.

ANOVA type, specified as one of the following:

  • 'component'tbl displays a ‘components’ ANOVA table, with sums of squares and F tests attributable to each term in the model except the constant term.

  • 'summary'tbl displays a summary ANOVA table with an F test for the model as a whole.

    • If there are both linear and higher-order terms, there is also an F test for the higher-order terms as a group.

    • If mdl is a full LinearModel object and the sample data contains replications (multiple observations sharing the same predictor values), there is also an F test for lack-of-fit computed by decomposing the residual sum of squares into a sum of squares for the replicated observations and the remaining sum of squares. If mdl is a compacted CompactLinearModel object, then the ANOVA table presents, but does not decompose, the residual sum of squares.

Sum of squares type, specified as one of the following:

ValueDescription
1Type I sum of squares. The reduction in residual sum of squares obtained by adding that term to a fit that already includes the terms listed before it.
2Type II sum of squares. The reduction in residual sum of squares obtained by adding that term to a model consisting of all other terms that do not contain the term in question
3Type III sum of squares. The reduction in residual sum of squares obtained by adding that term to a model containing all other terms, but with their effects constrained to obey the usual “sigma restrictions” that make models estimable.
'h'Hierarchical model. Similar to Type II, but uses both continuous and categorical factors to determine the hierarchy of terms.

For Type III sum of squares:

  • If mdl is a CompactLinearModel object and the model is non-hierarchical, anova errors.

  • If mdl is a full LinearModel object and the model is non-hierarchical, then anova refits the model using effects coding whenever it needs to compute Type III sums of squares.

  • If mdl is either a CompactLinearModel or a LinearModel object and the model is hierarchical, anova computes the results without refitting the model.

sstype only applies if anovatype is 'component'.

For more information about sum of squares types, see the sstype argument on the anovan function reference page.

Tipos de datos: char | string | single | double

Output Arguments

expandir todo

ANOVA summary statistics table, returned as table

The contents of tbl depends on the ANOVA type specified in anovatype.

  • If anovatype is 'component', then tbl contains:

    • Sum of squares

    • Degrees of freedom

    • Mean squares

    • F statistic

    • p-value

    • Formula used for model

  • If anovatype is 'summary', then tbl contains:

    • Total Sum of Squares

    • Model Sum of Squares

      • Linear Sum of Squares (present if model has powers or interactions)

      • Nonlinear Sum of Squares (present if model has powers or interactions)

    • Residual Sum of Squares

      • Lack-of-fit Sum of Squares (present if model has replicates)

      • Pure error Sum of Squares (present if model has replicates)

Ejemplos

expandir todo

Create a component ANOVA table from a model of the hospital data.

Load the hospital data and make a model of the blood pressure as a function of age and gender.

load hospital
tbl = table(hospital.Age,hospital.Sex,hospital.BloodPressure(:,2), ...
    'VariableNames',{'Age','Sex','BloodPressure'});
tbl.Sex = categorical(tbl.Sex);
mdl = fitlm(tbl,'BloodPressure ~ Sex + Age^2');

Create an ANOVA table.

tbl = anova(mdl)
tbl=4×5 table
             SumSq     DF    MeanSq       F        pValue 
             ______    __    ______    _______    ________

    Age      18.705     1    18.705    0.40055     0.52831
    Sex      222.09     1    222.09     4.7558    0.031643
    Age^2    30.934     1    30.934    0.66242     0.41772
    Error    4483.1    96    46.699                       

Create a summary ANOVA table from a model of the carsmall data.

Load the carsmall data and make a model of the MPG as a function of weight and model year.

load carsmall
cars = table(MPG,Weight);
cars.Year = ordinal(Model_Year);
mdl = fitlm(cars,'MPG ~ Year + Weight^2');

Create a summary ANOVA table.

tbl = anova(mdl,'summary')
tbl=7×5 table
                     SumSq     DF    MeanSq      F         pValue  
                     ______    __    ______    ______    __________

    Total            6005.3    93    64.573                        
    Model              5317     4    1329.3    171.88    5.5208e-41
    . Linear         5240.3     3    1746.8    225.87    1.7302e-41
    . Nonlinear      76.688     1    76.688    9.9164     0.0022303
    Residual         688.27    89    7.7334                        
    . Lack of fit    663.77    86    7.7183    0.9451       0.62874
    . Pure error       24.5     3    8.1667                        

The summary ANOVA table shows tests for groups of terms. The nonlinear group consists of just the Weight^2 term, so it has the same -value as that term in the component ANOVA table. The statistic comparing the residual sum of squares to a "pure error" estimate from replicated observations shows no evidence of lack of fit.

Alternatives

More complete ANOVA statistics are available in the anova1, anova2, and anovan functions.