Load the fields library and the North American precipitation record.

library( fields)
## Loading required package: spam
## Loading required package: grid
## Spam version 1.4-0 (2016-08-29) is loaded.
## Type 'help( Spam)' or 'demo( spam)' for a short introduction 
## and overview of this package.
## Help for individual functions is also obtained by adding the
## suffix '.spam' to the function name, e.g. 'help( chol.spam)'.
## 
## Attaching package: 'spam'
## The following objects are masked from 'package:base':
## 
##     backsolve, forwardsolve
## Loading required package: maps
data(NorthAmericanRainfall)
# this is list not a data frame
names(NorthAmericanRainfall )
##  [1] "longitude"  "latitude"   "precip"     "elevation"  "precipSE"  
##  [6] "trend"      "trendSE"    "type"       "projection" "x.s"
# the lazy typist!
x<- cbind(NorthAmericanRainfall$longitude,
           NorthAmericanRainfall$latitude)
y<- NorthAmericanRainfall$precip/254 #inches of rainfall June-August
quilt.plot(x,y, nx=150, ny=75)
map( "world", add=TRUE, col="grey20")

Estimate a smooth surface to describe the spatial distribution. In this case this is a simple statistical method – a thin plate spline. Main feature is that the signal to noise is found using cross-validation. Cross-validation function shows a minimum around 650 degrees of freedom ( out of a possible range of 3 to 1720.) REML is another way to find the amount of smoothing.

fitObj<- Tps( x,y)
plot( fitObj, which=3) # CV plot