pred.strk | R Documentation |
Function for spatio-temporal regression kriging prediction based on krigeST.
pred.strk(data,
obs.col=1,
data.staid.x.y.z = NULL,
newdata,
newdata.staid.x.y.z = NULL,
z.value = NULL,
crs = NA,
zero.tol=0,
reg.coef,
vgm.model,
sp.nmax=20,
time.nmax=2,
by='time',
tiling= FALSE,
ntiles=64,
output.format = "STFDF",
parallel.processing = FALSE,
pp.type = "snowfall",
cpus=detectCores()-1,
computeVar=FALSE,
progress=TRUE,
...)
data |
STFDF-class, STSDF-class, STIDF-class, sf-class, sftime-class, SpatVector-class or data.frame; Contains target variable (observations) and covariates in space and time used to perform STRK. If data.frame object, it should have next columns: station ID (staid), longitude (x), latitude (y), 3rd component - time, depth, ... (z) of the observation, observation value (obs), and covariates (cov1, cov2, ...). Covariate names should be the same as in the |
obs.col |
numeric or character; Column name or number showing position of the observation column in the |
data.staid.x.y.z |
numeric or character vector; Positions or names of the station ID (staid), longitude (x), latitude (y) and 3rd component - time, depth (z) columns in data.frame object (e.g. c(1,2,3,4)). If |
newdata |
STFDF-class, STSDF-class, STIDF-class, sf-class, sftime-class, SpatVector-class, SpatRaster-class or data.frame; Contains prediction locations and covariates used for STRK prediction. If data.frame object, it should have next columns: prediction location ID (staid), longitude (x), latitude (y), 3rd component - time, depth, ... (z), and covariates (cov1, cov2, ...). Covariate names have to be the same as in the |
newdata.staid.x.y.z |
numeric or character vector; Positions or names of the prediction location ID (staid), longitude (x), latitude (y) and 3rd component (z) columns in data.frame |
z.value |
vector; A vector of 3rd component - time, depth, ... (z) values if |
crs |
st_crs or crs; Source CRS of |
zero.tol |
numeric; A distance value below (or equal to) which locations are considered as duplicates. Default is 0. See rm.dupl. Duplicates are removed to avoid singular covariance matrices in kriging. |
reg.coef |
numeric; Vector of named linear regression coefficients. Names of the coefficients (e.g. "Intercept", "temp_geo", "modis", "dem", "twi") will be used to match appropriate covariates from |
vgm.model |
StVariogramModel list; Spatio-temporal variogram of regression residuals (or observations if spatio-temporal ordinary kriging). See vgmST. Spatio-temporal variogram model on residuals for metorological variables (temperature, precipitation, etc.) can be taken from data(tvgms) or can be specified by the user as a vgmST object. |
sp.nmax |
numeric; A number of spatially nearest observations that should be used for kriging predictions. If |
time.nmax |
numeric; A number of temporally nearest observations that should be used for kriging predictions Deafult is 2. |
by |
cahracter; Will foreach loop by time (default) or station. If station is set, |
tiling |
logical; Should simplified local kriging be used. Default is FALSE. If TRUE, area is divided in tiles and kriging calculation is done for each tile separately. Number of observation used per tile is defined with |
ntiles |
numeric; A number of tiles for tilling. Default is 64. Ideally, each tile should contain less observations than |
output.format |
character; Format of the output, STFDF-class (default), STSDF-class, STIDF-class, data.frame, sf-class, sftime-class, SpatVector-class, or SpatRaster-class. |
parallel.processing |
logical; If parallel processing is performed. Default is FALSE. |
pp.type |
character; Type ( |
cpus |
numeric; Number of processing units. Default is detectCores()-1. |
computeVar |
logical; If kriging variance is computed. Default is FALSE. |
progress |
logical; If progress bar is shown. Default is TRUE. |
... |
Further arguments passed to krigeST function. |
A STFDF-class, STSDF-class, STIDF-class, data.frame, sf-class, sftime-class, SpatVector-class, or SpatRaster-class object (depends on output.format
argument), with columns (elements):
pred |
Predictions. |
tlm |
Trend. |
var |
Kriging variance, if |
Milan Kilibarda kili@grf.bg.ac.rs, Aleksandar Sekulic asekulic@grf.bg.ac.rs
Kilibarda, M., T. Hengl, G. B. M. Heuvelink, B. Graeler, E. Pebesma, M. Percec Tadic, and B. Bajat (2014), Spatio-temporal interpolation of daily temperatures for global land areas at 1 km resolution, J. Geophys. Res. Atmos., 119, 2294-2313, doi:10.1002/2013JD020803.
tregcoef
tvgms
regdata
meteo2STFDF
tgeom2STFDF
library(sp)
library(spacetime)
library(sf)
library(gstat)
library(plyr)
# prepare data
# load observation - data.frame of mean temperatures
# preparing data
data(dtempc)
data(stations)
data(regdata) # covariates, made by mete2STFDF function
regdata@sp@proj4string <- CRS('+proj=longlat +datum=WGS84')
lonmin=18 ;lonmax=22.5 ; latmin=40 ;latmax=46
serbia = point.in.polygon(stations$lon, stations$lat, c(lonmin,lonmax,lonmax,lonmin),
c(latmin,latmin,latmax,latmax))
st = stations[ serbia!=0, ] # stations in Serbia approx.
obs.staid.time = c("staid", "time")
stations.staid.lon.lat = c(1,2,3)
crs = CRS('+proj=longlat +datum=WGS84')
delta = NULL
# create STFDF
stfdf <- meteo2STFDF(obs = dtempc,
stations = st,
crs = crs)
# Calculate prediction of mean temperatures for "2011-07-05" and "2011-07-06"
# global model is used for regression and variogram
# load precalculated variograms
data(tvgms) # ST variogram models
data(tregcoef) # MLR coefficients
### Example with STFDF and without parallel processing
results <- pred.strk(data = stfdf, # observations
newdata = regdata, # prediction locations with covariates
# newdata = regdata[,2,drop=FALSE], # for one day only
output.format = "STFDF", # data.frame | sf | sftime | SpatVector | SpatRaster
reg.coef = tregcoef[[1]], # MLR coefficients
vgm.model = tvgms[[1]], # STRK variogram model
sp.nmax = 20,
time.nmax = 2,
computeVar=TRUE
)
class(results)
# plot prediction
results@sp=as(results@sp,'SpatialPixelsDataFrame')
stplot(results[,,"pred", drop= FALSE], col.regions=bpy.colors())
stplot(results[,,"var", drop= FALSE], col.regions=bpy.colors())
# Example with data.frames and parallel processing - SpatRaster output
library(terra)
library(doParallel)
# create data.frame
stfdf.df <- join(dtempc, st)
summary(stfdf.df)
regdata.df <- as.data.frame(regdata)
results <- pred.strk(data = stfdf.df,
obs.col = 3,
data.staid.x.y.z = c(1,4,5,2),
newdata = regdata.df,
newdata.staid.x.y.z = c(3,1,2,4),
crs = CRS("EPSG:4326"),
output.format = "SpatRaster", # STFDF |data.frame | sf | sftime | SpatVector
reg.coef = tregcoef[[1]],
vgm.model = tvgms[[1]],
sp.nmax = 20,
time.nmax = 2,
parallel.processing = TRUE,
pp.type = "doParallel", # "snowfall"
cpus = 2, # detectCores()-1,
computeVar = TRUE,
progress = TRUE
)
# plot prediction
plot(results$`2011-07-06`[["pred"]])
plot(results$`2011-07-06`[["var"]])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.