From: Samoline1 Linke on
Hi,

while applying the following code I get no answer. Why is that so?

if mat_corr is a matrix then:

m_corr = size(mat_corr,2);
R_corr = eye(m_corr);
for i = 1:m_corr
for j = 1:i-1
k = setdiff(1:m_corr,[i j]);
R_corr(i,j) = partialcorr(mat_corr(:,i),mat_corr(:,j),mat_corr(:,k), 'type', 'spearman'); R_corr(i,j)=R_corr(j,i);
end
end

I get 1 at the diagonal (which is correct) but always 0 at non-diagonal places (which is wrong)

Why is that so?
From: Tom Lane on
> R_corr(i,j) = partialcorr(mat_corr(:,i),mat_corr(:,j),mat_corr(:,k),
> 'type', 'spearman');
> R_corr(i,j)=R_corr(j,i);
...
> I get 1 at the diagonal (which is correct) but always 0 at non-diagonal
> places (which is wrong)
>
> Why is that so?

The answer is on the second line above.

-- Tom


From: Samoline1 Linke on
"Tom Lane" <tlane(a)mathworks.com> wrote in message <hjn9nl$lrr$1(a)fred.mathworks.com>...
> > R_corr(i,j) = partialcorr(mat_corr(:,i),mat_corr(:,j),mat_corr(:,k),
> > 'type', 'spearman');
> > R_corr(i,j)=R_corr(j,i);
> ..
> > I get 1 at the diagonal (which is correct) but always 0 at non-diagonal
> > places (which is wrong)
> >
> > Why is that so?
>
> The answer is on the second line above.
>
> -- Tom
>
#

Thanks for the reply but could you please explain but I still did not get what you mean
From: Tom Lane on
>> > R_corr(i,j) = partialcorr(mat_corr(:,i),mat_corr(:,j),mat_corr(:,k),
>> > 'type', 'spearman');
>> > R_corr(i,j)=R_corr(j,i);
>> ..
>> > I get 1 at the diagonal (which is correct) but always 0 at non-diagonal
>> > places (which is wrong)
>> >
>> > Why is that so?
>>
>> The answer is on the second line above.
>>
>> -- Tom
> #
>
> Thanks for the reply but could you please explain but I still did not get
> what you mean

On the first line you assign something to R_corr(i,j).

On the second line you immediately wipe out that value by re-assigning from
the contents of R_corr(j,i), which was initialized to zero and is still
zero. So every time you assign into an off-diagonal element of this array,
you immediately wipe out the value that you assigned.