Main Content

varianceComponent

Variance component estimates for analysis of variance (ANOVA)

Since R2022b

    Description

    v = varianceComponent(aov) returns a table of variance component estimates of the random factors and error for an anova object at the 95% confidence level.

    example

    v = varianceComponent(aov,Alpha=alpha) returns the variance component estimates with 100(1α)% confidence intervals.

    example

    Examples

    collapse all

    Load the sample car data.

    load carsmall

    Data for the country of origin, model year, and mileage is stored in the variables Origin, Model_Year, and MPG, respectively.

    Perform a two-way ANOVA to test the null hypothesis that mean mileage is not affected by the country of origin or model year. The factors Origin and Year are random because the data was sampled from a larger population.

    aov = anova({Origin, Model_Year},MPG,RandomFactors=[1 2],FactorNames=["Origin" "Year"])
    aov = 
    2-way anova, constrained (Type III) sums of squares.
    
    Y ~ 1 + Origin + Year
    
                  SumOfSquares    DF    MeanSquares      F         pValue  
                  ____________    __    ___________    ______    __________
    
        Origin       1078.1        5      215.62       10.675    5.3303e-08
        Year         2638.4        2      1319.2       65.312    5.5975e-18
        Error          1737       86      20.198                           
        Total        6005.3       93                                       
    
    
      Properties, Methods
    
    
    

    The p-values for Origin and Year indicate that the country of origin and model year have statistically significant effects on mileage.

    Display the variance component estimates for the error and random factors with confidence intervals. Use the default confidence level of 95%.

    vtbl = varianceComponent(aov)
    vtbl=3×3 table
                  VarianceComponent    VarianceComponentLower    VarianceComponentUpper
                  _________________    ______________________    ______________________
    
        Origin         21.337                  6.1257                    139.94        
        Year           44.031                  11.176                    1765.7        
        Error          20.198                  15.298                    27.909        
    
    

    The variance components for Origin and Year are due to the random sampling of the data. The variance of MPG is the sum of the variance components for Origin, Year, and Error. The table output shows that the variance components for Origin and Year are responsible for the majority of the variance in MPG.

    Load the sample car data.

    load carsmall

    Data for the model year and mileage is stored in the variables Model_Year and MPG, respectively.

    Perform a two-way ANOVA to test the null hypothesis that mean mileage is not affected by the model year. Year is a random factor because it contains a randomly selected subset of all possible model years.

    aov = anova(Model_Year, MPG, RandomFactors=[1],FactorNames=["Year"])
    aov = 
    1-way anova, constrained (Type III) sums of squares.
    
    Y ~ 1 + Year
    
                 SumOfSquares    DF    MeanSquares      F        pValue  
                 ____________    __    ___________    _____    __________
    
        Year        3190.1        2      1595.1       51.56    1.0694e-15
        Error       2815.2       91      30.936                          
        Total       6005.3       93                                      
    
    
      Properties, Methods
    
    
    

    Display the variance component estimates for Year and the error with confidence intervals. Specify a confidence level of 99%.

    vtbl = varianceComponent(aov,Alpha=0.01)
    vtbl=2×3 table
                 VarianceComponent    VarianceComponentLower    VarianceComponentUpper
                 _________________    ______________________    ______________________
    
        Year          50.026                  8.1282                     10177        
        Error         30.936                   21.74                    46.915        
    
    

    The output shows that Year contributes more to the sample variance than Error.

    Input Arguments

    collapse all

    ANOVA results, specified as an anova object. The properties of aov contain the factors and response data used by varianceComponent to compute the variance component estimates and their confidence intervals.

    Significance level for the estimates, specified as a scalar value in the range (0,1). The confidence level of the confidence intervals is 100(1α)%. The default value for alpha is 0.05, which returns 95% confidence intervals for the estimates.

    Example: Alpha=0.01

    Data Types: single | double

    Output Arguments

    collapse all

    Variance component estimates and their confidence intervals, returned as a table. The varianceComponent function assumes that coefficients for dummy variables corresponding to the same random factor have equal variance. The table v has rows for the error term and for each of the random terms in aov.Formula. The columns of v correspond to the following variables:

    • VarianceComponent — The estimated variance component.

    • VarianceComponentLower — A lower confidence bound of the variance component. You can specify the confidence level using alpha.

    • VarianceComponentUpper — An upper confidence bound of the variance component.

    You can use the variance component estimates to determine if the random sampling has a significant effect on the mean squares of a term.

    Data Types: table

    References

    [1] Dunn, O. J., and V. A. Clark. Applied Statistics: Analysis of Variance and Regression. New York: Wiley, 1974.

    [2] Goodnight, J. H., and F. M. Speed. Computing Expected Mean Squares. Cary, NC: SAS Institute, 1978.

    [3] Seber, G. A. F., and A. J. Lee. Linear Regression Analysis. 2nd ed. Hoboken, NJ: Wiley-Interscience, 2003.

    Version History

    Introduced in R2022b