UCLA Department of Statistics Statistical Consulting Center Intro to Spatial Statistics in R David Diez June 2, 2009 David Diez Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center Prerequisites It is assumed that an attendant has... A strong understanding of basic probability theory. Taken a regression course. Familiarity with using R for regression and building very simple functions. David Diez Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center Outline Geostatistics Regression modeling Kriging Correlogram (in passing) Point patterns Poisson theory Clustering Tools to ID clustering Inhibition David Diez Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center Introduction Modeling Kriging Correlogram Geostats Geostats Geostatistical data includes observations at a collection of locations. The locations may or may not be random, and it is what is observed at these locations that is of particular interest. Later we will discuss point pattern data, where the points themselves are the data (such as earthquake locations). David Diez Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
14
Embed
Intro to Spatial Statistics in R - UCLA Statistical Consultingscc.stat.ucla.edu/page_attachments/0000/0094/spatial_R_1_09S.pdf · UCLA Department of Statistics Statistical Consulting
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
UCLA Department of StatisticsStatistical Consulting Center
Intro to Spatial Statistics in R
David Diez
June 2, 2009
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
Prerequisites
It is assumed that an attendant has...
A strong understanding of basic probability theory.
Taken a regression course.
Familiarity with using R for regression and building very simplefunctions.
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
Outline
Geostatistics
Regression modelingKrigingCorrelogram (in passing)
Point patterns
Poisson theoryClusteringTools to ID clusteringInhibition
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
Introduction Modeling Kriging Correlogram
Geostats
Geostats
Geostatistical data includes observationsat a collection of locations. Thelocations may or may not be random,and it is what is observed at theselocations that is of particular interest.
Later we will discuss point pattern data,where the points themselves are thedata (such as earthquake locations).
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
Introduction Modeling Kriging Correlogram
Packages
Packages
We will need the spatial and MASS packages:
> library(spatial)> library(MASS)
spatial is included in the initial R install, however, MASS is not. Ifloading MASS does not work, first install the package:
> install.packages("MASS")
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
Introduction Modeling Kriging Correlogram
topo
Data
Topographic heights within a 310 feet square. We follow the methods ofModern Applied Statistics with S. First, plot the data.
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
Introduction Modeling Kriging Correlogram
Ordinary kriging
Kriging result
0 1 2 3 4 5 6
0
1
2
3
4
5
6
0 1 2 3 4 5 6
0
1
2
3
4
5
6
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
Introduction Modeling Kriging Correlogram
Try it
Try it
We don’t have time for all of these, but this would be a good exercise forlater. Load the library geoR and the data set parana. Change the formatof the data set and plot the data:
We will use the library spatstat for spatial point patterns.
> library(spatstat)
If you get an error, first install the package (and select a location toinstall from):
> install.packages("spatstat")
This library has a wide range of point pattern functions, includingsimulation, summary, analysis, and modeling tools. (Among much more.)Help files for the package can be accessed via
> help(spatstat)
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
The package spatstat uses a special class for points called ppp. Thecoordinates of the points in a ppp object can be accessed via
> pp1$x[1] 0.965859088 0.9874...
> pp1$y[1] 0.787572894 0.0075...
Objects of class ppp also maintain other components, including the spaceover which points are observed, the number of points in the pattern, andany “marks” associated with the pattern (for instance, earthquakes mightbe marked by their magnitude).
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
None are clustered processes. The points are all uniformly distributedover the space (generated from a uniform intensity, i.e. homogeneous,Poisson process).
rpoispp(50) rpoispp(50) rpoispp(50)
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
A Neyman-Scott process is basically a Poisson process with each(“parent”) point (red) replaced with k uniformly distributed “children”points about it (black). Generate such a process via
Use the function rMatClust to simulate a clustered process that is...
clearly clustered, and name this pattern clearlyClustered.
not clearly clustered but still might show some clustering, and namethis pattern littleClustering,
When creating the second pattern, consider what properties would makeit hard to distinguish it from a Poisson process. We will be using thesepatterns later on, so don’t overwrite them!
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
It is useful to identify the type of process as either clustered or not.(Later we will discuss a process that is “anti-clustered”.) How might wedo this?
A good first step would be to look at how close neighboring points are. Asecond step might be to look at the neighborhood intensity around points(as estimated by the data).
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
For each point p, identify the distance dp of p to its nearest neighbor.Then we can examine the distribution of these distances dp to seewhether they follow what we would anticipate in a homogeneous(uniform) Poisson process.
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
If a process shows clustering, then the proportion of points with a smallnearest neighbor distance will be larger (or is more likely to be larger)than would be anticipated under a Poisson process.
If the process is a Poisson process, then the proportion of points withinradius r should follow
G (r) = 1− P(no point within r)
= 1− e−λπr2
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
Of a similar nature, the K function estimates the intensity within r of alocation. If the process is homogeneous Poisson, then the K functionK (r) should closely resemble
Λwithin r units = λπr2
λ might be estimated via
λ̂ =# of points in pattern
area of space
The empirical K function can be compared to this theoretical function toidentify clustering.
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
One example of an inhibition process is a Matern I process. Produce aPoisson process with intensity kappa. If a point is within distance r ofanother point, delete it.
> pp6 <- rMaternI(kappa=50, r=0.1)> plot(pp6)
pp6
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
Make a Matern I process where consistently no points are produced,however, we require kappa to be at least 1 and r to be no larger than10% of the width of the space.
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center
The package spatstat offers a variety of tools that can be used toestimate parameters of particular processes. We examine the utility of acouple of the functions.
David Diez
Intro to Spatial Statistics in R UCLA Department of Statistics Statistical Consulting Center