Path: news.mathworks.com!not-for-mail
From: "Tom Lane" <tlane@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: p-values
Date: Mon, 2 Nov 2009 17:15:53 -0500
Organization: The MathWorks, Inc
Lines: 31
Message-ID: <hcnlmp$o19$1@fred.mathworks.com>
References: <f5889743-7afb-4534-ae77-66c0026c0ce2@c3g2000yqd.googlegroups.com>
Reply-To: "Tom Lane" <tlane@mathworks.com>
NNTP-Posting-Host: lanet.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1257200153 24617 172.31.57.151 (2 Nov 2009 22:15:53 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 2 Nov 2009 22:15:53 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5843
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:581920


> I have 2 random variables x and y. I calculate the correlation between
> x and y. Then I permute y a 1000 times and compute the correlation
> each time between x and permuted y (bootstrap approach). Could anyone
> suggest how to compute the p-values from this??

Well, the corr (Statistics Toolbox) and corrcoef (MATLAB) functions will 
compute p-values for you:

>> x = randn(10,1);
>> y = .6*x + randn(size(x));
>> [r,p] = corr(x,y)
r =
    0.7564
p =
    0.0114

But if you want to do this by simulation, notice that if the y values are 
permuted randomly, there should be no correlation with x. This gives you a 
random set of sample correlations with a distribution under the null 
hypothesis of no correlation. You could just see what proportion of them 
exceed the actual correlation you measured for your data:

>> rv = zeros(1000,1);
>> for j=1:1000; rv(j) = corr(x,y(randperm(numel(y)))); end
>> mean(abs(rv)>.7564)
ans =
    0.0110

-- Tom