Predicting TPS from fields onto SpatialPixelsDataFrame object

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Predicting TPS from fields onto SpatialPixelsDataFrame object

Andy Bunn-4
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?

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Predicting TPS from fields onto SpatialPixelsDataFrame object

Roger Bivand
Administrator
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
> [hidden email]
> 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: [hidden email]
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway