Вы находитесь на странице: 1из 2

Ordinary Kriging in R

library(geoR);library(fields);library(maps)

#You will need to change the directory to load these files:


source("...\\plot.field.points.R")
load("...\\PM25.RData")

#Combine the spatial coordinates in a 84x2 matrix


s<-cbind(long,lat)

#Plot the data


plot.field.points(s,PM,map.border="county",cex=1.5)
X11()

#Estimate parameters by maximum likelihood:


ml <- likfit(data=PM,coords=s,
fix.nugget=F,cov.model="exponential",
ini = c(30, 5),nugget=5)
summary(ml)

#Create grid of prediction points:


sp1<-seq(min(s[,1]),max(s[,1]),length=100)
sp2<-seq(min(s[,2]),max(s[,2]),length=100)
sp<-expand.grid(sp1,sp2)
inCA<-map.where("state",x=sp[,1],y=sp[,2])
inCA[is.na(inCA)]<-"NA"
inCA<-inCA=="california"

#Perform ordinary Kriging (value of cov.pars and nugget are copied from mle output):
pred<-krige.conv(data=PM,coords=s,locations=sp,
krige=krige.control(cov.model="exponential",
cov.pars=c(14.73,6.144),
nugget=4.299))
pred$predict[!inCA]<-NA
pred$krige.var[!inCA]<-NA

#Plot the predicted values:


image.plot(sp1,sp2,matrix(pred$predict,100,100),zlim=range(PM))
map("county",add=T)

#Plot the standard errors:


image.plot(sp1,sp2,matrix(sqrt(pred$krige.var),100,100),zlim=c(2,3.5))
map("county",add=T)
points(s)
Output
Raw data: > summary(ml)
Parameters of the mean component (trend):
beta
6.6346
40

16
Parameters of the spatial component:
14
correlation function: exponential
(estimated) partial sill = 14.73
38

12
(estimated) range parameter = 6.144
locs[, 2]

10

Parameter of the error component:


36

8
(estimated) nugget = 4.299
6
34

-124 -122 -120 -118 -116

locs[, 1]

Predicted values Standard deviations


40

40

3.4
16

3.2
14
38

38

3.0
12

2.8
sp2

sp2

10
36

36

2.6
8

6 2.4
34

34

4 2.2

2.0

-124 -122 -120 -118 -116 -124 -122 -120 -118 -116

sp1 sp1