Re: [R] creating a file of p.values

From: Peter Dalgaard <P.Dalgaard_at_biostat.ku.dk>
Date: Wed, 12 Nov 2008 17:49:03 +0100

jim holtman wrote:

> Try something like this (untested):
> 
> Pvalues <- lapply(1:25, function(x)get(paste("A", i, sep=""))$p.value)


He probably wants to start one level earlier, with the X1, etc.

How about

nm <- paste("X", 1:9, sep="")
fml <- lapply(nm, function(nm)eval(bquote(.(as.name(nm))~treatment)) ) names(fml) <- nm

dd <- as.data.frame(matrix(rnorm(300),30)) names(dd) <- nm
attach(dd)
treatment <- rep(1:3,10)
sapply(fml, function(f) kruskal.test(f)$p.value)

(This overdoes it a bit, you could also just do

sapply(dd[nm], function(x) kruskal.test(x~treatment)$p.value)

and lose the eval(bquote(....)) mess, but I was looking for a way to loop over the model formulas, so that you don't get all response variables called "x" if you retain the full output.)

> 
> On Wed, Nov 12, 2008 at 11:15 AM,  <lave0083_at_umn.edu> wrote:

>> Hi all,
>> I am performing hundreds of kruskal wallis tests and trying to figure out
>> how to create a file of the p.values I obtain.
>>
>> This is the code I use for the tests:
>> A2<-kruskal.test(X2~treatment)
>> A3<-kruskal.test(X3~treatment)
>> A4<-kruskal.test(X4~treatment)
>> A5<-kruskal.test(X5~treatment)
>> A6<-kruskal.test(X6~treatment)
>> A7<-kruskal.test(X7~treatment)
>> A8<-kruskal.test(X8~treatment)
>> A9<-kruskal.test(X9~treatment)
>> ect
>>
>> and I can get the p values from each one individually by:
>> A2$"p.value"
>>
>> I was hoping to figure out how to make one list of all of the p values I
>> need without having to type each one seperately
>>
>> I tried
>>> list1<-list(A1$"p.value":A3$"p.value")
>>> list1
>> [[1]]
>> [1] 0.8419078
>> but you see this only gives me the first p-value when I was trying to get 3.
>>
>> I also tried
>>> list1<-list(A1$"p.value", A2$"p.value")
>>> list1
>> [[1]]
>> [1] 0.8419078
>>
>> [[2]]
>> [1] 0.1127509
>>
>> and this works but I would have to type them all out.
>> If anyone is aware of a shortcut that would be helpful. Thanks
>>
>> ______________________________________________
>> 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.
>>
> 
> 
> 


-- 
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard_at_biostat.ku.dk)              FAX: (+45) 35327907

______________________________________________
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 Wed 12 Nov 2008 - 16:51:33 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 Wed 12 Nov 2008 - 17:30:25 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