[R] Odp: Write function multiple tests and write summary table

ctu at bigred.unl.edu ctu at bigred.unl.edu
Tue May 27 12:44:56 CEST 2008


Hi Peter,
your method is significantly better than mine.

Amazing~
Chunhao Tu




Quoting Petr PIKAL <petr.pikal at precheza.cz>:

> Petr Pikal
> petr.pikal at precheza.cz
> 724008364, 581252140, 581252257
>
>
> r-help-bounces at r-project.org napsal dne 27.05.2008 10:52:18:
>
>> Dear R community,
>>
>> I am not experienced in writing functions and need your help to
> understand
>> the strategy to face the following problem:
>>
>> I have a group of independent numerical variables, let's say
>>
>> a<-c(1,3,2,6,9,2,2,3,4,1)
>> b<-c(2,3,3,4,5,6,2,1,1,6)
>> c<-c(0,2,4,4,7,6,7,1,2,2)
>> d<-c(0,0,0,1,0,2,1,3,1,2)
>> e<-c(9,2,3,1,1,1,0,2,5,6)
>>
>> and a grouping variable,
>>
>> group<-c
>>
> ("case","case","case",","case",","case","control","control","control","control","control")
>>
>> I want to apply a test for every variable independently and store the
>> summary result in a table
>>
>> for example
>>
>> mod1<-aov(a~group)
>> mod2<-aov(b~group)
>> .
>> .
>> .
>>  generate summary table
>>
>>
>> Any suggestions?
>
> Use lists.
>
> lll<-list(a,b,c,d,e)
> group<-factor(group)
> lapply(lll, function(x) summary(aov(x~group)))
> [[1]]
>             Df Sum Sq Mean Sq F value Pr(>F)
> group        1    8.1     8.1    1.35 0.2788
> Residuals    8   48.0     6.0
>
> [[2]]
>             Df Sum Sq Mean Sq F value Pr(>F)
> group        1    0.1     0.1   0.025 0.8783
> Residuals    8   32.0     4.0
>
> [[3]]
>             Df Sum Sq Mean Sq F value Pr(>F)
> group        1   0.10    0.10  0.0142 0.9081
> Residuals    8  56.40    7.05
>
> [[4]]
>             Df Sum Sq Mean Sq F value   Pr(>F)
> group        1   6.40    6.40  14.222 0.005456 **
> Residuals    8   3.60    0.45
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> Further improvement will be necessary because it is not clear what the
> output shall look like.
>
> Regards.
>
> Petr
>
>
>> Thank you
>>
>> Fabio
>>
>>
>>
>> --
>> Fabio Sánchez, MD, MSc, PhD
>> Unit of Dermatology and Venereology
>> Department of Medicine
>> Karolinska Institute
>> SE-17176 Karolinska University Hospital
>> Phone: +46 8 51772158
>> Fax: +46 8 51773620
>>
>>    [[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.
>
> ______________________________________________
> 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.
>
>



More information about the R-help mailing list