title: Calculation of Moran's I with 4000 records
body: <p>I have 4000 records of volume in trees plantation. I need to calculate the Moran's I to the whole plantation. I use <strong>ape</strong> library because <strong>spdep</strong> is said to be slower.
  My code is this:</p>
  
  <pre><code># Modified from http://www.ats.ucla.edu/stat/r/faq/morans_i.htm
  require(ape)
  df &lt;- data.frame(
       x = 1:2000,
       y = 1:2000,
       v = rnorm(4000, mean=4) )
  df.dists &lt;- as.matrix(dist(cbind(df$x, df$y)))
  df.dists.inv &lt;- 1/df.dists
  diag(df.dists.inv) &lt;- 0
  Moran.I(df$v, df.dists.inv)
  </code></pre>
  
  <p>When I run the code, I get overflow-like errors.</p>
  
  <pre><code>*Error in if (obs &lt;= ei) 2 * pv else 2 * (1 - pv) : 
    missing value where TRUE/FALSE needed*
  </code></pre>
  
  <p>Using ff library</p>
  
  <pre><code>require(ape)
  require(ff)
  ffdf &lt;- as.ffdf(df)
  ffdf.dists &lt;- as.matrix(dist(cbind(ffdf$x, ffdf$y)))
  ffdf.dists.inv &lt;- 1/df.dists
  diag(ffdf.dists.inv) &lt;- 0
  Moran.I(ffdf$v, ffdf.dists.inv)
  </code></pre>
  
  <p>More error messages:</p>
  
  <pre><code>*Error in x - m : non-numeric argument to binary operator
  In addition: Warning message:
  In mean.default(x) : argument is not numeric or logical: returning NA*
  </code></pre>
  
  <ul>
  <li><p>How can I get the calculation to the whole plantation?</p></li>
  <li><p>Should I use <strong>sdep</strong> instead of <strong>ape</strong> library?</p></li>
  <li><p>How could <strong>parallel</strong> library solve this problem?</p></li>
  </ul>
  
  <p>Thanks in advance
  Juan</p>