When should aov () be used and when is anova ()?

I have mentioned most of the online literature, but this increases my confusion. Most of the discussion is too technical with terms of unbalanced designs and I, II, or III ANOVA factors and all.

I only know what it aov()uses lm()internally and is useful for data with factors. While it anova()can be used for different models on one data set. Do I understand correctly?

+4
source share
1 answer

anovasignificantly different from aov. Why not read the R documentation ?aovand ?anova? Shortly speaking:

  • aov ( , lm), , , ..; "aov", "lm". , "lm".
  • anova - . anova.lm anova.lmlist ( ?anova.lm ). ​​ ( lm aov), ( ) ( lm aov). ANOVA ().

lm/aov , anova . , :

fit <- aov(sr ~ ., data = LifeCycleSavings)  ## can also use `lm`
z <- anova(fit)

. aov :

str(fit)

#List of 12
# $ coefficients : Named num [1:5] 28.566087 -0.461193 -1.691498 -0.000337 0.409695
#  ..- attr(*, "names")= chr [1:5] "(Intercept)" "pop15" "pop75" "dpi" ...
# $ residuals    : Named num [1:50] 0.864 0.616 2.219 -0.698 3.553 ...
#  ..- attr(*, "names")= chr [1:50] "Australia" "Austria" "Belgium" "Bolivia" ...
# $ effects      : Named num [1:50] -68.38 -14.29 7.3 -3.52 -7.94 ...
#  ..- attr(*, "names")= chr [1:50] "(Intercept)" "pop15" "pop75" "dpi" ...
# $ rank         : int 5
# $ fitted.values: Named num [1:50] 10.57 11.45 10.95 6.45 9.33 ...
#  ..- attr(*, "names")= chr [1:50] "Australia" "Austria" "Belgium" "Bolivia" ...
# $ assign       : int [1:5] 0 1 2 3 4
# $ qr           :List of 5
#  ..$ qr   : num [1:50, 1:5] -7.071 0.141 0.141 0.141 0.141 ...
#  .. ..- attr(*, "dimnames")=List of 2
#  .. .. ..$ : chr [1:50] "Australia" "Austria" "Belgium" "Bolivia" ...
#  .. .. ..$ : chr [1:5] "(Intercept)" "pop15" "pop75" "dpi" ...
#  .. ..- attr(*, "assign")= int [1:5] 0 1 2 3 4
#  ..$ qraux: num [1:5] 1.14 1.17 1.16 1.15 1.05
#  ..$ pivot: int [1:5] 1 2 3 4 5
#  ..$ tol  : num 1e-07
#  ..$ rank : int 5
#  ..- attr(*, "class")= chr "qr"
# $ df.residual  : int 45
# $ xlevels      : Named list()
# $ call         : language aov(formula = sr ~ ., data = LifeCycleSavings)
# $ terms        :Classes 'terms', 'formula'  language sr ~ pop15 + pop75 + dpi + ddpi
#  .. ..- attr(*, "variables")= language list(sr, pop15, pop75, dpi, ddpi)
#  .. ..- attr(*, "factors")= int [1:5, 1:4] 0 1 0 0 0 0 0 1 0 0 ...
#  .. .. ..- attr(*, "dimnames")=List of 2
#  .. .. .. ..$ : chr [1:5] "sr" "pop15" "pop75" "dpi" ...
#  .. .. .. ..$ : chr [1:4] "pop15" "pop75" "dpi" "ddpi"
#  .. ..- attr(*, "term.labels")= chr [1:4] "pop15" "pop75" "dpi" "ddpi"
#  .. ..- attr(*, "order")= int [1:4] 1 1 1 1
#  .. ..- attr(*, "intercept")= int 1
#  .. ..- attr(*, "response")= int 1
#  .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> 
#  .. ..- attr(*, "predvars")= language list(sr, pop15, pop75, dpi, ddpi)
#  .. ..- attr(*, "dataClasses")= Named chr [1:5] "numeric" "numeric" "numeric" "numeric" ...
#  .. .. ..- attr(*, "names")= chr [1:5] "sr" "pop15" "pop75" "dpi" ...
# $ model        :'data.frame':	50 obs. of  5 variables:
#  ..$ sr   : num [1:50] 11.43 12.07 13.17 5.75 12.88 ...
#  ..$ pop15: num [1:50] 29.4 23.3 23.8 41.9 42.2 ...
#  ..$ pop75: num [1:50] 2.87 4.41 4.43 1.67 0.83 2.85 1.34 0.67 1.06 1.14 ...
#  ..$ dpi  : num [1:50] 2330 1508 2108 189 728 ...
#  ..$ ddpi : num [1:50] 2.87 3.93 3.82 0.22 4.56 2.43 2.67 6.51 3.08 2.8 ...
#  ..- attr(*, "terms")=Classes 'terms', 'formula'  language sr ~ pop15 + pop75 + dpi + ddpi
#  .. .. ..- attr(*, "variables")= language list(sr, pop15, pop75, dpi, ddpi)
#  .. .. ..- attr(*, "factors")= int [1:5, 1:4] 0 1 0 0 0 0 0 1 0 0 ...
#  .. .. .. ..- attr(*, "dimnames")=List of 2
#  .. .. .. .. ..$ : chr [1:5] "sr" "pop15" "pop75" "dpi" ...
#  .. .. .. .. ..$ : chr [1:4] "pop15" "pop75" "dpi" "ddpi"
#  .. .. ..- attr(*, "term.labels")= chr [1:4] "pop15" "pop75" "dpi" "ddpi"
#  .. .. ..- attr(*, "order")= int [1:4] 1 1 1 1
#  .. .. ..- attr(*, "intercept")= int 1
#  .. .. ..- attr(*, "response")= int 1
#  .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> 
#  .. .. ..- attr(*, "predvars")= language list(sr, pop15, pop75, dpi, ddpi)
#  .. .. ..- attr(*, "dataClasses")= Named chr [1:5] "numeric" "numeric" "numeric" "numeric" ...
#  .. .. .. ..- attr(*, "names")= chr [1:5] "sr" "pop15" "pop75" "dpi" ...
# - attr(*, "class")= chr [1:2] "aov" "lm"

anova :

str(z)

#Classes ‘anova’ and 'data.frame':  5 obs. of  5 variables:
# $ Df     : int  1 1 1 1 45
# $ Sum Sq : num  204.1 53.3 12.4 63.1 650.7
# $ Mean Sq: num  204.1 53.3 12.4 63.1 14.5
# $ F value: num  14.116 3.689 0.858 4.36 NA
# $ Pr(>F) : num  0.000492 0.061125 0.359355 0.042471 NA
# - attr(*, "heading")= chr  "Analysis of Variance Table\n" "Response: sr"
+6

Source: https://habr.com/ru/post/1661995/


All Articles