1
votes

if I have two series of data: a = [1 4 6 3 4 6 7 8]; b [34 56 34 56 79 23 48 28]; Then i can find the spearman and pearson correlation coefficient respectively as: RHO= corr(a',b','Type','Spearman'); for pearson correlation, i can use: r=corr2(a,b) or

[R] = corr(a',b','Type','pearson')

what will be the confidence level (95% and 99%) both for pearson and spearman correlation. i need result as in the given example. let,

pearson correlation r=0.76

spearman rank correlation r=0.65

95% confidence level=0.34

99% confidence level=0.42

Note: My values of correlation coefficients and confidence level are general, they are not for given 'a' and 'b' values above. thanks.

1

1 Answers

0
votes

You can use corrcoef for that. For confidence interval of 95% write:

[R,~,RL,RU] = corrcoef(a.',b.')

And for other confidence intervals, add the alpha (CI = 100*(1-alpha)%):

[R,~,RL,RU] = corrcoef(a.',b.','alpha',0.01)

RL and RU are the lower and upper bounds, respectively, of the correlation.

EDIT:

For spearman correlation confidence interval you need fisher transformation, which is arctanh(r):

RHO = corr(a.',b.','Type','Spearman');
n = numel(a);
STE = 1/sqrt(n-3);
% here the input is 95% confidence interval, for 99% use 0.99:
CI = norminv(0.95); 
upper_bound = tanh(atanh(RHO)+CI*STE);
lower_bound = tanh(atanh(RHO)-CI*STE);