Instantly share code, notes, and snippets.

Embed
What would you like to do?
Distance function computation for UK House of Lords voting analysis
# -------------------------------- 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