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' . > 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) } -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. & Chair, Quantitative Methods York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA [[alternative HTML version deleted]]
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) > } > > > >
Hi Michael, Take a look at ?printCoefmat. I hope this helps, John On Sat, 02 Mar 2013 12:37:36 -0500 Michael Friendly <friendly at yorku.ca> wrote:> 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' . > > > 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) > } > > > > > -- > Michael Friendly Email: friendly AT yorku DOT ca > Professor, Psychology Dept. & Chair, Quantitative Methods > York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 > 4700 Keele Street Web: http://www.datavis.ca > Toronto, ONT M3J 1P3 CANADA > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.
Some packages have to be installed on new R version, 2.15.3 but I have 2.15.2 If I don't want to go through all download, and uninstall and install procedures, is there any simple R command that could handle this? Thanks. [[alternative HTML version deleted]]