This is a straightforward implementation of Myers blended digit preference index in R.
The code depends on the dplyr
package. Please install it, before using the code.
Download myers-score.R from this repository and save it to your project's working directory. In R:
library("downloader")
download("https://raw.githubusercontent.com/chmue/myers.R/master/myers-score.R")
Then, use it with the following code:
source("myers-score.R")
myers(target_variable, target_frequency, bin_start = 0, bin_size = 40)
There are currently two unit tests, which compare the output of the function against previous results. If you clone the complete repository, you can run the unit tests with the following snippet. You need the package testthat
.
source("tests/testthat.R")
There is also a small write-up of the validation using the data from Lee & Zhang 2013 (see below.)
The code is adapted from Stata code by Germán Rodríguez available here. I also consulted the following research paper for additional guidelines and background on Myers' blended index: Melissa M. Lee and Nan Zhan (2013). The Art of Counting the Governed: Census Accuracy, Civil War, and State Presence. CDDRL Working Papers, Vol. 146. Available here.
The unit tests use two datasets made available by Germán Rodríguez on the introductory website mentioned above (phpop1990.dat and bdblci.dat) and one dataset from Lee & Zhang 1993 (Table OA2.1).
The code is available under the GNU General Public License 3 or later.