Re: [R] how to extract object from stats test output (cor.test)?

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Thu, 19 Jun 2008 11:49:30 -0400

On 6/19/2008 11:01 AM, Patrick Ayscue wrote:
> Hello,
>
> Is there a way to extract output objects from a stats test without viewing
> the entire output? I am trying to do so in the following:
>
> define a vector of length j
>
> for( i in 1: length (vector)) {
> vector[i] = cor.test (datavector1, datavector2[i], method=("spearman"))
> }
>
> I would like the reported Spearman's rho to be saved in a vector. I have
> tried a few different ways of doing this but seem unable to figure out how
> to get only that output without looking at each report and copying by hand.

See the Value section of the ?cor.test man page. It says that the result is a list containing (among other things) the components

statistic: the value of the test statistic.

estimate: the estimated measure of association, with name '"cor"',

           '"tau"', or '"rho"' corresponding to the method employed.

I think "estimate" is what you want, which you can get as

cor.test (datavector1, datavector2[i], method=("spearman"))$estimate

This is a numeric vector with one element named "rho", in the example on the ?cor.test page.

Duncan Murdoch

>
>
> Any help would be appreciated.
>
>
> Thanks,
> Patrick
>
> [[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. Received on Thu 19 Jun 2008 - 16:15:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 19 Jun 2008 - 16:30:43 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive