Smoothing of “spatial” data

孤街浪徒 提交于 2019-12-21 20:53:25

问题


I have 2 variables x and y which are Cartesian coordinates at [0,1], and z is the value of a (continuous) variable at these coordinates. The z vector has some important outliers

x<-sample(seq(0,1,0.001), replace=F)
y<-sample(seq(0,1,0.001), replace=F)
z<-runif(1001,min=0,max=1)
z[100]<-8;z[400]<-16;z[800]<-4

These outliers I would like to emphasize when presenting these data in a filled.contour

I have used until now

library(akima)
a<-interp(x,y,z)
filled.contour(a$x,a$y,a$z)

But I am not happy with this linear interpolation. For example (the outliers do not show up correctly).

I am thinking what I need is a some kind nearest neighbor "spatial" smoothing of z (based on the x,y location). Can anyone help or pinpoint to data/examples/packages/code that could help me? I would prefer a base R solution but if ggplot2 or lattice can do my job it would be fine. Any other idea/proposal of better visualization would be also welcomed.


回答1:


Check out @Paul Heimstra's answer here. They suggest thin plate spline interpolation from the fields package. If kriging is right for you, the package automap may be useful.

If you're concerned with the interpolation of geographic values, it's worth mentioning DG Rossiter's online/free course on Geostatistics and Open-source statistical computing.




回答2:


Thin plate splines, or the Tps() function, from the fields package is a your ticket. The model results must then be placed into the predictSurface() function from the same package to generate smoothed spatial data. Just a few lines of code is all you need:

test.spline <- Tps(data.frame(x,y), z)
new.grid <- predictSurface(test.spline, nx = 200, ny = 200)
image(new.grid)

The nature of the data will define how fine a grid is appropriate. You control this with nx and ny arguments in predictSurface(). In this example, increased grid resolution has no impact. With real spatial data, smoothing with a high-res surface can be dramatic. Check function help for more details.



来源:https://stackoverflow.com/questions/13668110/smoothing-of-spatial-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!