pred.strk {meteo}R Documentation

Spatio-temporal regression kriging prediction

Description

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.

Usage

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,
          ...)

Arguments

data

STFDF-class, STSDF-class or data.frame; Contains dependent 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), time of the observation (time), observation value (obs) and covariates (cov1, cov2, ...). Covariate names should be the same as in the reg.coef (see below). If covariates are missing, overlay with newdata is tried. If overlay with newdata is not possible, then spatio-temporal ordinary kriging is performed.

zcol

numeric or character; Column name or number showing the position of dependent variable (observations) in data. Default is 1.

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 data if data is data.frame. Default is c(1,2,3,4).

obs

data.frame; Contains dependent variable (observations) and covariates in space and time. It should have next columns: station ID (staid), time of the observation (time), observation value (obs) and covariates (cov1, cov2, ...). This object is used together with stations (see below) to create STFDF-class object (if data object is missing) which is then used to perform STRK. If covariates are missing, spatio-temporal ordinary kriging is performed.

obs.staid.time

numeric or character vector; Positions or names of the station ID (staid) and time columns in obs. Default is c(1,2).

stations

data.frame; It should have next columns: station ID (staid), longitude (x) and latitude (y) of the stations. This object is used together with obs (see above) if data object is missing.

stations.staid.x.y

numeric or character vector; Positions or names of the station ID (staid), longitude (x) and latitude (y) columns in stations. Default is c(1,2,3).

newdata

STFDF-class, STSDF-class or data.frame; Contains prediction locations and covariates. If data.frame object, it should have next columns: prediction location ID (staid), longitude (x), latitude (y), time of the prediction (time) and covariates (cov1, cov2, ...). Covariate names should be the same as in the reg.coef (see below).

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 newdata. Default is c(1,2,3).

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 data (or obs) and newdata. Coefficients for metorological variables (temperature, precipitation, etc.) can be taken from data(tregcoef) or can be specified by the user.

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, sp.nmax will be used for each station prediction.

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 sp.nmax and time.nmax. If FALSE, temporal local kriging will be applied defined with time.nmax, and sp.nmax will be ignored.

ntiles

numeric; A number of tiles for tilling. Default is 64. Ideally, each tile should contain less observations than sp.nmax and observations fall in neighboring tiles.

output.format

character; Format of the output, "STFDF" (default), "STSDF" or "data.frame" (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.

Value

A STFDF-class, STSDF-class or data.frame object (depends on output.format argument), with columns:

pred

Predictions.

tlm

Trend.

var

Kriging variance, if computeVar=TRUE.

Author(s)

Milan Kilibarda kili@grf.bg.ac.rs, Aleksandar Sekulic asekulic@grf.bg.ac.rs

References

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.

See Also

tregcoef tvgms regdata meteo2STFDF tgeom2STFDF

Examples

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())


[Package meteo version 1.0-1 Index]