Re: [R] Wilcoxon test output as a table

From: Iurie Malai <iurie.malai_at_gmail.com>
Date: Sun, 06 Jun 2010 02:24:33 +0300

Maybe, this will be better:

W <- as.matrix(lapply(Dataset[2:11], function(x) wilcox.test(x ~ GrFac, alternative="two.sided", data=Dataset)$statistic)) P <- as.matrix(lapply(Dataset[2:11], function(x) wilcox.test(x ~ GrFac, alternative="two.sided", data=Dataset)$p.value)) out <- rbind(as.numeric(W),as.numeric(P)) rownames(out) <- c("W", "p")
colnames(out) <- paste(colnames(Dataset[2:11])) out

The output table we can format later in a spreadsheet (Calc, Excel, etc.).

2010/6/6 Iurie Malai <iurie.malai_at_gmail.com>

> Yes, Joris, my code (and output) is not perfect, but right now is
> acceptable for me. Later I will try the options suggested by you.
>
> Thank you very much for your help!
>
> Iurie
>
>
>
> 2010/6/6 Joris Meys <jorismeys@gmail.com>
>
>> Can't reproduce those with your code and your dataset.
>> I also noticed some other unwanted behaviour by using as.numeric : it
>> changes the formatting again. You won't get rid of the "" as that
>> indicates it's a character, and you won't be able to format the
>> numbers as the columns in a dataframe or in a matrix have all the same
>> formatting.
>>
>> If you want to generate output for a function or so, you can play
>> around with cat() (see ?cat ). If it's for a report, think about using
>> latex or HTML and the xtable package. There are other options, but
>> that requires a bit more info.
>>
>> And your code is not very optimal.
>>
>> setwd("c:/Temp")
>> Dataset <- read.table("Dataset.txt",header=T,sep=",")
>>
>> W <- apply(Dataset[2:11],2, function(x) wilcox.test(x ~ GrFac,
>> alternative="two.sided", data=Dataset)$statistic)
>> P <- apply(Dataset[2:11],2, function(x) wilcox.test(x ~ GrFac,
>> alternative="two.sided", data=Dataset)$p.value)
>> W <- format(W, digits = 5, nsmall = 2)
>> P <- format(P, digits = 1, nsmall = 3)
>>
>> out <- rbind(W,P)
>> rownames(out) <- c("W","P")
>> colnames(out) <- colnames(Dataset[2:11])
>>
>>
>> If you know latex, you can use following package to get
>> library(xtable)
>> xtable(out) # latex output
>>
>> #html output
>> outtable <- xtable(out)
>> print(outtable,type="html")
>>
>> On Sat, Jun 5, 2010 at 11:35 PM, Iurie Malai <iurie.malai_at_gmail.com>
>> wrote:
>> > Thank you, Joris!
>> >
>> > I received two identical warnings:
>> >
>> > [14] WARNING: Warning in if (nchar(cmd) <= width) return(cmd) :
>> > the condition has length > 1 and only the first element will be used
>> > [15] WARNING: Warning in if (nchar(cmd) <= width) return(cmd) :
>> > the condition has length > 1 and only the first element will be used
>> >
>> > 2010/6/6 Joris Meys <jorismeys_at_gmail.com>
>> >
>> >> # not tested
>> >> out <- rbind(as.numeric(Wnew),as.numeric(P))
>> >> rownames(out) <- c("Wnew","P")
>> >>
>> >>
>> >
>> > [[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.
>> >
>>
>>
>>
>> --
>> Ghent University
>> Faculty of Bioscience Engineering
>> Department of Applied mathematics, biometrics and process control
>>
>> tel : +32 9 264 59 87
>> Joris.Meys_at_Ugent.be
>> -------------------------------
>> Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
>>
>
>
>
> --
> Iurie Malai, Senior Lecturer
> Department of Psychology
> Faculty of Psychology and Special Education
> Ion Creanga Moldova Pedagogical State University - www.upsm.md
> http://en.wikipedia.org/wiki/Ion_Creang%C4%83_Pedagogical_State_University
>

        [[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. Received on Sat 05 Jun 2010 - 23:27:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 06 Jun 2010 - 04:50:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive