
Learning how to model spatial data can be tricky, even more so when you are not very familiar with math or geometry! Luckily, there is an easy way to do this using software that most people have access to. This software allows you to create statistical models that use coordinates instead of numbers. These types of models are called spatial regression models because they apply mathematical concepts to predict outcomes depending on locations.
The easiest type of spatial regression to learn is something known as ordinary least squares (OLS) estimation. In OLS estimation, we simply add all of the independent variable coefficients together to get one total coefficient value. The difference between these two comes down to whether the distance matter or not – the “spatial” part. With OLS, if the distance between two points matters then the coefficient will be included, but if it does not then it will be dropped.
Spatial regression goes beyond just distances, however. You can also include squared distances, which some refer to as Euclideous distances, or categorical variables, such as dengue fever versus flu season, or urban areas vs rural ones. All of these additional terms increase the length of the equation substantially, making it much harder to perform inference.
Luckily, researchers have developed efficient algorithms for doing so by limiting the number of possible values of each term to only discrete ones. By applying these constraints, it becomes feasible to run regressions with large amounts of Spatio-temporal data.

A common beginner’s mistake when it comes to working with spatial datasets is assuming that all of the features are numeric. This can lead to confusing results, as you might try to add two different areas together and get an unexpected result.
A more nuanced way to think about spatial datasets is to understand that some of them contain information not only about location regression but also about size or area. For example, if we wanted to know how big the ocean is, then our dataset for this would be the longitude and latitude coordinates of the edge of the water.
This distinction between numerical and non-numerical features is important to keep in mind while performing calculations using raster layers. It will save you time by helping you identify whether your calculation makes sense conceptually and correctly.
RegressionThe next step is to establish or create a spatial dataset. This can be done by using any of the following tools: Google Maps, ArcGIS, Qgis, etc.
A common way to begin establishing a spatial database is to use Google maps. Begin by searching your area or topic online and see if there are any relevant articles or videos that talk about it. If so, go through those steps and then add some details to fit your needs!
Another good source for beginners is looking at examples given in software such as Tableau, which allows you to make interactive visualizations.

In other words, creating a spatially correlated structure or pattern is what this chapter will focus on! To begin with, you’ll need to create an empty data frame that contains your independent variables as well as your dependent variable.
The way that we would typically do this is by using built-in functions such as sp() for our state parameter, lon() for our longitude coordinate, lat() for our latitude coordinate, and then means() to run clustering analysis on our dependent variable.
We can use these three functions together to achieve our goal of creating a spatial correlation! Let’s take a look at some code. First, let’s grab some random points from the map: east = c(-72.2267,-71.9097) west = c(72.2267, 71.9097) north = c(-122.9983,-121.8992) south = c(-81.9888, -82.0184) We can input those into the coordinates argument of SF(), which creates a Point object.
Next, we’ll want to add those objects to our data frame using bind().

Kriging is an interesting spatial statistical method that works by creating weighted averages of values across space. The weightings are determined by how close one location is to another, with closer locations having more influence on the average.
A common example of kriging is predicting house prices. You take several houses along with their sales prices and use software to determine what variables predict price — square footage, number of bedrooms, etc. Then you plug these numbers into a formula to come up with an estimated price for each property!
So why not just use the sale prices as an estimate? Because people tend to buy near where they live, this approach would underestimate the value of properties that are far away from home.
By incorporating information about the neighbourhood, though, kriging can be used to give estimates that better reflect the true market value of a property. By weighing distances differently, it creates an adjusted price that takes into account things like commute time and safety of the area.
There are many ways to do kriging in R, but the most straightforward way is using the g stat package’s Krige (Regression) function. This article will go over some basics of kriging and then apply this knowledge to make some predictions using data.

The next step to understanding spatial patterns is defining what level of spatial correlation there is within your data. There are two main types of correlations that you can identify in spatially-linked datasets:
Global Moran’s I - This statistic calculates whether there is an overall positive or negative relationship between nearby observations, as well as how much variability exists across all areas being studied.
Local Indicators of Poverty (LIP) - These statistics assess whether there is enough income diversity present around individual census tracts or zip codes. If there is not enough variation, then it suggests that there may be something going on that is causing people with similar incomes to live close together, creating a more concentrated area of wealthy individuals.
Both of these metrics require some additional math beyond just calculating global and local indices! Check out this great primer on both LIPs and GMOs from Statistic Zone.

What is spatial data? Special information can be categorized as numerical, categorical, or discrete (like state names). Numerical variables are easy to understand- they depend on only one other variable. For example, if you were given a question like “What is your height?” and then asked “How tall was Barack Obama?”, your answer would be the difference between those two numbers.
That is what a numerical dependent variable is- an answer that depends on another number. The second type of dependent variable is called categorical because it comes down to just choosing from among several options. State names are a good example of this- you choose either California, Florida, New York, or some other US state!
The third kind of special dependent variable is something more abstract- things like county, city, or district name. This is also considered discrete spatial data because there is no universal size for it. There is not any mathematical way to determine regression big or small a district is, but we usually give them a length such as a mile long, a kilometre wide, etc. Regression
When talking about geographic data, people mostly use latitude and longitude. These two coordinates go along with our normal cartesian coordinate system which has x and y axes that run parallel to each other in both directions. The last/long system itself is very intuitive- every degree north is going up, and every degree west is moving away.

The next step is to apply our newly-created layer of the model to your data set. To do this, you will need to add two new columns to your dataset – one for the state and another for the county. These two fields should be chosen as strings instead of integers due to the way we constructed our layers earlier!
After that, you can run through each row of your original table and calculate the distance between each address and each layer’s feature (state or county). This calculation can easily be done using the st_distance() function within the sp package.
Once all distances are calculated, you can sort the entries by descending order (nearest first) and pick out the five nearest features to determine which belongs to which layer.

A second way to look at this is as a type of regression where the independent variables are not only related to each other but also relate to the dependent variable spatially. This approach was first popularized by Robert Muthén who coined the term latent class analysis (LCA).
Latent class analysis can be thought of as cluster analysis that looks for groups or classes within a set of measured indicators. In LCA, these clusters are called “latent” because they represent unobserved characteristics.
For example, let’s say we want to determine if someone is an alcoholic. We could test their alcohol volume, how often they drink, etc., and use those measurements to predict whether someone is an alcoholic or not.
But what if two different people had the same level of drinking? How would you decide which one was more likely to be an alcoholic?
In such cases, LCA predicts that a person is most likely an alcoholic. The reason why is that it assumes there is something about individuals that makes some people more likely to become alcoholics.
This assumption fits well with our earlier analogy. If there are two people who both have a lot of drinks, then maybe one of them is more likely to get drunk than the other one. So, LCAs assume that there is something special about the individual members of a group that accounts for why some members of that group turn into members of another group.