[R] print method like print.anova()
Milan Bouchet-Valat
nalimilan at club.fr
Sat Mar 2 19:28:50 CET 2013
Le samedi 02 mars 2013 à 12:37 -0500, Michael Friendly a écrit :
> I have a print method for a set of statistical tests, vcdExtra::CMHtest,
> for which I'd like to
> have more sensible printing of pvalues, as in print.anova().
> [Testing this requires the latest version of vcdExtra, from R-Forge
> **|install.packages("vcdExtra", repos="http://R-Forge.R-project.org")|**
> ]
>
> With my current print method, I get results like this, but all Prob
> values should better
> be reported as something like '<0.0001' .
I think you want to use format.pval(), which is intended exactly for
this use case:
format.pval(c(7.4426e-13, 5.6601e-12, 1.3450e-11, 1.9580e-10), eps=1e-3)
# [1] "< 0.001" "< 0.001" "< 0.001" "< 0.001"
My two cents
> > CMHtest(MSPatients[,,1])
> Cochran-Mantel-Haenszel Statistics for New Orleans Neurologist by
> Winnipeg Neurologist
>
> AltHypothesis Chisq Df Prob
> cor Nonzero correlation 51.424 1 7.4426e-13
> cmeans Col mean scores differ 55.393 3 5.6601e-12
> rmeans Row mean scores differ 53.631 3 1.3450e-11
> general General association 64.318 9 1.9580e-10
>
> In the print.CMHtest() function below the lines before # # TODO give the
> output shown above.
> The lines below try to use print.anova(), but this gives something even
> worse:
>
> Cochran-Mantel-Haenszel Statistics for New Orleans Neurologist by
> Winnipeg Neurologist
>
> AltHypothesis Chisq Df Prob
> cor 3 51.424 1 7.440e-13
> cmeans 1 55.393 3 5.660e-12
> rmeans 4 53.631 3 1.345e-11
> general 2 64.318 9 1.958e-10
>
> Here is the print method, showing the attempt to use print.anova() as well:
>
> print.CMHtest <- function(x, digits = max(getOption("digits") - 2, 3),
> ...) {
> heading <- "Cochran-Mantel-Haenszel Statistics"
> if (!is.null(x$names)) heading <- paste(heading, "for",
> paste(x$names, collapse=" by "))
> # TODO: determine score types (integer, midrank) for heading
>
> df <- x$table
> types <- rownames(df)
> labels <- list(cor="Nonzero correlation", rmeans="Row mean scores
> differ",
> cmeans="Col mean scores differ", general="General association")
> df <-
> data.frame("AltHypothesis"=as.character(unlist(labels[types])), df)
> cat(heading,"\n\n")
> print(df, digits=digits, ...)
> cat("\n")
>
> # # TODO: use print.anova() method, but this screws up the AltHyp
> attr(df, "heading") <- paste(heading,"\n")
> class(df) <- c("anova", "data.frame")
> print(df)
> invisible(x)
> }
>
>
>
>
More information about the R-help
mailing list