R Geostatistics Homework

Statistics C173/C273: Applied Geostatistics

  • First lecture is on Monday, 08 January 2018
    Location: Dodd Hall 167.
    Day/time: MWF 12:00 - 12:50.
    See you then!

  • For the course syllabus click here.

    Useful links:

  • http://www.socr.ucla.edu

    It's online, therefore it exists!

  • http://wiki.stat.ucla.edu/socr/index.php/SOCR_EduMaterials
  • Download R and packages.
  • Download RStudio.

    Data sets

    Copy and paste each line below at the R command line to acces the data:
    a1 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/wolfcamp.txt", header=TRUE)
    a2 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/walker_lake_v.txt", header=TRUE)
    a3 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/walker_lake_u.txt", header=TRUE)
    a4 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/soil.txt", header=TRUE)
    a5 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/o3.txt", header=TRUE)
    a6 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/soil_complete.txt", header=TRUE)
    a7 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/coal_ash.txt", header=TRUE)
    a8 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/broom_barn_data.txt", header=TRUE)
    a9 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/nc_sids.txt", header=TRUE)
    a10 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/unemp_data.txt", header=TRUE)
    a11 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/nc_sids_data.txt", header=TRUE)
    a12 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/nc_seats.txt", header=TRUE)
    a13 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/parana.txt", header=TRUE)
    a14 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/jura.txt", header=TRUE)
    a15 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/o3.txt", header=TRUE)
    a16 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/coal_ash.txt", header=TRUE)
    a17 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/elevation.txt", header=TRUE)
    a18 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/kruger_park_rainfall.txt", header=TRUE)
    a19 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/ca_elections_results_2012.txt", header=TRUE)
    a20 <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c173_c273/la_data.txt", header=TRUE)


  • 1. Lab 1 - Due on Wednesday, 17 January.
  • 2. Lab 2.
  • 3. Lab 3 - cross valdation.
  • 4. Lab 4 - Due on Monday, 05 March.
  • 5. Lab 5 - Due on Wednesday, 14 March.


  • 1. Introduction.
  • 2. Spatial statistics.
  • 3. The variogram.
  • 4. Computing the variogram using geoR.
  • 5. Multivariatre normal distribution.
  • 6. Application of geostatistics in Political Science.
  • 7. Parana data: h-scatterplots.
  • 8. Robust estimator paper.
  • 9. Special matrices - examples.
  • 10. More on variogram.
  • 11. More variograms.
  • 12. Fitting a model variogram - Noel Cressie (1985).
  • 13. Fitting a model variogram.
  • 14. Fitting a model variogram - R code.
  • 15. R code to graph some model variograms.
  • 16. Simulations using Cholesky decomposition - example.
  • 17. Simulations using the grf function of geoR - example.
  • 18. Simulations using geoR and the maps packages.
  • 19. Simulating geostatistical data.
  • 20. Data with trend.
  • 21. Working with gstat.
  • 22. Geometric anisotropy.
  • 23. Anisotropy plot.
  • 24. Geometric anisotropy - calculations.
  • 25. Anisotropy paper.
  • 26. Variogram models - summary.
  • 27. Spatial prediction.
  • 28. Inverse distance interpolation - with contours.
  • 29. Ordinary kriging in terms of variogram.
  • 30. Ordinary kriging in terms of covariance.
  • 31. Ordinary kriging using geoR and gstat.
  • 32. Short R code for ordinary kriging in terms of variogram.
  • 33. Short R code for ordinary kriging in terms of covariance.
  • 34. Data file kriging_1.txt for handouts 29 and 30.
  • 35. Data file kriging_11.txt for handouts 29 and 30.
  • 36. Ordinary kriging in matrix form.
  • 37. Kriging is an exact interpolator.
  • 38. Simple kriging - R code.
  • 39. Simple kriging - with geoR and gstat.
  • 40. Kriging is an exact interpolator.
  • 41. Check geoR and gstat for exact interpolation calculations!
  • 42. Effect of variogram parameters on kriging weights.
  • 43. Cross validation.
  • 44. Cross-validation using geoR and gstat - example.
  • 45. Lognormal ordinary kriging - R code.
  • 46. Assign "NA" values.
  • 47. Nonnegative kriging weights I.
  • 48. Nonnegative kriging weights II.
  • 49. One-dimensional ordinary kriging - screen and relay effect.
  • 50. Universal kriging.
  • 51. Problems with universal kriging.
  • 52. Decomposition of mean squared error of prediction.
  • 53. Indicator kriging.
  • 54. Cross-validation: comparing ordinary with univesrsal kriging - example.
  • 55. Block kriging.
  • 56. Cokriging.
  • 57. Cokriging - extra notes.
  • 58. Cross validation: Comparing ordinary with cokriging.
  • 58. Cokriging: Target variable plus two colocated variables - example.
  • 60. Universal kriging and cokriging as a regression procedure (paper by Stein and Cornsten).
  • 61. Kriging for categorical variables.
  • 62. Linear model of coregionalization.
  • 63. Kriging revisited.
  • 64. Sequential simulations.
  • 65. Bayesian kriging.
  • 66. Fixed rank kriging (paper by Cressie and Johannesson).
  • 67. Spatial-temporal models.


  • Homework 1: Due on Wednesday, 17 January.
  • Homework 2: Due on Friday, 26 January.
  • Homework 3: Due on Wednesday, 07 March.
    Back to the Statistics Department Home page.

Spatial Analysis Techniques in R

taught by David Unwin

Aim of Course:

The R environment provides a consistent and stable platform for spatial statistical analysis and is the computing environment of choice for most researchers in the field.

This online course, “Spatial Analysis Techniques in R,” aims to

  • Introduce the use of R for geographic information analysis.  Although much of what will be covered can be accomplished using a GIS, such use is awkward and often highly inefficient;
  • Develop understanding of some topics beyond the basic courses or most standard texts.
After following the course and doing the assignments you will be able to:
  • Install and use the basic R environment;
  • Select an appropriate R package for point, lattice and geostatistical data and enter spatial data into it;
  • Create sensible maps of these same data;
  • Undertake both global and local spatial analysis of the patterns these maps reveal, using the idea of complete spatial randomness as benchmark;
  • Most important of all, critically assess the results of these analyses.

Which course should you take, this one, or "Mapping in R?"

"Spatial analysis techniques in R" employs the standard R methods and packages (spatstat, sp, gstat), with an emphasis on the statistical analysis of three major types of spatial objects: point events, spatial lattices and continuous surfaces.  If your interest is more in the display of spatial data, and especially area lattice data (e.g. states, counties, provinces), including mapping data acquired over the internet, then "Mapping in R" (using GISTools) might be a better choice. There is virtually no overlap between these courses.

This course may be taken individually (one-off) or as part of a certificate program.

Course Program:

WEEK 1: Introducing R

  • spatial and displaying some geographic data including
    • visualization of point
    • lattice
    • geostatistical data using simple maps

WEEK 2: Point Pattern Analysis

  • global tests against the hypothesis of complete spatial randomness
  • kernel density estimation
  • dealing with non-homogeneity using the spatstat package

WEEK 3: Area (lattice) objects

  • spatial autocorrelation and local statistics including
    • global autocorrelation
    • local indicators of spatial association
    • geographical weighted regression using the spdep package

WEEK 4: Geostatistical data

  • the analysis of continuous ‘field’ data by variography including
    • interpolation by inverse distance decay
    • trend surface analysis
    • variography
    • kriging using the gstat package

Note that the course does not concentrate on the analysis of spatially continuous data using methods that are collectively referred to as geostatistics but that Lesson 4 covers the basics.

Homework Assignments

There are four assignments in this course. These will be marked by the course leader himself, but whether you need to be concerned with these marks depends on your purpose in taking the course. Some students are interested just in learning for learning's sake, others may require a certificate showing they have completed a course, some may need academic credit (offered in selected courses only).  Students enrolled in a Program in Advanced Statistical Studies also complete a guided project using spatial data.

In addition to assigned readings, this course also has an end of course data modeling project, and supplemental readings available online.

Spatial Analysis Techniques in R

Who Should Take This Course:

The course is aimed at anyone with experience either in spatial analysis using a standard GIS (such as ArcGIS), or who already uses R for basic non-spatial analysis wishing to extend their skills in spatial analysis using R.  Although it covers some of the same ground, students who have followed the course Spatial Statistics with GIS given by the same instructor will find that this course usefully extends their skills.


You should be familiar with introductory statistics.  Try these self tests to check your knowledge.

You should also be familiar with R, or, at a minimum, a command line environment, since this course involves:

  • Installing and running the R environment;
  • Installing a series of packages (spatstat, map, maptools, sp, lattice, spdep and gstat) designed for use in spatial analysis;
  • Driving these packages at a command line interface; and
  • Reading in data using read.table.

Lesson 1 contains an optional and very basic introduction to these operations that will get you started, but you should be confident of your ability to perform these simple operations in the R environment.  Any 'programming' we do is simply selecting appropriate inputs to the listed packages.  If you are new to R and doubtful about your ability to learn R quickly enough to follow along in the course, we recommend first taking one of the introductory R courses.
Organization of the Course:

This course takes place online at the Institute for 4 weeks. During each course week, you participate at times of your own choosing - there are no set times when you must be online. Course participants will be given access to a private discussion board. In class discussions led by the instructor, you can post questions, seek clarification, and interact with your fellow students and the instructor.

At the beginning of each week, you receive the relevant material, in addition to answers to exercises from the previous session. During the week, you are expected to go over the course materials, work through exercises, and submit answers. Discussion among participants is encouraged. The instructor will provide answers and comments, and at the end of the week, you will receive individual feedback on your homework answers.

Time Requirement:
About 15 hours per week, at times of  your choosing.

Options for Credit and Recognition:
Students come to the Institute for a variety of reasons. As you begin the course, you will be asked to specify your category:
  1. No credit - You may be interested only in learning the material presented, and not be concerned with grades or a record of completion.
  2. Certificate - You may be enrolled in PASS (Programs in Analytics and Statistical Studies) that requires demonstration of proficiency in the subject, in which case your work will be assessed for a grade.
  3. CEUs and/or proof of completion - You may require a "Record of Course Completion," along with professional development credit in the form of Continuing Education Units (CEU's).  For those successfully completing the course,  CEU's and a record of course completion will be issued by The Institute, upon request.
  4. Other options - Statistics.com Specializations, INFORMS CAP recognition, and academic (college) credit are available for some Statistics.com courses

Specializations are an easy way for you to demonstrate mastery of a specific skill in statistics and analytics. This course is part of the Spatial Analytics Specialization which gives a deep dive into analyzing location and geospatial data.  Take any three of the four Statistics.com courses on this topic (this course, plus the courses listed to the right under "related courses," not including conferences).  For savings, use the promo code "spatial-specialization" and register for all three courses at once for  $1197 ($399 per course, not combinable with other tuition savings).  If you register for all four, you'll still receive the discounted rate.


This course is also recognized by the Institute for Operations Research and the Management Sciences (INFORMS) as helpful preparation for the Certified Analytics Professional (CAP®) exam, and can help CAP® analysts accrue Professional Development Units to maintain their certification .

Course Text:

The required text for this course is Geographic Information Analysis, 2nd ed by David O'Sullivan and David J. Unwin.  It can be purchased here

In addition, students might also like to purchase Bivand, R.S., Pebesma, E. and V. Gomez Rubio (2008) Applied Spatial Data Analyis With R (Springer, NY, in the UseR! Series). This contains all you need to know, but at relatively advanced level.  This optional textbook can be purchased here

You must have a copy of R for the course. Click Here for information on obtaining a free copy.


Prof. David Unwin


December 07, 2018 to January 04, 2019January 25, 2019 to February 22, 2019January 24, 2020 to February 21, 2020

Spatial Analysis Techniques in R


Prof. David Unwin

December 07, 2018 to January 04, 2019January 25, 2019 to February 22, 2019January 24, 2020 to February 21, 2020

Course Fee: $589

Do you meet course prerequisites? What about book & software? (Click here to learn more)

We have flexible policies to transfer to another course, or withdraw if necessary (modest fee applies)

Group rates:Click here to get information on group rates. 

First time student or academic? Click here for an introductory offer on select courses. Academic affiliation?  You may be eligible for a discount at checkout.

First Time Student?

If you are new to Statistics.com, welcome! To get you going, take 10% off the standard tuition rate on your first course. Just use the following promo code at the end of the registration process.

Code: newstudent8am1 (code expires March 31, 2018)

Not quite ready to register? We will send you a longer lasting code; just fill out your contact info below:

Register Now


Leave a Reply

Your email address will not be published. Required fields are marked *