[R] Calculating signicance value

Ben Bolker bolker at ufl.edu
Sat Jan 3 18:49:45 CET 2009


Moumita Das <das.moumita.online <at> gmail.com> writes:

 [snip snip snip]

> But how do i get significance of
> e say:--
> recmeanC1&recmeanC2 or say recmeanC1 & i1.
> I can add this in my corr function shown above but:----
> 
> #Finding out significance of the two items whose correlations are being
> found
> sig_value<-cor.test(corr_dataset)
> and also return that :-
> return(list(matrix=BPcor,sig=sig_value))
> 
>  For example recmeanC1 and i1 has to be passed here..as 2 separate
> dataframes,shown below if i pass the dataset for (recmeanC1 & i1 ) as as
> single datframe,cor.test() function doesn't accept it.Moreover cor()
> function took care of what will be crossed with what and the correlation
> produced.Now do i have to manually get possible pairs of the column names of
> my dataset(shown above dataset 1),and also the data and then pass to
> cor.test and calculate the significance.
> Isn't there any easier way to do this,with minimum number of lines of
> code.Because I am dealing with huge datasets.

  Take a look at stats:::cor.test.default .  It's pretty
long and complicated but most of the complication is for
dealing with different correlations (i.e., other than Pearson),
and the key lines for your purposes are:

r <- cor(x, y)
df <- n - 2
ESTIMATE <- c(cor = r)
PARAMETER <- c(df = df)
STATISTIC <- c(t = sqrt(df) * r/sqrt(1 - r^2))
p <- pt(STATISTIC, df)

  You can incorporate this in your function.
(I'm assuming you're not treating these computed values
as actual probabilities of observing the data given
the null hypothesis, since there is a huge multiple testing
issue ...)

 good luck
   Ben Bolker




More information about the R-help mailing list