Or if David's answer seems like too much work you could use the `mvrnorm`
function in the MASS package to generate 2 vectors with the given
correlation and sample size and feed those vectors to the `cor.test`
function.
Or Pearson's test can be computed in 1 line of R code without needing any
special functions:
pt( print( r*sqrt( (n-2)/(1-r^2) ) ), n-2, lower=FALSE )
Or a test based on simulation (parametric bootstrap) can be constructed in
a single line as well (though may be more readable and give other useful
info if spread over a few lines):
mean( replicate(100000, cor( rnorm(n),rnorm(n) )) >= r )
Which of these are actually more/less work depends on your current brand of
lazyness.
On Sun, Feb 24, 2013 at 4:12 PM, David Winsemius wrote:
>
> On Feb 24, 2013, at 1:29 PM, Martin Batholdy wrote:
>
> > Dear Miguel,
> >
> > thanks!
> > But I actually do not have two vectors but just a correlation
> coefficient and want to get the p value.
> > As far as I can see it, cor.test only works when having raw data pairs
> or am I missing something?
> >
> >
>
> You are ignoring the fact that the code is readily accessible. It first
> calculates the cor() results and then works with it using that vale and the
> numbers of cases. It doesn't seem to me that it should be at all difficult
> to modify the code to take cor() and N and return a statistic of your
> choosing.
>
> --
> David.
> > On Feb 24, 2013, at 22:24 , Miguel Manese wrote:
> >
> >> Hi Martin,
> >>
> >> See ?cor.test
> >>
> >> example(cor.test)
> >>
> >> Regards,
> >> - Jon
> >>
> >> On Mon, Feb 25, 2013 at 5:06 AM, Martin Batholdy
> >> wrote:
> >>> Hi,
> >>>
> >>> is there a predefined function that computes the p- or t-value
> >>> based on a correlation coefficient and its sample size?
> >>>
> >>>
> >>> thanks!
> >>>
> >>> ______________________________________________
> >>> R-help@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@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.
>
> David Winsemius
> Alameda, CA, USA
>
> ______________________________________________
> R-help@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.
>
--
Gregory (Greg) L. Snow Ph.D.
538280@gmail.com
[[alternative HTML version deleted]]