[R] ttest in R

0 views
Skip to first unread message

1Rnwb

unread,
Mar 7, 2009, 2:23:10 PM3/7/09
to r-h...@r-project.org

Dear list,

i am a biologist who needs to do some ttest between disease and non disease,
sex, genotype and the serum levels of proteins on a large number of
individuals. i have been using excel for a long time but it is very tedious
and time consuming. i am posting the data below and ask your help in
generating a code to get this analysis done in R. thanks

gender disease genotype data
M N CC 3.206447188
F N CC 8.2
M N CC 15.78908629
M N CC 21.14311843
F N CC 21.48413647
M N CC 30.08028842
M N CC 30.11455009
F N CC 32.41258845
F N CT 6622.253065
M N CT 6763.6
M N CT 7342.023209
F N CT 7617.7
F N CT 7857.3
M N CT 8027.78692
F N CT 8755.950438
M N CT 9007.7
F N CT 9157.76987
M N CT 9398.270953
F N CT 9710.083037
F N CT 9896.887277
M N CT 10082.60082
F N CT 10137.05244
F N CT 10350.76186
M N CT 14629.34508
F N TT 4.614829254
F N TT 5.223593964
F N TT 6.7
M N TT 6.7
M N TT 7.735287229
F N TT 13.68084134
F N TT 14.5
M N TT 15.3
M N TT 16.16826703
M N TT 19.8
M N TT 24.51271254
M N TT 29.92459383
F N TT 30.3993842
M N TT 30.57161207
F N TT 30.72031553
F N TT 31.8
F N TT 34.72409961
M N TT 37
F N TT 38.94507607
M N TT 39.1
M N TT 40.9
M N TT 41.5
F N TT 42.36614019
F Y CC 338.2166757
M Y CC 345.8711007
M Y CC 347.4659528
F Y CC 356.3
F Y CC 358.4
F Y CC 360.184259
F Y CC 453.8
F Y CC 573.7342373
M Y CC 962.1232959
F Y CC 1055.9
F Y CC 1309.532621
F Y CC 2798.6
F Y CC 3568.794326
M Y CT 1.227348206
F Y CT 2.061944986
F Y CT 2.245592643
M Y CT 2.454696412
M Y CT 2.456716738
M Y CT 4.318447391
M Y CT 4.503098245
M Y CT 5.873088452
M Y CT 7.106930564
F Y CT 7.7
M Y CT 10.83537709
M Y CT 11.4
M Y CT 12.1
M Y CT 12.62002743
M Y CT 13.6
F Y CT 13.7
F Y CT 14.35562171
F Y CT 15.9
F Y TT 986.6755719
F Y TT 1206.475083
F Y TT 1237.9
M Y TT 1254.5
F Y TT 1303.6
F Y TT 1573.915019
M Y TT 1756.8
M Y TT 1895
M Y TT 2126.766565
F Y TT 2149.512866
M Y TT 3249.449945
F Y TT 6999.3
M Y TT 7172.479241
M Y TT 8268.909251
M Y TT 8544.229671

--
View this message in context: http://www.nabble.com/ttest-in-R-tp22390889p22390889.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-h...@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.

Tal Galili

unread,
Mar 7, 2009, 4:51:08 PM3/7/09
to 1Rnwb, r-h...@r-project.org
Hello friend.

I believe anova might be a better solution for you.
You might have a look here:
http://www.personality-project.org/r/r.anova.html

A simple R session that will work for you is:

# getting the data in:
data1 <- read.table( "enter the path of the file here, look at ?read.table
for exact syntax)

aov1 <- aov(data ~ gender + disease + genotype ,data = data1)
summary(aov1)


If you insist on t.test, here is the way:
t.test(data ~ gender ,data = data1)
t.test(data ~ disease ,data = data1)
t.test(data ~ genotype ,data = data1)


Cheers,
Tal

--
----------------------------------------------


My contact information:
Tal Galili
Phone number: 972-50-3373767
FaceBook: Tal Galili
My Blogs:
www.talgalili.com
www.biostatistics.co.il

[[alternative HTML version deleted]]

Tal Galili

unread,
Mar 7, 2009, 5:04:17 PM3/7/09
to 1Rnwb, r-h...@r-project.org
p.s: since the "data" (Y variable) is very much not normal (also after a log
transform)I would consider going with an a-parametric test
check:
? wilcox.test
(for a non parametric t.test )
OR
(for a non parametric simple anova)
?kruskal.test

1Rnwb

unread,
Mar 8, 2009, 1:41:36 PM3/8/09
to r-h...@r-project.org

Thanks for the help, but ANOVA will give me a single pvalue, then how i can
make sure which group is showing the significant differences.

--
View this message in context: http://www.nabble.com/ttest-in-R-tp22390889p22400624.html

Thomas Petzoldt

unread,
Mar 8, 2009, 2:23:35 PM3/8/09
to 1Rnwb, r-h...@r-project.org
1Rnwb schrieb:

> Thanks for the help, but ANOVA will give me a single pvalue, then how i can
> make sure which group is showing the significant differences.

Hi,

ANOVA is fine and please have a look on ?TukeyHSD and don't forget to
consult your statistics textbook about post-hoc testing. If you insist
in using t.test, don't forget Bonferroni or Holm-correction (in R:
?p.adjust) or use ?pairwise.t.test !!!

ThPe

1Rnwb

unread,
Mar 8, 2009, 2:45:43 PM3/8/09
to r-h...@r-project.org

since the estimation is not done pairwise so i cannot use pairwise.t.test,
how do i apply tukeyHSD

--
View this message in context: http://www.nabble.com/ttest-in-R-tp22390889p22401372.html


Sent from the R help mailing list archive at Nabble.com.

______________________________________________

Thomas Petzoldt

unread,
Mar 8, 2009, 3:27:43 PM3/8/09
to 1Rnwb, r-h...@r-project.org
1Rnwb wrote:
> since the estimation is not done pairwise so i cannot use pairwise.t.test,
> how do i apply tukeyHSD

Note correct capitalization: TukeyHSD and follow the examples on the
help page:

?TukeyHSD

You may also contact a statistics textbook. In addition I send you some
links off list.

Reply all
Reply to author
Forward
0 new messages