kurt Zhao
2007-Aug-29 20:53 UTC
[R] a new-bie question about obtaining certain value from the print out
Hi everyone, I am quite new to R. my command is t.test(c(1:5,7:11), y=c(1:10),alternative = c("two.sided"), paired = TRUE) The output is Paired t-test data: c(1:5, 7:11) and c(1:10) t = 3, df = 9, p-value = 0.01496 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 0.1229738 0.8770262 sample estimates: mean of the differences 0.5 According to the reference: Value A list with class "htest" containing the following components: p.value the p-value for the test. How can I get only the p.value as the output instead of the whole print out? Thanks a lot! -Kurt
Greg Snow
2007-Aug-29 21:22 UTC
[R] a new-bie question about obtaining certain value from the printout
You need to save the output in order to do something with it (the default if you don't save the output is to call the print method, so what you are seeing is the results of calling print.htest on the return value from t.test). Save the output by doing something like:> out <- t.test(c(1:5,7:11), y=c(1:10),+ alternative = c("two.sided"), paired = TRUE) Now the results are stored in "out" (or whatever better name you come up with) To access the p-value you can do:> out$p.valueOr use that in another expression. The details on what comes after the '$' can be found in this case from the t.test help page, or in general using the str function:> str(out)Gives a wealth of information (sometimes too much) on the components of the returned object. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of kurt Zhao > Sent: Wednesday, August 29, 2007 2:53 PM > To: r-help at stat.math.ethz.ch > Subject: [R] a new-bie question about obtaining certain value > from the printout > > Hi everyone, > > I am quite new to R. > > my command is > t.test(c(1:5,7:11), y=c(1:10),alternative = c("two.sided"), > paired = TRUE) > > The output is > > Paired t-test > > data: c(1:5, 7:11) and c(1:10) > t = 3, df = 9, p-value = 0.01496 > alternative hypothesis: true difference in means is not equal to 0 > 95 percent confidence interval: > 0.1229738 0.8770262 > sample estimates: > mean of the differences > 0.5 > According to the reference: > > Value > A list with class "htest" containing the following components: > p.value the p-value for the test. > > How can I get only the p.value as the output instead of the > whole print out? > > Thanks a lot! > > -Kurt > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
Rolf Turner
2007-Aug-29 21:31 UTC
[R] a new-bie question about obtaining certain value from the print out
On 30/08/2007, at 8:53 AM, kurt Zhao wrote:> Hi everyone, > > I am quite new to R. > > my command is > t.test(c(1:5,7:11), y=c(1:10),alternative = c("two.sided"), paired > = TRUE) > > The output is > > Paired t-test > > data: c(1:5, 7:11) and c(1:10) > t = 3, df = 9, p-value = 0.01496 > alternative hypothesis: true difference in means is not equal to 0 > 95 percent confidence interval: > 0.1229738 0.8770262 > sample estimates: > mean of the differences > 0.5 > According to the reference: > > Value > A list with class "htest" containing the following components: > p.value the p-value for the test. > > How can I get only the p.value as the output instead of the whole > print out?t.test(c(1:5,7:11), y=c(1:10),alternative = c("two.sided"), paired = TRUE)$p.value Or: rslt <- t.test(c(1:5,7:11), y=c(1:10),alternative = c("two.sided"), paired = TRUE) rslt$p.value Look at names(rslt) and/or str(rstl) to see what else you can dig out. A side-comment: You ***do not need*** the c() wrappers for 1:10 and "two.sided"; the c() function is for ``combine'' or ``catenate''. You don't need to ``combine'' a single item! The wrapper does no harm, but it's a waste of key strokes and indicates a certain lack of insight which *could* do harm in more complex situations. cheers, Rolf Turner ###################################################################### Attention:\ This e-mail message is privileged and confidenti...{{dropped}}