title: Testing for MCAR using TestMCARNormality
body: <p>I have a DF (dfNA) that contains a small amount of missing data in each column. This data frame is a subset of a larger data frame (wideRawDF) for which I want to impute the missing values of. </p>
  
  <p>In order to impute the data, I need to determine whether the data is missing MCAR/NMAR/MAR so that I can apply the right imputation method.</p>
  
  <p>colsNA is a character string of the columns which contain NA values, it was derived as follows:</p>
  
  <pre><code>colsNA &lt;- colnames(wideRawDF)[colSums(is.na(wideRawDF)) &gt; 0]
  
   &gt; str(colsNA)
   chr [1:9] "DO0182U09A3" "DO0182U09B3" "DO0182U09C3" "DO0182U21A1" "DO0182U21A2" "DO0182U21A3" "DO0182U21B1" ...
  </code></pre>
  
  <p>In order to simplify and better understand why I was getting an error with TestMCARNormality I decided to pass just the columns with NA values and not the ones containing complete values. </p>
  
  <p>I subsetted wideRawDF as follows:</p>
  
  <pre><code>dfNA &lt;- wideRawDF[colsNA]
  </code></pre>
  
  <p><code>TestMCARNormality</code> is a function that tests whether the missing data is MCAR.</p>
  
  <p>Using this function I am getting the following error when I pass dfNA to it: </p>
  
  <pre><code>R&gt; library("MissMech")
  R&gt; TestMCARNormality(dfNA)
  Warning: More than one missing data pattern should be present.
  Error in TestMCARNormality(dfNA) :
  </code></pre>
  
  <p>I can't figure out what the error is referring to since my data frame has missing values within it:</p>
  
  <pre><code>&gt; apply(dfNA, 2, function(x) any(is.na(x)))
  DO0182U09A3 DO0182U09B3 DO0182U09C3 DO0182U21A1 DO0182U21A2 DO0182U21A3 DO0182U21B1 DO0182U21B2 DO0182U21B3 
         TRUE        TRUE        TRUE        TRUE        TRUE        TRUE        TRUE        TRUE        TRUE
  </code></pre>
  
  <p>My data frame also has numerical data in it:</p>
  
  <pre><code>&gt; str(dfNA)
  'data.frame':   1343 obs. of  9 variables:
   $ DO0182U09A3: num  -102 -101 -101 -101 -101 ...
   $ DO0182U09B3: num  -103.4 -102.8 -103.3 -95.9 -103 ...
   $ DO0182U09C3: num  -103.9 -104.2 -103.9 -99.2 -104.1 ...
   $ DO0182U21A1: num  -105 -105 -105 -104 -102 ...
   $ DO0182U21A2: num  -105 -104 -105 -105 -105 ...
   $ DO0182U21A3: num  -105 -105 -105 -105 -105 ...
   $ DO0182U21B1: num  -102 -103 -104 -104 -104 ...
   $ DO0182U21B2: num  -99.4 -102 -104 -101.4 -104.1 ...
   $ DO0182U21B3: num  -104 -104 -104 -104 -104 ...
  </code></pre>
  
  <p>I've googled the error and found the source code at this <a href="https://rdrr.io/cran/MissMech/src/R/TestMCARNormality.R" rel="nofollow noreferrer">page</a> but I am not a strong programmer and struggle to understand it. Any help in getting to the bottom of this would be greatly appreciated.</p>
  
  <p>Below is a dput() output of the files I am using. </p>
  
  <p><a href="https://drive.google.com/file/d/0BzkBEqPfozOOOHRYLUljcE5BR0U/view?usp=sharing" rel="nofollow noreferrer">wideRawDF</a> <strong>This is the original DF with columns containing both missing and complete values</strong></p>
  
  <p><a href="https://drive.google.com/open?id=0BzkBEqPfozOOU21CVmh5eW1WaDg" rel="nofollow noreferrer">colsNA</a> <strong>This is a character string of columns with NA values in them</strong></p>
  
  <p><a href="https://drive.google.com/open?id=0BzkBEqPfozOOVTdIeXJvSEZaaUk" rel="nofollow noreferrer">dfNA</a> <strong>is a subset DF of columns with NA values in them</strong></p>