Automatic spatial interpolation with R: the automap package

In case of continuously collected data, e.g. observations from a monitoring network, spatial interpolation of this data cannot be done manually. Instead, the interpolation should be done automatically. To achieve this goal, I developed the automap package. automap builds on top of the excellent gstat package, and provides automatic spatial interpolation, more specifically, automatic kriging. Kriging in its more simple form (Ordinary Kriging, Universal Kriging, aka Kriging with External Drift) is actually nothing more than linear regression with spatially correlated residuals.

automap provides the following set of functions (for details I refer to the online manual):

  • autofitVariogram, automatically fits the variogram model to the data.
  • autoKrige, automatically fits the variogram model using autofitVariogram, and creates an interpolated map.
  •, automatically fits the variogram model using autofitVariogram, and performs cross-validation. Uses under the hood.
  •, allows comparison of the output of and This can be used to evaluate the performance of different interpolation algorithms. allows comparison using both summary statistics and spatial plots.

In general, the interface of automap mimics that of gstat. The following code snippets show some examples of creating interpolated maps using automap:

You can get automap from either CRAN:

or my bitbucket account.

PS: automap was the first package I wrote, at the beginning of my PhD, so it is not the most beautiful code I ever wrote ;).

Tagged with: ,
Posted in R stuff
2 Comments » for Automatic spatial interpolation with R: the automap package
  1. mrad says:

    Thank you so much. Greetings

  2. Praveen says:

    Hi, I’m from Sri Lanka. I used the automap package you developed to interpolate the rainfall data in Sri Lanka. But It gives me negative rainfall values to some years. Could you please give me your assistance in correcting this issue.

Leave a Reply

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

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see