bryan
bryan

Reputation: 11

visualizing a distance matrix

Sorry if there's already an answer to this. I can't seem to find it.

I'm working on an application that pulls legislators' voting records on bills, and I'm trying to come up with some interesting ways of visualizing the data. There's one idea in my head right now, but I'm not sure it's mathematically possible to do the visualization I want to in two dimensions.

The data begins like this:

       HB1 HB2 HB3 
Smith   1   0   1  
Hill    1   1   1  
Davis   0   1   0  

Where 1 = aye, 0 = nay.  

The next step I take is to measure the "distance" of each legislator from the other by summing the XORs of their voting records, so that each time one legislator disagrees with another they get a distance "point" with that legislator. That creates a table like this:

       Smith Hill  Davis
Smith    0     1     3
Hill     1     0     2
Davis    3     2     0

So my idea is to graph each legislator as a point on a plane, and to have the distances between those points reflect the distance rating in the table. I think it presents an interesting opportunity to see if there are clusters of legislators with similar voting patterns, etc.

Now, obviously, this is easy to do with 3 points since you can always draw a triangle with three given lengths for sides. But I can't figure out whether it's mathematically possible to graph lots more (35-70) legislators and still have all the distances right within a 2-dimensional space, or whether you potentially need one additional dimension with each legislator after three.

So, for example, is it possible to preserve all the distances if the data table looks like this?

    0   13    6    8   10   14   12   14   12   12
   13    0   13   13   13    7    9   11    9    7
    6   13    0   12    8   16   14   10   12   14
    8   13   12    0   12   10    6   10   10    8
   10   13    8   12    0   10   12   12   14   14
   14    7   16   10   10    0   10   10   12    8
   12    9   14    6   12   10    0   12    8   10
   14   11   10   10   12   10   12    0    8   10
   12    9   12   10   14   12    8    8    0   10
   12    7   14    8   14    8   10   10   10    0

If so, does Octave have a built-in function? or can anyone point me to an algorithm?

Upvotes: 0

Views: 545

Answers (1)

bryan
bryan

Reputation: 11

Ok, found the answer.

  1. No, it's generally not mathematically possible to do what I wanted to do.

  2. The best approximation is an algorithm called multidimensional scaling. Octave has a built-in function: cmdscale.

Hope others may find this helpful.

Upvotes: 1

Related Questions