1

I have one month of data that I converted to STDFDF.

#set the spatial location of the regions
Data.loc <- data.frame(Stat = c("Firmo","Citta dei Ragazzi", "Rende",
                              "Schiavonea","Acri"),
                     ID = c("IT1766A", "IT1938A", "IT2086A",
                              "IT2090A", "IT2110A"),
                     Lat=c(39.71376, 39.3134, 39.33893,
                           39.65176, 39.48963),
                     Lon=c(16.19397, 16.24517, 16.24334,
                           16.54677, 16.3868))
coordinates(Data.loc) = ~Lon+Lat
proj4string(Data.loc) = "+proj=longlat +datum=WGS84"

stations = 4:8
Data.loc = Data.loc[match(names(combineData[stations]), Data.loc$Stat),]
Data.loc$Station = row.names(Data.loc)

combineData$time = ISOdate(combineData$Year, combineData$Month, combineData$Day, 0)

dataObj = STFDF(Data.loc, combineData$time, 
                data.frame(values = as.vector(t(combineData[stations]))))

Sample data: DATA

I save my final pred_kriged object when I use the METRIC MODEL

# Kriging Prediction
#---------------------------
pred_kriged <- krigeST(values ~ 1,
                       data = dataObj, # data set
                       newdata = ST_pred, # prediction grid
                       modelList = metricFit, # best fitted semivariogram
                       computeVar = TRUE) # compute variances

Space-time kriging is realized and I want to extract data for other unknown points (long, lat) before kriging for the same period for each day.

1
  • 1
    You should probably add some information about how you've created this object, and maybe show your workflow up to this point. It seems to be a space-time prediction grid already, and if you want to predict at other locations you need to do that when you predict on the grid by supplying the space-time coordinates at the kriging prediction stage.
    – Spacedman
    Commented Apr 3, 2023 at 15:57

1 Answer 1

0

You need to specify prediction locations when you call krigeST with the newdata parameter. It looks like your output here was created with newdata being a grid over your space, but you can specify any space-time object (not necessarily a grid) and get predictions at those locations.

For example, the help for krigeST creates DE_kriged as predictions over a grid once it has got its variogram, but you can create a set of points and predict at those locations. I'll create 10 random points at the three time points in the data:

### points over bounds of data
xy = data.frame(
    x = runif(10, 5.5, 15.5),
    y = runif(10, 47.5, 55.5)
)
coordinates(xy) = ~x+y

### rr comes from the example code
proj4string(xy) = proj4string(rr)

### take the three dates randomly
times = sample(c("2005-06-01","2005-06-02","2005-06-02"), 10, TRUE)

### create a set of space-time points, sorted by time:
stpts = STI(xy, sort(as.Date(times)))

Now we can use krigeST to predict at those locations instead of the DE_kriged grid locations:

pts_kriged <- krigeST(PM10~1, data=rr, newdata=stpts, modelList=sumMetricVgm,
                      computeVar=TRUE)

Which produces a STIDF with the prediction and variance at those locations:

> pts_kriged
An object of class "STIDF"
Slot "data":
   var1.pred var1.var
1   12.31332 30.41005
2   13.63335 33.60311
3   17.75493 45.91366
4   14.76074 54.78252
5   17.16476 48.82819
6   15.20627 35.21975
7   14.05065 27.47846
8   19.11712 30.63970
9   19.62724 36.37277
10  17.38218 25.76576
[ etc, with locations and times ]

This is probably more complicated if your data has covariates since you have to have your new data with covariates too, but this is the principle. Feed your prediction locations as newdata to krigeST.

4
  • I couldn't understand the phrase "I'll create 10 random points at the three time points in the data". Finding values at one point per month is what I am interested in. Commented Apr 3, 2023 at 19:28
  • cava <- data.frame(Lon = 16.44529, Lat = 39.495616) coordinates(cava) <- ~Lon+Lat proj4string(cava) <- proj4string(dataObj) times <- seq(as.POSIXct("2021-07-01 00:00:00 UGT"), as.POSIXct("2021-07-31 00:00:00 UGT"), length.out=31) stpts = STF(cava, sort(as.POSIXct(times))) pts_kriged <- krigeST(values~1, data=dataObj, newdata=stpts, modelList=metricFit, computeVar=TRUE) pts_kriged Commented Apr 3, 2023 at 19:31
  • Not knowing what locations you wanted to predict at I made a most general example. Does that code you posted in the comment above do the equivalent of what you want to do with your data using the sample data?
    – Spacedman
    Commented Apr 3, 2023 at 19:43
  • Yes, I'm only interested in one point of "cava" per month. It seems to work, make it up right? Commented Apr 3, 2023 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.