title: Spatial Autocorrelation Analysis (Global Moran's I) in R
body: <p>I have a list of points I want to check for autocorrelation using Moran's I and by dividing         area of interest by 4 x 4 quadrats.</p>
  
  <p>Now every example I found on Google (e. g. <a href="http://www.ats.ucla.edu/stat/r/faq/morans_i.htm" rel="nofollow">http://www.ats.ucla.edu/stat/r/faq/morans_i.htm</a>) uses some kind of measured value as the first input for the Moran's I function, no matter which library is used (I looked into the ape and spdep packages). </p>
  
  <p>However, all I have are the points themselves I want to check the correlation for.</p>
  
  <p>The problem is, as funny (or sad) as this might sound, I've no idea what I'm doing here. I'm not much of a (spatial) statistics guy, all I want to find out is if a collection of points is dispersed, clustered or ramdom using Moran's I.</p>
  
  <p>Is my approach correct? If not where and what I am doing wrong?</p>
  
  <p>Thanks</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code># download, install and load the spatstat package (http://www.spatstat.org/)
  install.packages("spatstat")
  library(spatstat)
  
  # Download, install and run the ape package (http://cran.r-project.org/web/packages/ape/)
  install.packages("ape")
  library(ape)
  
  # Define points
  x &lt;- c(3.4, 7.3, 6.3, 7.7, 5.2, 0.3, 6.8, 7.5, 5.4, 6.1, 5.9, 3.1, 5.2, 1.4, 5.6, 0.3)
  y &lt;- c(2.2, 0.4, 0.8, 6.6, 5.6, 2.5, 7.6, 0.3, 3.5, 3.1, 6.1, 6.4, 1.5, 3.9, 3.6, 5.2)
  
  # Store the coordinates as a matrix
  coords &lt;- as.matrix(cbind(x, y))
  
  # Store the points as two-dimensional point pattern (ppp) object (ranging from 0 to 8 on both axis)
  coords.ppp &lt;- as.ppp(coords, c(0, 8, 0, 8))
  
  # Quadrat count
  coords.quadrat &lt;- quadratcount(coords.ppp, 4)
  
  # Store the Quadrat counts as vector
  coords.quadrat.vector &lt;- as.vector(coords.quadrat)
  
  # Replace any value &gt; 1 with 1
  coords.quadrat.binary &lt;- ifelse(coords.quadrat.vector &gt; 1, 1, coords.quadrat.vector)
  
  # Moran's I
  
  # Generate the distance matrix (euclidean distances between points)
  coords.dists &lt;- as.matrix(dist(coords))
  
  # Take the inverse of the matrix
  coords.dists.inv &lt;- 1/coords.dists
  
  # replace the diagonal entries (Inf) with zeroes
  diag(coords.dists.inv) &lt;- 0
  
  writeLines("Moran's I:")
  print(Moran.I(coords.quadrat.binary, coords.dists.inv))
  writeLines("")
  </code></pre>