[R] by group testing

Joshua Wiley jwiley.psych at gmail.com
Wed Aug 4 19:17:46 CEST 2010


Hello,

This will put the results of the Fisher test in a list, with each
element of the list being the results for mouse type a, b, c, and d.

mice <- rep(letters[1:4],10)
outcome <- sample(c(0,1),length(mice),replace=T)
group <- c(rep("A",length(mice)/2),rep("B",length(mice)/2))

my.data <- data.frame(mice,outcome,group)

results <- lapply(split(x = my.data, f = my.data$mice), function(dat) {
  fisher.test(x = dat[, "outcome"], y = dat[, "group"])
})

results$a #mouse type a
results$b #b, etc.

Cheers,

Josh

On Wed, Aug 4, 2010 at 9:27 AM, cheba meier <cheba.meier at googlemail.com> wrote:
> Hello,
>
> I have a data set which is similar to the following data
>
> mice <- rep(letters[1:4],10)
> outcome <- sample(c(0,1),length(mice),replace=T)
> group <- c(rep("A",length(mice)/2),rep("B",length(mice)/2))
>
> my.data <- data.frame(mice,outcome,group)
> my.sort.data <- my.data[order(my.data[,1]),]
>
> I would like to test wether there is a different between group A and B for
> each mause type!
>
> I was trying to use by, table and fisher.test/prop.test functions to do
> this, but I could not solve this problem, any suggestion?
>
> Many thanks in advance,
> Cheba
>
>        [[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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list