フィルターのクリア

Dealing with NaNs in corr function (upper/lower triangles of matrices with same dimension)

2 ビュー (過去 30 日間)
The correlation coeficients of the upper and lower parts of matrices A,B (see attachment) yield "NaNs
nn=374;
temp= ~eye (nn);
ii_all_conn = find(temp>0);
ii_uptri_conn = find(triu(temp,1)> 0);
ii_lotri_conn = find(tril(temp,-1)> 0);
% Corr plots up entries
figure, plot(A(ii_uptri_conn), B(ii_uptri_conn),'o'), grid on, xlabel('A'), ylabel('B');
[r,p]= corr(A(ii_uptri_conn), B(ii_uptri_conn));
title(['Upper connections - r = ' num2str(r) ' (p ' num2str(p) ')']);
%Corr plots low entries
figure, plot(A(ii_lotri_conn), B(ii_lotri_conn),'o'), grid on, xlabel('A'), ylabel('B');
[r,p]= corr(A(ii_lotri_conn), B(ii_lotri_conn));
title(['Lower connections - r = ' num2str(r) ' (p ' num2str(p) ')']);
How can I modify the code to skip the NaN values in both matrices?
My code works (i.e., it yields person and p-values) when matrices A,B do not have NaNs.

採用された回答

the cyclist
the cyclist 2023 年 11 月 7 日
The documentation page for the corr function describes how to use the "Row" name-value parameter to decide how to deal with missing data.
  2 件のコメント
julian gaviria
julian gaviria 2023 年 11 月 14 日
編集済み: the cyclist 2023 年 11 月 14 日
As simple as adding 'pairwise'
[r,p]= corr(A(ii_uptri_conn), B(ii_uptri_conn),'rows', 'pairwise');
the cyclist
the cyclist 2023 年 11 月 14 日
always nice when there is a simple solution

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by