Download the tutorial file, knit it to see the complete analysis, then run it chunk by chunk to understand each step.
In this lab you will test whether economic hardship clusters spatially using Global Moran’s I, then identify specific hot spot and cold spot neighborhoods using Local Indicators of Spatial Association (LISA). You will build spatial weights matrices, interpret Moran scatter plots, classify block groups into cluster types (HH, LL, HL, LH), and produce LISA cluster maps.
The tutorial walks through every step with fully working code. Knit it first to see the finished product, then go back and run chunk by chunk to understand how it works.
poly2nb() and nb2listw()moran.test()localmoran() to detect significant clustersCreate this folder structure before downloading anything. Move the downloaded .qmd into PAF516/Lab4/ before opening it in RStudio.
PAF516/
Lab1/ Lab2/ Lab3/
Lab4/
Lab4_Tutorial.qmd ← downloaded tutorial (do not edit)
Lab4_Tutorial.html ← auto-generated when you knit
Lab4_Assignment_Howell.qmd ← your renamed assignment copy
Lab4_Assignment_Howell.html ← submit this to Canvas
Lab5/ ...
Lab4_Tutorial.qmd in RStudiopackages chunk (labeled #| label: packages)renv block only runs once automaticallyThe lab pulls live data from the Census Bureau. If you don’t have a key yet:
census_api_key("YOUR_KEY_HERE", install = TRUE)Click the Render button (blue arrow, top of editor) or press Cmd+Shift+K / Ctrl+Shift+K. This produces Lab4_Tutorial.html with all results — choropleth maps, Moran’s I output, scatter plots, and LISA cluster maps. Review the output to see what the completed analysis looks like.
Place your cursor inside any code chunk and press the run shortcut. Output appears inline. Fix any errors before moving on. This is how you understand what each step does.
| Action | Mac | PC |
|---|---|---|
| Run current chunk | Cmd+Return | Ctrl+Enter |
| Run all chunks above | Cmd+Option+P | Ctrl+Alt+P |
| Knit / Render | Cmd+Shift+K | Ctrl+Shift+K |
| Step | What It Does |
|---|---|
| Step 1 | Pull Maricopa County block group data from the Census API |
| Step 2 | Build the 5-variable Economic Hardship Index with z-score standardization |
| Step 3 | Build spatial weights using queen contiguity (poly2nb + nb2listw) |
| Step 4 | Test for global spatial autocorrelation with moran.test() |
| Step 5 | Visualize spatial dependence with a Moran scatter plot |
| Step 6 | Run Local Moran’s I (LISA) and classify clusters (HH, LL, HL, LH) |
| Step 7 | Create LISA cluster maps and side-by-side hardship comparison |
Right-click → Save Link As. Save directly to your PAF516/Lab4/ folder. Do not open in the browser.