Error when simulating correlated binary variables in R with rmvbin

By Canovice

I am building a model in hindsight that predicts the 2016 US presidential election, and am tackling the issue of correlations between states. To do this I am using the function rmvbin() from the bindata library. Here is a subset of the data that I am working with:

cor.mtx = structure(c(1, 0.755, 0.575, 0.548, 0.755, 1, 0.834, 0.816, 0.575,
                        0.834, 1, 0.892, 0.548, 0.816, 0.892, 1), .Dim = c(4L, 4L), .Dimnames = list(c("alabama", "florida", "michigan", "wisconsin"),
                  c("alabama", "florida", "michigan", "wisconsin")))
marg.vals = c(0.001, 0.629, 0.921, 0.953)

The data above should be interpreted in the following way:

  • marg.vals has 1 candidates chances of winning each state. 0.001 chance to win alabama, 0.629 chance to win florida, etc.
  • cor.mtx is a correlation matrix for the states. Given that I want to generate random, correlated binary values, these correlations are important. We see here that the correlation between michigan and wisconsin is quite high, at 0.892.

Next I use the rmvbin function, with the margprob and bincorr parameters, to simulate the outcomes of the states:

library(bindata)
cor.mtx
rmvbin(10, margprob = marg.vals, bincorr = cor.mtx)
Error in Element ( 1 , 2 ): Admissible values are in [ 0 , 0.001 ].
Error in Element ( 1 , 3 ): Admissible values are in [ 0 , 0.001 ].
Error in Element ( 1 , 4 ): Admissible values are in [ 0 , 0.001 ].
Error in Element ( 2 , 3 ): Admissible values are in [ 0.55 , 0.629 ].
Error in Element ( 2 , 4 ): Admissible values are in [ 0.582 , 0.629 ].
Error in Element ( 3 , 2 ): Admissible values are in [ 0.55 , 0.629 ].
Error in Element ( 3 , 4 ): Admissible values are in [ 0.874 , 0.921 ].
Error in commonprob2sigma(commonprob, simulvals) :
  Matrix commonprob not admissible.

I am thoroughly confused as to what is wrong with my input correlation matrix. Any help is appreciated. Thanks!

Source: Stack Overflow

    

Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273