Unit 4: Spatial Analysis
This unit puts data together and starts to analyze it. It joins tables by a shared column and by location, then explores data the way an analyst first meets a new dataset: describing each variable’s center and spread, plotting its distribution, and mapping it. It ends with statistics that describe where features are, and puts your own R functions to work calculating them.
Chapter 15: Joins: Attribute and Spatial
A join combines tables by matching rows. This chapter covers dplyr’s inner, left, right, and full joins, naming the key with join_by(), and chaining joins across several tables. It explains cardinality, and why you should know it before you join. It then joins by location with sf’s st_join(), compares simple and summarized, inside and distance spatial joins, and shows why distances need a projected coordinate system.
Chapter 16: Exploratory Spatial Data Analysis
Before modeling data, get to know it. This chapter places exploratory data analysis in the data science workflow and adds the spatial question: how do values vary across space? It covers checking a data table, measures of central tendency (mean, median, mode) and dispersion (range, IQR, standard deviation), histograms, boxplots, and density plots, distribution shapes and outliers, and mapping rates rather than counts.
Chapter 17: Spatial Descriptive Statistics
Spatial descriptive statistics describe where features are. This chapter covers the mean center, the weighted mean center (including the U.S. center of population), the central feature, and the standard distance, each matched to the familiar statistic it extends. It then reviews writing functions in R, from a one-line addSeven() to a meanCenter() function for any layer of polygons.
GEOID with
left_join().
In R, a named piece of memory that holds data, such as
months <- 12. In a dataset, a measured characteristic,
such as median income; each Census variable has a code.
Code that takes inputs (arguments), does a job, and returns an output,
such as mean(temps).
The tidyverse package for transforming data frames: filtering rows,
choosing columns, adding new columns, joining tables, and summarizing.
A join that keeps every row of both tables, with NA wherever there is no
match. full_join() in dplyr.
How many rows in one table can match a row in another: one-to-one,
one-to-many, many-to-one, or many-to-many.
“Simple features”: the R package for spatial vector data. An sf object
is a data frame with a geometry column holding each row’s point, line,
or polygon.
A join that matches features by their location, such as attaching to
each point the polygon it falls inside. st_join() in R.
A method for flattening the curved graticule onto a flat map. Every
projection distorts shape, area, distance, or direction.
The rules that tie coordinates to places on the Earth, including how the
round Earth is flattened onto a map (the projection). Layers must share
a coordinate system before you can combine them.
Learning what is in a dataset, with summaries and plots, before trying
to explain or predict anything with it.
The steps of a data analysis: import, tidy, then a loop of transform,
visualize, and model, and finally communicate.
One value that describes the center of a set of values: the mean,
median, or mode.
The middle value when values are sorted, so half are above and half
below. Unlike counts, medians can’t be added across areas.
How spread out values are around their center, measured by the range,
interquartile range, or standard deviation.
Q3 minus Q1: the spread of the middle half of the data. Outliers barely
affect it. IQR() in R.
A measure of how spread out values are around their mean, in the same
units as the values. sd() in R.
A chart that divides a variable’s range into bins and draws a bar for
how many values fall in each. geom_histogram() in ggplot2.
A smoothed histogram whose total area is 1. geom_density()
in ggplot2.
A value far from all the others. It may be real or an error, so check it
before you report it.
Statistics that describe the center and spread of a set of locations,
such as the mean center and standard distance.
The average x coordinate and average y coordinate of a set of features.
Like the mean, outliers pull it.
A mean center in which each feature counts in proportion to an
attribute, such as population.
The point where a flat map of the country would balance if every
resident weighed the same.
The existing feature with the smallest total distance to all the others:
the spatial counterpart of the median.
The typical distance of features from their mean center: the spatial
counterpart of the standard deviation, drawn as a circle.
A closed shape that represents an area, such as a county, a lake, or a
census tract.