Francesca Pancotto wrote on 09/28/2011 10:23:17 AM:
> 
> Dear Contributors
> I have a problem with the collection of data from the results of a test.
> I need to perform a comparative test over groups of data , recall the 
value
> of the pvalue and create a table.
> My problem is in the way to replicate the analysis over and over again 
over
> subsets of data according to a condition.
> I have this database, called y:
> gg       t1     t2        d
>  40      1      1         2
>  50     2       2         1
>  45     1       3         1
>  49     2       1         1
>  5       2       1         3
>  40     1       1         2
> 
> where gg takes values from 1 to 100, t1 and t2 have values in (1,2,3) 
and d
> in (0,1,2,3)
> I want to perform tests on the values of gg according to the conditions 
that
> 
> d==0 , compare values of gg when t1==1 with values of gg when t1==3
> d==1 , compare values of gg when t1==1 with values of gg when t1==3
> d==2 , compare values of gg when t1==1 with values of gg when t1==3
> ..
> then
> d==0 , compare values of gg when t2==1 with values of gg when t2==3
> d==1...
> 
> 
> then collect the data of a statistics and create a table.
> The procedure i followed is to create sub datasets called m0,m1,m2,m3
> corresponding
> to the values of d, i.e.
> 
> m0<- y[y$d==0,c(7,17,18,19)]
> m1<- y[y$d==1,c(7,17,18,19)]
> m2<- y[y$d==2,c(7,17,18,19)]
> m3<- y[y$d==3,c(7,17,18,19)]
> 
> then perform the test as follows:
> 
> x1<-wilcox.test(m0[m0$t1==1,1],m0[m0$t1==3,1],correct=FALSE, 
exact=FALSE,
> conf.int=TRUE,alternative = c("g"))   #ABC   ID
> x2<-  wilcox.test(m1[m1$t1==1,1],m1[m1$t1==3,1],correct=FALSE, 
exact=FALSE,
> conf.int=TRUE,alternative = c("g"))
>  x3<-  wilcox.test(m2[m2$t1==1,1],m2[m2$t1==3,1],correct=FALSE, 
exact=FALSE,
> conf.int=TRUE,alternative = c("g"))
> x4<- wilcox.test(m3[m3$t1==1,1],m3[m3$t1==3,1],correct=FALSE, 
exact=FALSE,
> conf.int=TRUE,alternative = c("g"))
> 
> each of these tests will create an object, say x and then I extract the
> value statistics using
> x$statistics.
> 
> How to automatize this?
> Thank you for any help you can provide.
> Francesca


y <- data.frame(gg=sample(100), t1=sample(1:3, 100, TRUE), 
        t2=sample(1:3, 100, TRUE), d=sample(0:3, 100, TRUE))

yd <- split(y, y$d)

sapply(yd, function(df)
        wilcox.test(df[df$t1==1, 1], df[df$t1==3, 1], correct=FALSE, 
                exact=FALSE, conf.int=TRUE, alternative="g")[c("estimate", 
"p.value")])

sapply(yd, function(df)
        wilcox.test(df[df$t2==1, 1], df[df$t2==3, 1], correct=FALSE, 
                exact=FALSE, conf.int=TRUE, alternative="g")[c("estimate", 
"p.value")])

Jean
        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to