[R] controlling number of decimals printed in anova tables?

Dieter Menne dieter.menne at menne-biomed.de
Mon Feb 16 17:27:59 CET 2009


Gabor Grothendieck <ggrothendieck <at> gmail.com> writes:

> 
> On Mon, Feb 16, 2009 at 11:08 AM, Dieter Menne
> 
> Yes, with as.integer(round(...)) It looks like this:
> 
> > modelFit.glm(berk.mod2)
> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
> 
> > modelFit.glm(berk.mod2)
> Analysis of Deviance Table
>         Formula:  Freq ~ Dept * (Gender + Admit)
> 
>            Deviance   df Pr(>Chi^2)
> Null model     2650   23
> Model            22    6     0.0014 **
> ---

I am 90% I am on the wrong trip, help me out. And what happens to your solutions
if the Null Model has small Deviance?

Dieter


modelFit.glm <-
function (x, digits = max(3, getOption("digits") - 3), ...)
{
dev <- c(x$null.deviance, x$deviance )
df <- as.integer(c(x$df.null, x$df.residual))
#df <- as.integer(round(c(x$df.null, x$df.residual)))
table <- data.frame(dev, df, c(NA, 1-pchisq(x$deviance, x$df.residual)),
row.names=c("Null model", "Model"))

dimnames(table) <- list(c("Null model", "Model"), c("Deviance", "df", 
"Pr(>Chi^2)"))
title <- paste("Analysis of Deviance Table", "\n\tFormula: ", 
deparse(x$formula), "\n")
structure(table, heading = title, class = c("anova", "data.frame"))

}

berkeley <- as.data.frame(UCBAdmissions)
berk.mod2 <- glm(Freq ~ Dept * (Gender+Admit), data=berkeley, 
family="poisson")

modelFit.glm(berk.mod2)



Analysis of Deviance Table 
        Formula:  Freq ~ Dept * (Gender + Admit) 

           Deviance      df Pr(>Chi^2)   
Null model  2650.10   23.00              
Model         21.74    6.00   0.001352 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
>




More information about the R-help mailing list