Add variable vectors to NMDS plot which visualizes observations.

8 visualizaciones (últimos 30 días)
Sierra Cagle
Sierra Cagle el 10 de En. de 2025
Respondida: Shantanu Dixit el 13 de En. de 2025
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))

Respuestas (1)

Shantanu Dixit
Shantanu Dixit el 13 de En. de 2025
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!

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by