This tutorial builds on Correlogram Part 1 and Variogram Part 1.
It shows how to compute Moran’s I/Geary’s C correlograms and a semivariogram from simple CSV point data.
- How to load your own CSV file of points
- Project coordinates into meters for distance-based analysis
- Define distance bins (rule of thumb: max lag = 1/3 of max pairwise distance)
- Compute Moran’s I and Geary’s C correlograms
- Compute a semivariogram (with
gstat) - Compare correlogram vs. semivariogram
This repo includes two dummy CSVs so you can try the workflow immediately:
dummy_strong_spatial.csv— columnCOVIDincid(positive values, strong spatial trend)dummy_no_spatial.csv— columnKuruPrev(no meaningful spatial trend)
Open the rendered HTML tutorial:
- https://parker-group.github.io/spatial_depend_2/
index.html(in this repo, rendered fromCorrelVariogram_pt2.rmd)
In R:
install.packages(c("spdep", "sp", "sf", "ggplot2", "gstat", "rmarkdown")) # first time
rmarkdown::render("CorrelVariogram_pt2.rmd", output_format = "html_document")Click to launch an interactive RStudio session in your browser:
When RStudio opens:
- In the Files pane, click
CorrelVariogram_pt2.rmd - Click Knit to render, or use Run ▶ to step through
- The RMarkdown script auto-detects whether the dataset column is
COVIDincidorKuruPrev. - If using your own CSV, ensure it has at least three columns:
X,Y, and a numeric value column. - Always project to meters before running distance-based spatial analyses.