I have latitude and longitude point data over time. I would like to plot (in R or Matlab) a contour map of spatial-temporal K function (much like the one below), but have no ide
Here's how to compute space-time K-functions using the stkhat
function in the splancs
package. I make some random data on a space-time cube, then compute the soace-time K function estimate for a spatial range up to 0.3 distance units and 0.3 time units.
> require(splancs)
> xyt=matrix(runif(3000),ncol=3)
> poly=bboxx(spoints(c(0,1,0,1)))
> tlim=c(0,1)
> s=seq(0,.3,len=51)[-1]
> t=s
> stk = stkhat(xyt[,1:2], xyt[,3], poly, tlim, s,t)
> image(str$kst)
> require(lattice)
> image(x=stk$s, y=stk$t,z = stk$kst)
Here's an outline of how you might start this in R
. Note that this does not address the question of 'how to compute a spatial-temporal K function'.
First, get example data from plot raster with discrete colors using rasterVis
x=seq(-107,-106,.1)
y=seq(33,34,.1)
coords=expand.grid(x,y)
data1=data.frame(coords,depth=runif(nrow(coords),0,2))
names(data1)=c('x','y','value')
# get max and min values
xmn=min(data1[,1]); xmx=max(data1[,1])
ymn=min(data1[,2]); ymx=max(data1[,2])
Now compute an interpolated raster from the raw data...
# compute interpolated raster. Note that this is not the 'spatial-temporal K function' requested in the question, as pointed out in a comment below, but a linear interpolation
library(akima)
akima.li <- interp(data1[,1], data1[,2], data1[,3], duplicate = "median",
xo=seq(xmn,xmx, length=100),
yo=seq(ymn,ymx, length=100))
Plot the raster...
# plot interpolated raster
image(akima.li, col = rainbow(100, alpha = 1))
Plot the raster as a contour plot...
# plot interpolated contour
contour(akima.li, nlevels = 3)
Now put the raster and contour together and this is close to the example image you posted...
# put the raster and contours together
image(akima.li, col = rainbow(100, alpha = 1))
contour(akima.li, nlevels = 3, add = TRUE)
And with a few minor tweaks, here is a very close match to the style of the example...
image(akima.li, col = gray.colors(10, start = 0, end = 0.9, gamma = 2.2, alpha = 1))
contour(akima.li, nlevels = 3, add = TRUE)
Finally, this is pretty much a match, with grey-scale contour fill, contour labels but no contour lines
image(akima.li, col = gray.colors(10, start = 0, end = 1, gamma = 1, alpha = 1))
contour(akima.li, nlevels = 3, add = TRUE, lty = 0)
Well, I stumbled across your question, because I am myself dealing with this kind of analysis now. I don't know if you still need an answer, but one way of computing it is to use stpp package in R.
The function is named STIKhat and you can plot it using plotK.
The documentation is here. Its very easy to follow that's why I dont put it here. Hope it helps someone that might have the same question!