Apply the spatial decorrelation transformation to a newdata object. This object contains explanatory variables that are transformed for prediction accoring to some spatial decorrelation transformation.

decorrelate_newdata(object, newdata, local, ...)

Arguments

object

A decorrelate_data() object.

newdata

A data frame or sf object in which to look for variables with which to predict. If a data frame, newdata must contain all variables used by formula(object) and all variables representing coordinates. If an sf object, newdata must contain all variables used by formula(object) and coordinates are obtained from the geometry of newdata. If omitted, missing data from the fitted model object are used.

local

A optional logical or list controlling the big data approximation. If omitted, local is set to TRUE or FALSE based on the sample size (the number of non-missing observations in data) – if the sample size exceeds 5,000, local is set to TRUE. Otherwise it is set to FALSE. If local is FALSE, no big data approximation is implemented. If a list is provided, the following arguments detail the big data approximation:

  • method: The big data approximation method. If method = "all", all observations are used and size is ignored. If method = "distance", the size data observations closest (in terms of Euclidean distance) to the observation requiring prediction are used. If method = "covariance", the size data observations with the highest covariance with the observation requiring prediction are used. If random effects and partition factors are not used in estimation and the spatial covariance function is monotone decreasing, "distance" and "covariance" are equivalent. The default is "covariance".

  • size: The number of data observations to use when method is "distance" or "covariance". The default is 30.

  • parallel: If TRUE, parallel processing via the parallel package is automatically used. This can significantly speed up computations even when method = "all" (i.e., no big data approximation is used), as predictions are spread out over multiple cores. The default is FALSE.

  • ncores: If parallel = TRUE, the number of cores to parallelize over. The default is the number of available cores on your machine.

When local is a list, at least one list element must be provided to initialize default arguments for the other list elements. If local is TRUE, defaults for local are chosen such that local is transformed into list(size = 30, method = "covariance", parallel = FALSE).

...

Other arguments.

Value

A list with many elements that store information about the fitted model object. Importantly, the list contains the following element:

  • X_newdata: The original fixed effects design matrix (of explanatory variables) for the prediction data.

  • tX_newdata: The spatially decorrelated fixed effects design matrix for the prediction data.

Examples

params <- spcov_params("exponential", de = 1, ie = 0.2, range = 1e5)
decorr <- decorrelate_data(log_cond ~ temp, data = lake, spcov_params = params)
decorr_newdata <- decorrelate_newdata(decorr, newdata = lake_preds)
head(decorr_newdata$tX_newdata)
#>   (Intercept)       temp
#> 1  0.04398591  3.5517590
#> 2  0.35364443  8.3422812
#> 3  0.25028363  1.6737532
#> 4  0.52145903  1.6198005
#> 5  0.47443063  0.4568461
#> 6  0.07631950 -1.1911105