Rapporter / pander

An R Pandoc Writer: Convert arbitrary R objects into markdown
http://rapporter.github.io/pander/
Open Software License 3.0
294 stars 66 forks source link

pander.anova always wants that fifth column to have p-value #297

Open therimalaya opened 7 years ago

therimalaya commented 7 years ago

Many ANOVA table may not have p-value at the fifth column. For example, if you use chisq test for MerMod Model, your p-value may lie on 3rd or 4th column of the ANOVA table. Isn't it good idea for displaying significance starts not my searching the p-value in 5th column but asking user for the index of the column that contains the p-value?

daroczig commented 7 years ago

Can you please provide a minimal reproducible example?

therimalaya commented 7 years ago

I will use an example in help file of lmer function of lme4 package. For example you have fitted two models as,

fm1 <- lme4::lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
fm2 <- lme4::lmer(Reaction ~ Days + (Days || Subject), sleepstudy)

If I want pander to print its ANOVA table obtained from Anova function of car package, then I will print,

pander::pander(car::Anova(fm1))
------------------------------------
  &nbsp;    Chisq   Df   Pr(>Chisq) 
---------- ------- ---- ------------
 **Days**   45.85   1    1.275e-11  
------------------------------------

Table: Analysis of Deviance Table (Type II Wald chisquare tests)

But, if I tried to use the parameter add.significance.star = T, then pander calls pander.anova which checks for 5th column to be a column for p-value, which is not in this case. The column of p-value vary accross different ANVOA ouput. The error I get is,

pander::pander(car::Anova(fm1), add.significance.star = T)
Error in `[.data.frame`(x, , 5) : undefined columns selected

The problem is not only with this situations, if I want to compare model fm1 and fm2 and wants to print the Anova table I get, the same thing happens,

pander::pander(anova(fm1, fm2))
pander::pander(anova(fm1, fm2), add.significance.star = T)

The first one gives an output as,

refitting model(s) with ML (instead of REML)

----------------------------------------------------------------------------
 &nbsp;    Df   AIC   BIC   logLik   deviance   Chisq   Chi Df   Pr(>Chisq) 
--------- ---- ----- ----- -------- ---------- ------- -------- ------------
 **fm2**   5   1762  1778    -876      1752      NA       NA         NA     

 **fm1**   6   1764  1783    -876      1752    0.06391    1        0.8004   
----------------------------------------------------------------------------

Table: Data: sleepstudy

The second one tries to use 5th columns as p-value and thus the output becomes,

refitting model(s) with ML (instead of REML)

----------------------------------------------------------------------------
 &nbsp;    Df   AIC   BIC   logLik   deviance   Chisq   Chi Df   Pr(>Chisq) 
--------- ---- ----- ----- -------- ---------- ------- -------- ------------
 **fm2**   5   1762  1778    -876                NA       NA         NA     

 **fm1**   6   1764  1783    -876              0.06391    1        0.8004   
----------------------------------------------------------------------------

Table: Data: sleepstudy

Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Look at the deviance column !!