[R] md.pattern ('mice') failure with more than 31 variables
jwiley.psych at gmail.com
Tue Nov 29 11:35:12 CET 2011
On Tue, Nov 29, 2011 at 1:58 AM, <saschaview at gmail.com> wrote:
> How come that the function md.pattern() from package 'mice' delivers a
> warning when run over data sets with more than 31 variables?
Because 2^31 is too large of a value to be represented as an integer.
The 15th line of md.pattern has the code:
mdp <- as.integer((r %*% (2^((1:ncol(x)) - 1))) + 1)
when ncol(x) > 31, 32+ - 1 = 31+, and
returns NA and gives the warning you see. Technically, the warning
does not occur at the 2^... part, it is when the results are converted
to integer, so if there were no missing values, r (a 0/1 matrix
indicating whether a particular cell is missing) would be all zeros,
and thus r %*% potentially larger value than 2^30 = 0, and you do not
get any warnings.
Aside from some storage inefficiency for < 31 columns, I do not see
any harm from from simply removing the conversion to integer. For <
31 columns, the function appears to give equal results with or without
the conversion, but for > 31 columns, some patterns are not included
when as.integer is used.
> library( 'mice' )
> x <- as.data.frame(
> sample( c(1:3, 1:3, 1:3, NA), 7000, repl=TRUE ),
> paste('V', 11:45, sep="")
> md.pattern(x) # Warning message: In md.pattern(x) : NAs introduced by
> md.pattern(x[, 1:31]) # fine
> Thanks, *S*
> Sascha Vieweg, saschaview at gmail.com
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
More information about the R-help