LAB 6 — TUTORIAL

Spatio-Temporal Change (Part 2)

Download the tutorial file, knit it to see the complete analysis, then run it chunk by chunk to understand each step.

What You Will Build

Lab 5 answered what changed in Maricopa County between 2013 and 2019. Lab 6 asks the deeper question: is change spatially structured? You will classify each tract by how its LISA cluster membership changed over time, test whether change scores are spatially autocorrelated using space-time Moran’s I, and add a 2016 middle observation to distinguish sustained trends from noise.

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.

Learning Objectives
  • Rebuild the Lab 5 change dataset (3-variable index, pooled standardization, 2013 & 2019)
  • Run LISA on each period separately and classify tracts into HH/LL/HL/LH/NS
  • Build a LISA transition matrix to compare 2013 and 2019 cluster membership
  • Classify tracts into trajectories: Persistent HH, Emerging HH, Dissolving HH, and more
  • Test whether change scores are spatially autocorrelated with moran.mc()
  • Add a 2016 middle observation for multi-point trend analysis

Before You Begin

1 — File and Folder Setup

Create this folder structure before downloading anything. Move the downloaded .qmd into PAF516/Lab6/ before opening it in RStudio.

PAF516/
  Lab1/  Lab2/  Lab3/  Lab4/  Lab5/
  Lab6/
    Lab6_Tutorial.qmd            ← downloaded tutorial (do not edit)
    Lab6_Tutorial.html           ← auto-generated when you knit
    Lab6_Assignment_Howell.qmd   ← your renamed assignment copy
    Lab6_Assignment_Howell.html  ← submit this to Canvas
  Lab7/  ...

2 — Install Packages (Run Once)

Do this before knitting
  1. Open Lab6_Tutorial.qmd in RStudio
  2. Click inside the packages chunk (labeled #| label: packages)
  3. Press Cmd+Return (Mac) or Ctrl+Enter (PC) to run just that chunk
  4. Wait — first run downloads and installs packages and may take 5–10 minutes
  5. After it finishes, future knits will be fast — the renv block only runs once automatically
What is renv?
renv records the exact version of every package used so that code that works today still works next semester.

3 — Census API Key

The lab pulls live data from the Census Bureau. If you don’t have a key yet:

  1. Register free at api.census.gov/data/key_signup.html
  2. Check email for your key (arrives within a few minutes)
  3. In the RStudio console run: census_api_key("YOUR_KEY_HERE", install = TRUE)
  4. Restart R: Session → Restart R

Running the Tutorial

Option A — Knit First (Recommended)

Click the Render button (blue arrow, top of editor) or press Cmd+Shift+K / Ctrl+Shift+K. This produces Lab6_Tutorial.html with all results — LISA cluster maps, transition matrices, trajectory maps, Moran scatterplots, and multi-point trend classifications. Review the output to see what the completed analysis looks like.

Option B — Run Chunk by Chunk (Best for Learning)

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.

ActionMacPC
Run current chunkCmd+ReturnCtrl+Enter
Run all chunks aboveCmd+Option+PCtrl+Alt+P
Knit / RenderCmd+Shift+KCtrl+Shift+K

What’s Inside

StepWhat It Does
Step 1Rebuild the Lab 5 dataset — pull 2013 and 2019 data, compute pooled-standardized change scores
Step 2Build queen contiguity spatial weights matrix
Step 3Run LISA separately on the 2013 and 2019 hardship indices
Step 4Build a LISA transition matrix (rows = 2013, columns = 2019)
Step 5Classify tracts into trajectories: Persistent HH, Emerging HH, Dissolving HH, etc.
Step 6Trajectory map and side-by-side comparison (2013 LISA | 2019 LISA | Trajectories)
Step 7Space-time Moran’s I — test whether change scores are spatially autocorrelated
Step 8Multi-point trend analysis — add 2016 to distinguish sustained trends from noise

Download

Lab 6 Tutorial File

Download Lab6_Tutorial.qmd

Right-click → Save Link As. Save directly to your PAF516/Lab6/ folder. Do not open in the browser.