I have 45x484 matrix but when I calculate coeff pca function, I am getting coeff with 484x44 matrix which causes errors in biplot. Why is the rows and columns switch places?

2 ビュー (過去 30 日間)
%from struct to matrix using function
T1 = createDataMatrix(REC);
x=ismissing(T1);
y=any(x,1);
z=T1(:,~y);
a=z;
% scaling data for each column using standardised Z
ZM=zscore(a);
ZM=ZM-mean(ZM);
%PCA using Matlab built-in function
[coeff,score,latent,~,explained,~]=pca(ZM);

採用された回答

Ive J
Ive J 2021 年 8 月 31 日
Well you should find the answer in your problem not MATLAB pca function. You have 45 observations with 484 variables, so degree of freedom (you already centered your variables) in your case would be 44 and that's the max number of PCs with a non zero variance. You need to look at the total variance explained and pick those PCs explaining much of the variance (let's say 90%); I highly doubt the number of PCs explaining that much of variance even exceeds half of variables in a real case situation (though I admit depends on the nature of the problem).
Bottom line: pca function works just fine.
  13 件のコメント
Ive J
Ive J 2021 年 9 月 2 日
編集済み: Ive J 2021 年 9 月 2 日
To remove only samples with missingness, you can apply something this to your dataset:
A = randn(487, 45); % raw data wish 487 observations and 45 variables
A(randi([1, numel(A(:))], 20, 1)) = nan; % add some missing values to raw data
fprintf('original matrix size: %d observations and %d features\n', size(A, 1), size(A, 2))
original matrix size: 487 observations and 45 features
nanObsIdx = any(isnan(A), 2); % samples having at least one missing value in either of features (columns)
A(nanObsIdx, :) = [];
fprintf('pruned matrix size: %d observations and %d features\n', size(A, 1), size(A, 2))
pruned matrix size: 467 observations and 45 features
Obviously this doesn't affect your features but only samples.
ack
ack 2021 年 9 月 4 日
Hi Ive, sorry for the late reply. My coding is sort of working now. Thank you so much for your inputs!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by