[R-sig-Geo] Predicting TPS from fields onto SpatialPixelsDataFrame object
Roger Bivand
Roger@B|v@nd @end|ng |rom nhh@no
Fri Apr 24 21:12:00 CEST 2020
On Fri, 24 Apr 2020, Andy Bunn wrote:
> Hi all, I'm used to using gstat for kriging surfaces from either sp or sf and stars objects. E.g., following the workflow below using meuse and meuse.grid. I'm curious how I can use Tps in the fields library. Given the zincTPSModel object below, how can I predict it onto meuse.grid? Thanks in advance, A
>
> library(sp)
> library(gstat)
> library(fields)
>
> # set up data
> data(meuse)
> data(meuse.grid)
> meuse$logZinc <- log(meuse$zinc)
> coordinates(meuse) <- ~x+y
> proj4string(meuse) <- CRS("+init=epsg:28992")
> coordinates(meuse.grid) <- ~x+y
> proj4string(meuse.grid) <- CRS("+init=epsg:28992")
> meuse.grid <- as(meuse.grid,"SpatialPixelsDataFrame")
>
> # kriging
> zincVar <- variogram(logZinc~1, meuse)
> zincVar <- variogram(logZinc~1, meuse)
> zincModel <- vgm(psill=0.6, model="Sph", range=750, nugget=0.05)
> zincFit <- fit.variogram(object = zincVar, model = zincModel)
> plot(zincVar,model=zincModel,pch=20,cex=1.5,col="black",
> ylab=expression("Semivariance ("*gamma*")"),
> xlab="Distance (m)", main = "Zinc concentrations (log(ppm))")
> zincKrige <- krige(formula = logZinc~1, locations = meuse,
> newdata = meuse.grid, model = zincFit)
> spplot(zincKrige,"var1.pred")
>
> # thin plate spline
> zincTPSModel <- Tps(coordinates(meuse), meuse$logZinc)
> # predict onto meuse.grid?
meuse.grid$Tps_pred <- c(predict(zincTPSModel, coordinates(meuse.grid)))
spplot(meuse.grid, "Tps_pred")
Roger
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: Roger.Bivand using nhh.no
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
More information about the R-sig-Geo
mailing list