autoKrigeST: Performs an automatic spatiotemporal interpolation

View source: R/autoKrigeST.R

autoKrigeSTR Documentation

Performs an automatic spatiotemporal interpolation

Description

This function performs automatic spatiotemporal kriging on the given dataset. The variogram is generated automatically using autofitVariogramST.

Usage

autoKrigeST(formula,
                   input_data,
                   new_data,
                   type_stv = 'sumMetric',
                   data_variogram = input_data,
                   block = 0,
                   model = c("Sph", "Exp", "Gau", "Ste"),
                   kappa = c(0.05, seq(0.2, 2, 0.1), 5, 10),
				   fix.values = c(NA, NA, NA),
                   newdata_mode = 'rect',
				   newdata_npoints = 3e3,
                   GLS.model = NA,
          		   tlags = 0:6,
          		   cutoff = 2e4,
          		   width = 5e2,
                   predict_chunk = NULL,
                   nmax = Inf,
          		   aniso_method = 'vgm',
          		   type_joint = 'Exp',
          		   prodsum_k = 0.25,
          		   start_vals = c(NA, NA, NA),
                   miscFitOptions = list(),
                   measurement_error = c(0,0,0),
                   cores = 1,
                   verbose = TRUE)
                    

Arguments

formula

formula that defines the dependent variable as a linear model of independent variables; suppose the dependent variable has name 'z', for ordinary and simple kriging use the formula 'z~1'; for simple kriging also define 'beta' (see below); for universal kriging, suppose 'z' is linearly dependent on 'x' and 'y', use the formula 'z~x+y'.

input_data

A sftime, STI, STS or STF object containing the data to be interpolated.

new_data

A sftime, STI or STF object containing the prediction locations. Must not contain NA's. If this object is not provided a default is calculated. This is done by taking the convex hull of input_data and placing around 3000 gridcells in that convex hull.

data_variogram

An optional way to provide a different dataset for the building of the variogram then for the spatial interpolation.

block

Use this parameter to pass on a specification for the block size. e.g. c(1000,1000)

model

List of models that will be tested during automatic variogram fitting. Default values are "Sph", "Exp", "Gau", and "Ste"

kappa

List of values for the smoothing parameter of the Matern model that will be tested during automatic variogram fitting.

fix.values

Can be used to fix a variogram parameter to a certain value. It consists of a list with a length of three. The items describe the fixed value for the nugget, range and sill respectively. Setting the value to NA means that the value is not fixed. Is passed on to autofitVariogram.

newdata_mode

How the new data will be generated in shape. One of "rect" (rectangle) and "hull" (convex hull)

newdata_npoints

The number of points will be generated in the extent of the new data

GLS.model

If a variogram model is passed on through this parameter a Generalized Least Squares sample variogram is calculated.

tlags

The range of time lags for fitting STVariogram

cutoff

The maximum range of spatial lags for fitting STVariogram

width

The interval for fitting spatial part of the STVariogram

predict_chunk

The number of chunks to predict values in 'new_data'. If this value is not 'NULL', the new data will be split into chunks in size of 'predict_chunk' and the prediction will be done per chunk.

nmax

The maximum number of spatiotemporal neighborhood to make predictions (not stable)

aniso_method

The method to estimate the spatiotemporal anisotropy (one of linear, range, vgm, or metric)

type_joint

The type of theoretical model of the joint spatiotemporal variogram. Only applied when joint type of spatiotemporal variogram is chosen.

prodsum_k

k value for stModel in vgmST is productSum. See vgmST for more.

start_vals

Can be used to give the starting values for the variogram fitting. The items describe the fixed value for the nugget, range and sill respectively. They need to be given in that order. Setting the value to NA means that the value will be automatically chosen.

miscFitOptions

Additional options to set the behavior of autofitVariogram. For details see the documentation of autofitVariogram.

measurement_error

integer vector (3). Adds measurement error components for spatial, temporal, and joint spatiotemporal variogram models, respectively. IT IS HIGHLY EXPERIMENTAL. MAY RESULT IN ERRORS.

cores

The number of cores to be used for estimating variogramST. See variogramST for more detail.

verbose

logical, if TRUE autoKrige will give extra information on the fitting process. Default is TRUE.

Details

autoKrigeST calls the function autofitVariogramST that fits a spatiotemporal variogram model to the given dataset. This variogram model and the data are used to make predictions on the spatiotemporal locations in new_data. If new_data is not specified, an internal function will automatically generate a new ST*DF data to perform the spatiotemporal interpolation.

Value

This function returns an autoKrige object containing the results of the interpolation (prediction, variance and standard deviation), the sample variogram, the variogram model that was fitted by autofitVariogram and the sums of squares between the sample variogram and the fitted variogram model. The attribute names are krige_output, exp_var, var_model and sserr respectively.

Author(s)

Insang Song, sigmafelix@hotmail.com

See Also

autofitVariogramST, krigeST

Examples

# The first part of the example is from the example of krigeST
library(spacetime)
library(sp)
library(stars)
library(sftime)
data(air)
stations = st_as_sf(stations)
stations = st_transform(stations, 'EPSG:3857')

airdf = data.frame(PM10 = as.vector(air))
stations_full = do.call(c, rep(stations, length(dates)))
dates_full = rep(dates, each = nrow(stations))

rural = cbind(airdf, time = dates_full, stations_full)

#ruralsft = st_as_stars(airdf, time = dates)
rural = st_as_sftime(rural, sf_column_name = 'geometry')

rr <- rural[which(rural$time 
air.stk <- autoKrigeST(formula = PM10~1,
                       input_data = rr,
                       type_stv = 'sumMetric',
                       tlags = 0:7,
                       model = c('Mat', 'Ste', 'Wav', 'Exp', 'Exc'),
                       cutoff = 3e5,
                       width = 3e4,
                       cores = 4)
plot(st_as_stars(air.stk[[1]])[1,], pch = 19, cex = 0.5)
    

sigmafelix/autoSTK documentation built on May 2, 2024, 11:23 a.m.