How to calculate the covariance and correlation among variables and principal components.

2 次查看(过去 30 天)
When i was doing the PCA analysis, i wanna calculate the covariance and correlations among variables and principal components to see which variables are important based on this correlation matrix?
I don't know how to do that.

回答(1 个)

Amish
Amish 2024-10-8
Hi Huan,
I see that you want to perform a PCA analysis and calculate the covariance and correlations among principal components.
This can be performed using existing functionalities in-built in the MATLAB. Here is a generic example (using a random sample set) highlighting how you can do the same:
% Example Data
X = randn(100, 5);
X_standardized = zscore(X);
% PCA
[coeff, score, latent, ~, explained] = pca(X_standardized);
% Covariance and Correlation with PCs
covMatrix = cov(X_standardized);
corrMatrix = corr(X_standardized);
correlationWithPCs = coeff .* sqrt(latent)';
disp('Covariance Matrix:');
disp(covMatrix);
disp('Correlation Matrix:');
disp(corrMatrix);
disp('Correlation with Principal Components:');
disp(correlationWithPCs);
The documentation for the functions mentioned in the above sample can be referred to using the 'doc' command or through the following links:
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Dimensionality Reduction and Feature Extraction 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by