library(sp)
## Warning: package 'sp' was built under R version 3.1.3
library(gstat)
## Warning: package 'gstat' was built under R version 3.1.3
data(meuse)
coordinates(meuse) <- ~x+y
proj4string(meuse) <- CRS("+init=epsg:28992")
spplot(meuse,"cadmium",colorkey=TRUE)
data(meuse.grid)
coordinates(meuse.grid) <- ~x+y
proj4string(meuse.grid) <- CRS("+init=epsg:28992")
meuse.grid <- as(meuse.grid,"SpatialPixelsDataFrame")
plot(meuse.grid)
points(meuse,pch=20)
I am going to set values for p of 0.1 and 50, and also do use 2.5 as given in the notes.
cdIDW <- idw(formula=cadmium~1,locations=meuse,newdata=meuse.grid,idp=2.5)
## [inverse distance weighted interpolation]
cdIDW.1 <- idw(formula=cadmium~1,locations=meuse,newdata=meuse.grid,idp=0.1)
## [inverse distance weighted interpolation]
cdIDW50 <- idw(formula=cadmium~1,locations=meuse,newdata=meuse.grid,idp=50)
## [inverse distance weighted interpolation]
spplot(cdIDW,"var1.pred")
spplot(cdIDW.1,"var1.pred")
spplot(cdIDW50,"var1.pred")
I want to do some Kriging on some of my own data. I will interpolate minimum temperature values in July from temperature sensors we placed across the landscape at a site. I realize that Kriging here ignores a lot of complex topography and is not going to give very accurate results, but I don’t care. I want to do it.
dat <- read.csv('mwaMonthJulTmin.csv')
coordinates(dat)<- c("LONG", "LAT")
proj4string(dat) <- CRS('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0')
plot(dat,axes=TRUE)
spplot(dat,"julTmin",colorkey=TRUE)
tempVar <- variogram(julTmin~1, dat)
plot(tempVar,pch=20,cex=1.5,col="black",
ylab=expression("Semivariance ("*gamma*")"),
xlab="Distance (m)", main = "July Min Temps (C)")
I couldn’t get any of the models to fit super well. It seemed like a Gaussian model might fit, but I just couldn’t get it to.
mat.model <- vgm(psill=0.25, model="Mat", range=0.25, nugget=0.1)
mat.fit <- fit.variogram(object = tempVar, model = mat.model)
## Warning in fit.variogram(object = tempVar, model = mat.model): Warning:
## singular model in variogram fit
plot(tempVar,pch=20,cex=1.5,col="black",
ylab=expression("Semivariance ("*gamma*")"),
xlab="Distance (m)", main = "July min temp",model=mat.fit)
I couldn’t go through with the Kriging because I am having a lot of trouble creating a SpatialPixelsDataFrame for the grid. It doesn’t seem like it should be that difficult but the ways I’ve tried have been fruitless. So I’ll finish this soon. Can someone help me with this?