title: Multivariate K-S test in R
body: <p>So we can run a K-S test to assess if we have a difference in the distribution of dtwo datasets, as outlined <a href="https://en.wikipedia.org/wiki/Kolmogorov%E2%80%93Smirnov_test" rel="nofollow">here</a>.</p>
  
  <p>So lets take the following data</p>
  
  <pre><code>set.seed(123)
  N &lt;- 1000
  var1 &lt;- runif(N, min=0, max=0.5)
  var2 &lt;- runif(N, min=0.3, max=0.7)
  var3 &lt;- rbinom(n=N, size=1, prob = 0.45)
  
  df &lt;- data.frame(var1, var2, var3)
  </code></pre>
  
  <p>We can then seperate based on var3 outcome</p>
  
  <pre><code>df.1 &lt;- subset(df, var3 == 1)
  df.2 &lt;- subset(df, var3 == 0)
  </code></pre>
  
  <p>Now we can run a Kolmogorov–Smirnov test to test for differences in the distributions of each individual variable.</p>
  
  <pre><code>ks.test(jitter(df.1$var1), jitter(df.2$var1))
  ks.test(jitter(df.1$var2), jitter(df.2$var2))
  </code></pre>
  
  <p>And not suprisngly, we do not get a difference and can assume the different dataset have been drawn from the same distribution. This can be visualised through:</p>
  
  <pre><code>plot(ecdf(df.1$var1), col=2)
  lines(ecdf(df.2$var1))
  
  plot(ecdf(df.1$var2), col=3)
  lines(ecdf(df.2$var2), col=4)
  </code></pre>
  
  <p>But now we want to consider if the distributions between <code>var3==0</code> and <code>var3==1</code> differ when we consider both <code>var1</code> &amp; <code>var2</code> together.
  <strong>Is there an R package to run such a test when we have a multiple predictors</strong></p>
  
  <p>The similar question was posed <a href="http://www.inside-r.org/questions/multivariate-kolmogorov-smirnov-distance-r" rel="nofollow">here</a>, but has not received any answers</p>
  
  <p>There appears to be some literature:
  <a href="http://v-scheiner.brunel.ac.uk/bitstream/2438/1166/1/acat2007.pdf" rel="nofollow">Example 1</a>
  <a href="http://halweb.uc3m.es/esp/Personal/personas/dpena/articles/kolpl97.pdf" rel="nofollow">Example 2</a></p>
  
  <p>But nothing appears to be linked to R</p>