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

2009-02-16 Thread Michael Friendly

Thanks, Gabor
No, that wasn't it at all.  In print.anova, I found:

   if (length(i <- grep("Df$", cn)))
   zap.i <- zap.i[!(zap.i %in% i)]

so it only recognizes "Df", not "df" as a column name prefix to print as 
integers.

-Michael

Gabor Grothendieck wrote:

Or safer:

df <- as.integer(round(...))

On Mon, Feb 16, 2009 at 10:54 AM, Gabor Grothendieck
 wrote:
  

Try this:

On Mon, Feb 16, 2009 at 9:02 AM, Michael Friendly  wrote:


For glm() models, I often find both the print() and summary() method
disappointing if my main interest
is seeing how well a given model fits. A basic display would just compare
the null model to to my model.

I wrote the function below based on code in some package.
How can I make it so that the df in the table are printed with 0 decimals?
  

Try this:
df <- as.integer(c(x$df.null, x$df.residual))





--
Michael Friendly Email: friendly AT yorku DOT ca 
Professor, Psychology Dept.

York University  Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT  M3J 1P3 CANADA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2009-02-16 Thread Dieter Menne
Gabor Grothendieck  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
> Model226 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.746.00   0.001352 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2009-02-16 Thread Gabor Grothendieck
On Mon, Feb 16, 2009 at 11:08 AM, Dieter Menne
 wrote:
> Gabor Grothendieck  gmail.com> writes:
>
>>
>> Or safer:
>>
>> df <- as.integer(round(...))
>>
>
> Did you try? I believe it is a problem of printCoefmat that has quite
> a few options for special column, but none for df. Ask Martin Mächler.

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
Model226 0.0014 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Also note:

> as.integer(1-.1)
[1] 0
> as.integer(round(1-.1))
[1] 1

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2009-02-16 Thread Dieter Menne
Gabor Grothendieck  gmail.com> writes:

> 
> Or safer:
> 
> df <- as.integer(round(...))
> 

Did you try? I believe it is a problem of printCoefmat that has quite
a few options for special column, but none for df. Ask Martin Mächler.

Dieter

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2009-02-16 Thread Gabor Grothendieck
Or safer:

df <- as.integer(round(...))

On Mon, Feb 16, 2009 at 10:54 AM, Gabor Grothendieck
 wrote:
> Try this:
>
> On Mon, Feb 16, 2009 at 9:02 AM, Michael Friendly  wrote:
>> For glm() models, I often find both the print() and summary() method
>> disappointing if my main interest
>> is seeing how well a given model fits. A basic display would just compare
>> the null model to to my model.
>>
>> I wrote the function below based on code in some package.
>> How can I make it so that the df in the table are printed with 0 decimals?
>
> Try this:
> df <- as.integer(c(x$df.null, x$df.residual))
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2009-02-16 Thread Gabor Grothendieck
Try this:

On Mon, Feb 16, 2009 at 9:02 AM, Michael Friendly  wrote:
> For glm() models, I often find both the print() and summary() method
> disappointing if my main interest
> is seeing how well a given model fits. A basic display would just compare
> the null model to to my model.
>
> I wrote the function below based on code in some package.
> How can I make it so that the df in the table are printed with 0 decimals?

Try this:
df <- as.integer(c(x$df.null, x$df.residual))

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2009-02-16 Thread Michael Friendly
For glm() models, I often find both the print() and summary() method 
disappointing if my main interest
is seeing how well a given model fits. A basic display would just 
compare the null model to to my model.


I wrote the function below based on code in some package.
How can I make it so that the df in the table are printed with 0 decimals?

# display basic model fit statistics for a glm object

modelFit.glm <-
function (x, digits = max(3, getOption("digits") - 3), ...)
{
dev <- c(x$null.deviance, x$deviance )
df <- 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
>


--
Michael Friendly Email: friendly AT yorku DOT ca 
Professor, Psychology Dept.

York University  Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT  M3J 1P3 CANADA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.