How to hide anova significance levels at the bottom of the table

Suppose I compared two models of nested random effects using anova() , and the result is below:

 new.model: new current.model: new Df AIC BIC logLik Chisq Chi Df Pr(>Chisq) new.model 8 299196 299259 -149590 current.model 9 299083 299154 -149533 115.19 1 < 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

I would like to use only part of the table (see below):

  Df AIC BIC logLik Chisq Chi Df Pr(>Chisq) new.model 8 299196 299259 -149590 current.model 9 299083 299154 -149533 115.19 1 < 2.2e-16 *** 

I know that I can get rid of part of the header (see hit) by setting the header to zero using the attributes (anova.object) $ heading = NULL, but I don't know how to get rid of the bottom of the part: sign. codes: .....

 new.model: new current.model: new 

I basically do not want to use data.frame (see below), since it changes empty cells to NA

 data.frame(anova(new.model, current.model)) Df AIC BIC logLik Chisq Chi.Df Pr..Chisq. new.model 8 299196.4 299258.9 -149590.2 NA NA NA current.model 9 299083.2 299153.6 -149532.6 115.1851 1 7.168247e-27 

I wonder if you know that you know how to deal with this situation.

[UPDATE]: I ended up writing a wrapper using print.anova:

 anova.print = function(object, signif.stars = TRUE, heading = TRUE){ if(!heading) attributes(object)$heading = NULL print.anova(object, signif.stars = signif.stars) } 

Example:

 dv = c(rnorm(20), rnorm(20, mean=2), rnorm(20)) iv = factor(rep(letters[1:3], each=20)) anova.object = anova(lm(dv~iv)) Analysis of Variance Table Response: dv Df Sum Sq Mean Sq F value Pr(>F) iv 2 46.360 23.1798 29.534 1.578e-09 *** Residuals 57 44.737 0.7849 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 anova.print(anova.object, F, F) Df Sum Sq Mean Sq F value Pr(>F) iv 2 46.360 23.1798 29.534 1.578e-09 Residuals 57 44.737 0.7849 
+4
source share
2 answers

The other day we had a similar article about not showing the National Assembly. You can do:

 x <- as.matrix(anova(new.model, current.model)) print(x, na.print="", quote=FALSE) 

A more reproducible example using the mtcars :

 x <- as.matrix(anova(lm(hp~mpg+am, data=mtcars))) print(x, na.print="", quote=FALSE) 
+3
source

EDIT: anova has a print method with signif.stars as a parameter

 anova(new.model, current.model, signif.stars=FALSE) > x <- anova(lm(hp~mpg+am, data=mtcars)) > print(x, signif.stars=F) Analysis of Variance Table Response: hp Df Sum Sq Mean Sq F value Pr(>F) mpg 1 87791 87791 54.5403 3.888e-08 am 1 11255 11255 6.9924 0.01307 Residuals 29 46680 1610 
+10
source

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


All Articles