Created
September 18, 2012 04:36
-
-
Save jstray/3741280 to your computer and use it in GitHub Desktop.
Distance function computation for UK House of Lords voting analysis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -------------------------------- Compute distances ------------------------------ | |
# distance function = 1 - fraction of votes where both voted, and both voted the same | |
votedist <- function(v1, v2) { | |
overlap = v1!=0 & v2!=0 | |
numoverlap = sum(overlap) | |
match = overlap & v1==v2 | |
nummatch = sum(match) | |
if (!numoverlap) | |
dist = 1 | |
else | |
#dist = 1- ((nummatch/numoverlap) * log(numoverlap)/log(Nvotes)) | |
dist = 1- (nummatch/numoverlap) | |
dist | |
} | |
# create distance matrix | |
d = dist(recentvotes, votedist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment