title: Computing Anderson-Darling test statistics for continuous distributions in R
body: <p>First of all I'm not actually sure if this belongs to CrossValidated or to StackOverflow. I'm sorry if I posted this Question on the wrong site.</p>
  
  <p>I'm comparing several datasets against an observational dataset using R. Each of these has about 10 million continuous float values (the length of the data vector is not exactly the same for each dataset).</p>
  
  <p>I usually calculate the <strong>Kolmogorov-Smirnov</strong> statistic using the <code>ks.test()</code> function from the standard <code>stats</code> package, but now I'm especially interested in the extreme values of the distributions. The KS, as far as I understand, pretty much hides those. The same happens for the <strong>Kullback-Leibler</strong> (feel free to correct me if I'm wrong).</p>
  
  <p>The <strong>Anderson-Darling</strong> test, on the other hand, is weighted to take into account the extremes of the distributions. However, I've not been able to find a simple implementation of the AD test that works on just two vectors as input (as <code>stats::ks.test()</code> does by just issuing <code>ks.test(obs.data, mod.data)</code>, where the two inputs are simple vectors), and neither I've been able to understand how to adapt my data to the functions I've tried.</p>
  
  <p>I've taken a look at the following functions:</p>
  
  <ul>
  <li><code>cvm.test()</code> from package <code>dgof</code>, with option <code>type="A2"</code>: requires a distribution as second input, not a vector</li>
  <li><code>ad.test()</code> from package <code>truncgof</code>: requires a distribution as second input</li>
  <li><code>ad.test()</code> from package <code>goftest</code>: as above</li>
  <li><code>ad.test()</code> from package <code>ADGofTest</code>: as above</li>
  <li><code>ad.test()</code> from package <code>kSamples</code>: in this case it's not clear to me what the output represents, and how I could normalize it, since it seems it's heavily dependent on the number of samples</li>
  <li><code>ad.test()</code> from package <code>nortest</code>: only tests for normality</li>
  <li><code>ADbootstrap.test()</code> from package <code>homtest</code>: this seems quite different from a standard AD test</li>
  </ul>
  
  <p>None of the above, in short, can be used as simply as the standard <code>ks.test()</code> function or as the Kullbach-Leibler function <code>KLdiv</code> from package <code>flexmix</code> (which accepts a matrix of density values).</p>
  
  <p>How can I calculate the AD statistic between two distributions provided simply as two vectors of continuous data, using R?</p>