Add variable vectors to NMDS plot which visualizes observations.

8 ビュー (過去 30 日間)
Sierra Cagle
Sierra Cagle 2025 年 1 月 10 日
回答済み: Shantanu Dixit 2025 年 1 月 13 日
I'm not sure how to add vectors that visualize the effect of data set parameters to an NMDS plot.
Using the example provided by matlab for function mdscale (shown below), I can create the figure with points for each observation (i.e. cerials of a certain brand). How would I go about adding vectors to the plot for each of the parameters included in the analysis, where the length of the vector indicates the strength of effect on the ordination. For the cerial example, these vectors would represent calories, protien, fat, sodium, fiber, carbo, sugars, shelf, potass, and vitamins. If you could show my how to do this in the sample below, that would be really helpful!
load cereal.mat
X = [Calories Protein Fat Sodium Fiber ...
Carbo Sugars Shelf Potass Vitamins];
% Take a subset from a single manufacturer
mfg1 = strcmp('G',cellstr(Mfg));
X = X(mfg1,:);
dissimilarities = pdist(zscore(X),'cityblock');
[Y,stress] =...
mdscale(dissimilarities,2,'criterion','stress');
plot(Y(:,1),Y(:,2),'o','LineWidth',2);
gname(Name(mfg1))

回答 (1 件)

Shantanu Dixit
Shantanu Dixit 2025 年 1 月 13 日
Hi Sierra,
To add vectors to the NMDS plot that visualize the effect of dataset parameters, you can compute correlations between the parameters and the ordination coordinates. These correlations indicate the strength and direction of each parameter's influence on the ordination.
  1. Standardize the data: Use "zscore(X)" to normalize the dataset.
  2. Compute correlations: Calculate correlations between the standardized dataset and the NMDS coordinates "Y" using "corr(zscore(X), Y)".
  3. Plot vectors: Use "quiver" to add arrows originating from the origin (0,0) with directions and lengths based on the computed correlations.
Below is a sample implementation to achieve this
load cereal.mat
X = [Calories Protein Fat Sodium Fiber Carbo Sugars Shelf Potass Vitamins];
mfg1 = strcmp('G',cellstr(Mfg));
X = X(mfg1,:);
dissimilarities = pdist(zscore(X),'cityblock'); %% n by n dissimilarity matrix
[Y,stress] = mdscale(dissimilarities,2,'criterion','stress');
plot(Y(:,1),Y(:,2),'o','LineWidth',2);
hold on;
% Calculate correlations between original variables and the MDS coordinates
correlations = corr(zscore(X), Y);
% Loop through each parameter to plot its vector
for i = 1:size(X, 2)
% Use the correlation to scale the vectors
quiver(0, 0, correlations(i,1), correlations(i,2), ...
'MaxHeadSize', 0.1, 'LineWidth', 2, 'Color', 'r');
end
Additionally you can refer to the following useful MathWorks documentation
Hope this helps!

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by