Skip to content

Instantly share code, notes, and snippets.

@jirilukavsky
Last active June 17, 2024 07:18
Show Gist options
  • Save jirilukavsky/c1e9f4aeaa9b22f81591ba6ea5ed3518 to your computer and use it in GitHub Desktop.
Save jirilukavsky/c1e9f4aeaa9b22f81591ba6ea5ed3518 to your computer and use it in GitHub Desktop.
Reconstruction of the distinctiveness measure from Murdock 1960 paper
murdock_D <- function(x, pc = T) {
n <- length(x)
mr <- matrix(x, nrow = n, ncol = n)
mc <- matrix(x, nrow = n, ncol = n, byrow = T)
md <- abs(mr - mc)
td <- rowSums(md)
dpc <- td / sum(td)
if (pc) {
# percentages or D%
return(dpc)
} else {
# total distinctiveness or TD
return(td)
}
}
# simple test case
murdock_D(1:3)
# isolated values get to 50%
murdock_D(c(0,0.1, 10))
# should be 30:20:20:30
murdock_D(c(2,4,6,8))
# should be wrong
murdock_D(1:8)
# almost correct
murdock_D(log(1:8))
# same
murdock_D(log10(1:8))
# wrong
murdock_D(log(1:9))
# random set of five
murdock_D(c(121, 202, 205, 37, 207))
# Murdock, B. B. (1960). The distinctiveness of stimuli. Psychological Review, 67(1), 16–31. https://doi.org/10.1037/h0042382
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment