Danielle Daidone
  • Home
  • Research
    • Publications
    • Current Research Projects
  • Teaching
  • Praat Scripts
  • Resources & Links
  • Blog

Analyzing free classification results: Visualization of MDS analyses

4/13/2026

0 Comments

 
The long awaited script for MDS visualization is finally here!  It took so long in part because I'm not great at math, and rotating the dimension scores is matrix multiplication.  Thankfully, with Ryan Lidster's help on that part, you can now plot your MDS output and rotate the points to your heart's content.

The R Markdown file is available here, and an example of its output is available in this pdf.  As you can see, MDS_visualization.Rmd takes the output files created by MDS_Analysis_new.Rmd as input, such as MDS_3D_AllContexts.txt.  It works with both 2D and 3D solutions, but make sure you pay attention to which you are choosing because there are different chunks you should run based on 2D versus 3D. 

After reading in your file, the script creates new columns from the row names.  You want columns for however you want to group your dimension scores in the figure.  In this example, we want each length template to have the same color (one color for CVCV, another for CVVCV, etc.) and each speaker to have the same shape (square for speaker N, circle for speaker L, etc.).  Since our row names are typically condition_speaker, the script separates the two based on the underscore delimiter.  If you've used another way of naming your rows, the stringr package has a lot of options for string manipulation.  Also, since the script pulls the labels from the "condition" column, you'll want to make sure your condition names are the ones you want to have in your figure (e.g., IPA symbols).  The script has an example of using stringr to find and replace condition names.

The script then uses the ggplot2 package to create the scatterplots.  This package is very versatile, and you can change essentially any part of the plot to look how you want (title, axes, colors, sizes, labels, etc.).  For example, because dimension scores are not inherently meaningful on their own, I've removed the numerical tick marks from the axes.  Here is what our first plots look like.  Since this is a 3D solution, we have both Dimension 1 by Dimension 2 and Dimension 1 by Dimension 3 (the second plot basically looking at the first plot from above).
Picture
Picture
If you don't like the orientation of the coordinates, this is where matrix rotation comes into play.  If you think of a 2D solution as dots on a flat piece of paper, if you spin the paper around, you can see them from different angles, but the distances between the dots don't change.  We can do the same in three dimensions, like turning a cube all around in your hand.  The only important thing is that we don't change the distances between points, since figuring out distances is the purpose of an MDS analysis.  

In order to do rotation, we can spin the coordinates around the x-axis, y-axis, or z-axis.  Here is a great visual example of rotating around each of these axes from ​jsfiddle.net/greggman/Lqg93y1v/. 
Picture
We tell the script to do this by inputting how much of a rotation we want in radians.  Below is a handy guide for converting angles to radians from this site.
Picture
You can put π into R as "pi", so pi/2 is a 90º rotation, pi is a 180º rotation, and (3 * pi)/2 is a 270º degree rotation.  Let's say we want to rotate our solution 90º around the z-axis.  Below is what this would look like.  As you can see in the first plot, the points have moved counterclockwise a fourth of the way around.  If you look at the updated dimension scores in the new dataframe MDS_points_rotated, you'll notice that because we're rotating around the z-axis, none of the D3 scores have changed.  In the second plot below, this means that all of the points are at the same height as in the original plot.
Picture
Picture
If you want to rotate around more than one axis, change the input of the relevant rotation chunk to the output of the previous rotation (MDS_points to MDS_rotated_points).  Here is what it would look like if we also rotated the already rotated solution 90º around the y-axis.
Picture
Picture
Use the rotations to help you understand how listeners were grouping the stimuli.  In this case, the original dimension scores are clearer, since for Dimension 1 at least, we can also see a divide with points with short V1 on the left and those with long V1 on the right.  Perhaps we would want to rotate -45º along the z-axis to make this distinction sharper.  You can also think about what makes most sense visually for your audience, such as putting /i/ in the top left corner in a study looking at vowels. 

​Once you're happy with your rotation, be sure to save the image(s) with the ggsave chunk at the bottom of the script.  There is also a chunk for saving the new dimension scores, which you can use later if you want to correlate acoustic/phonological properties with the dimension scores to find out what cues listeners were using to group the stimuli.
0 Comments

    Author

    I like sounds.  Here I'll teach you how to play with them and force other people to listen to them.  For science.

    Archives

    April 2026
    August 2023
    February 2023
    March 2022
    February 2019
    August 2017
    July 2017
    June 2017

    Categories

    All
    Creating Perception Tasks
    Free Classification

    RSS Feed

Copyright © 2026
​Danielle Daidone
​daidoned AT uncw DOT edu
You can also check out my ResearchGate page
  • Home
  • Research
    • Publications
    • Current Research Projects
  • Teaching
  • Praat Scripts
  • Resources & Links
  • Blog