Skip to content

Instantly share code, notes, and snippets.

@dweidele
Last active April 27, 2017 07:32
Show Gist options
  • Save dweidele/10561e02e5b189161a5c to your computer and use it in GitHub Desktop.
Save dweidele/10561e02e5b189161a5c to your computer and use it in GitHub Desktop.
Brainerd-Robinson Coefficient of Similarity in R
# function to load the observations
load = function() {
p <- read.csv("observations.csv")
rownames(p) <- p[,1]
p <- p[,c(2:6)]
return(p)
}
# function to compute the normalized Brainerd-Robinson similarity for observations x
BR <- function(x)
{
rd <- dim(x)[1]
results <- matrix(0,rd,rd)
for (s1 in 1:rd) {
for (s2 in 1:rd) {
results[s1,s2] <- 1 - (sum(abs(x[s1, ] / sum(x[s1,]) - x[s2, ] / sum(x[s2,]))))/2
}
}
rownames(results) <- rownames(x)
colnames(results) <- rownames(x)
return(results)
}
# load observations, compute Brainerd-Robinson similarity and write results to file
write.csv(BR(load()), "br.csv")
X x_1 x_2 x_3 x_4 x_5
A 234 123 465 384 103
B 543 100 456 394 239
C 492 203 784 134 193
D 293 674 199 948 942
E 112 342 543 384 384
F 294 234 000 113 841
@article{robinson1951method,
title={A method for chronologically ordering archaeological deposits},
author={Robinson, William S},
journal={American antiquity},
volume={16},
number={4},
pages={293--301},
year={1951},
publisher={JSTOR}
}
@article{brainerd1951place,
title={The place of chronological ordering in archaeological analysis},
author={Brainerd, George W},
journal={American antiquity},
volume={16},
number={4},
pages={301--313},
year={1951},
publisher={JSTOR}
}
@misc{weidele2015brsim,
author={Daniel Weidele},
title={{Normalized Brainerd-Robinson Similarity in R}},
year={2015},
howpublished={\url{https://gist.github.com/dweidele/10561e02e5b189161a5c}},
note={[{Online at GitHub Gist}; accessed dd.MM.yyyy]}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment