pred.strk {meteo} | R Documentation |
Function for spatio-temporal regression kriging prediction based on krigeST. The prediction is made for raster objects, i.e. for STFDF-class, STSDF-class, or for data.frame objects.
pred.strk(data, zcol=1, data.staid.x.y.time = c(1,2,3,4), obs, obs.staid.time = c(1,2), stations, stations.staid.x.y = c(1,2,3), newdata, newdata.staid.x.y.time = c(1,2,3), 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 or |
zcol |
numeric or character; Column name or number showing the position of dependent variable (observations) in |
data.staid.x.y.time |
numeric or character vector; Positions or names of the station ID (staid), longitude (x), latitude (y) and time columns in |
obs |
|
obs.staid.time |
numeric or character vector; Positions or names of the station ID (staid) and time columns in |
stations |
|
stations.staid.x.y |
numeric or character vector; Positions or names of the station ID (staid), longitude (x) and latitude (y) columns in |
newdata |
STFDF-class, STSDF-class or |
newdata.staid.x.y.time |
numeric or character vector; Positions or names of the prediction location ID (staid), longitude (x), latitude (y) and time columns in |
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 |
named numeric vector; 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 /codetiling is TRUE (see below), then is a number of spatially nearest observations that should be used for each tile. Deafult is 20. |
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" (default), "STSDF" or "data.frame" ( |
parallel.processing |
logical; If parallel processing is performed. Default is FALSE. |
pp.type |
character; Type (R package) of parallel processing, "snowfall" (default) or "doParallel". |
cpus |
numeric; Number of processing units. Default is detectCores()-1. |
computeVar |
logical; If kriging variance is computed. Ddefault is FALSE. |
progress |
logical; If progress bar is shown. Default is TRUE. |
... |
Further arguments passed to krigeST. |
A STFDF-class, STSDF-class or data.frame
object (depends on output.format
argument), with columns:
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(gstat) library(plyr) # prepare data # load observation - data.frame of mean temperatures data(dtempc) data(stations) serbia= point.in.polygon(stations$lon, stations$lat, c(18,22.5,22.5,18), c(40,40,46,46)) st= stations[ serbia!=0, ] dtempc <- dtempc[dtempc$staid %in% st$staid, ] dtempc <- dtempc[complete.cases(dtempc),] # create STFDF stfdf <- meteo2STFDF(dtempc,st) # Adding CRS stfdf@sp@proj4string <- CRS('+proj=longlat +datum=WGS84') # load covariates for mean temperatures data(regdata) # str(regdata) regdata@sp@proj4string <- CRS('+proj=longlat +datum=WGS84') # Calculate prediction of mean temperatures for "2011-07-06" # global model is used for regression and variogram # load precalculated variograms data(tvgms) data(tregcoef) results <- pred.strk(data = stfdf, newdata = regdata[,2,drop=FALSE], # newdata = regdata[,,drop=FALSE], output.format = "stfdf", reg.coef = tregcoef[[1]], vgm.model = tvgms[[1]], sp.nmax = 20, time.nmax = 2, computeVar=TRUE ) # plot prediction 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 library(snowfall) library(doParallel) # create data.frames stfdf.df <- join(dtempc, st) regdata.df <- as.data.frame(regdata) results <- pred.strk(data = stfdf.df, zcol=3, data.staid.x.y.time = c(1,4,5,2), # obs = stfdf.df, # if used, comment data argument # obs.staid.time = c(1,2), # stations = stfdf.df, # stations.staid.x.y = c(1,4,5), newdata = regdata.df[regdata.df$time=="2011-07-06", ], # newdata = regdata.df, newdata.staid.x.y.time = c(3,1,2,4), reg.coef = tregcoef[[1]], vgm.model = tvgms[[1]], sp.nmax = 20, time.nmax = 2, parallel.processing = TRUE, pp.type = "snowfall", # "doParallel" cpus=detectCores()-1, computeVar=TRUE, progress=TRUE ) # plot prediction stplot(results[,,"pred", drop=FALSE], col.regions=bpy.colors()) # stplot(results[,,"var", drop=FALSE], col.regions=bpy.colors())