Acknowledgements:
Oscar Morton and Jocelyne Sze helped with R coding.