Apply the spatial decorrelation transformation to a data object. This object contains the transformed explanatory and response variables which can be used to fit a machine learning model. This object also contains information needed to decorrelate prediction data.

ssn_decorrelate_data(
  formula,
  ssn.object,
  tailup_params,
  taildown_params,
  euclid_params,
  nugget_params,
  additive,
  randcov_params,
  partition_factor,
  ordering,
  local,
  ...
)

Arguments

formula

A two-sided linear formula describing the fixed effect structure of the model, with the response to the left of the ~ operator and the terms on the right, separated by + operators. . on the right-hand side represents every variable in ssn.object$obs except the response and geometry column.

ssn.object

A spatial stream network object with class SSN.

tailup_params

A tailup_params() object giving the known tailup covariance parameters, or omitted/NULL for no tailup covariance (equivalent to tailup_type = "none").

taildown_params

A taildown_params() object giving the known taildown covariance parameters, or omitted/NULL for no taildown covariance (equivalent to taildown_type = "none").

euclid_params

A euclid_params() object giving the known Euclidean covariance parameters, or omitted/NULL for no Euclidean covariance (equivalent to euclid_type = "none"). Anisotropy is modeled automatically whenever euclid_params's rotate is nonzero or its scale is not one; there is no separate anisotropy argument.

nugget_params

A nugget_params() object giving the known nugget covariance parameter. Required (there is no default): every active covariance parameter, including the nugget, must be supplied and known.

additive

Additive-function variable for the tail-up covariance, as in ssn_lm().

randcov_params

A spmodel::randcov_params() object giving the known random-effect variances, or omitted/NULL for no random effects. The random effect grouping structure is derived automatically from its names; there is no separate random argument.

partition_factor

A one-sided linear formula with a single term specifying the partition factor. The partition factor assumes observations from different levels of the partition factor are uncorrelated.

ordering

The data ordering applied. Available options include "pid", "grts", "maxmin", "middleout", "outsidein", "coordinate", "random", and "none". "pid" applies ordering by point ID from the network geometry, with network ID used to break ties. "grts" applies ordering using a spatially balanced GRTS sample via spsurvey::grts(). "maxmin" applies maximum minimum distance ordering via GPvecchia::order_maxmin_exact(). "middleout" applies middle out ordering via GPvecchia::order_middleout(). "outsidein" applies outside in ordering via GPvecchia::order_outsidein(). "coordinate" applies coordinate ordering via GPvecchia::order_coordinate(..., coordinate = c(1, 2)), which orders from bottom-left to top-right of the spatial domain. "random" applies a completely random ordering. "none" applies no random ordering. The default is "pid". "maxmin", "middleout", "outsidein", and "coordinate" require GPvecchia; "grts" requires spsurvey.

local

An 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 ssn.object$obs) – 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 earlier observations in the ordering are used and size is ignored. If method = "covariance", the size data observations with the highest absolute covariance among earlier observations are used. The default is "covariance".

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

  • parallel: If TRUE, parallel processing via the parallel package is used. 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 to the functions called by algorithm.

Value

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

  • X: The original fixed effects design matrix (of explanatory variables)

  • y: The original response variable

  • tX: The spatially decorrelated transformed fixed effects design matrix

  • ty: The spatially decorrelated transformed response variable

Details

The spatial decorrelation transformation is a preprocessing transformation that reduces the impacts of spatial dependence (i.e., covariance, correlation) on machine learning models. See ssn_decorrelate() and Heaton et al., 2025 for more details.

References

Matthew J. Heaton, Andrew Millane, and Jake S. Rhodes. 2025. A Scalable Spatial Decorrelation Preprocessing Approach for Machine and Deep Learning. Journal of Data Science. 1-15, DOI 10.6339/25-JDS1210

Examples

# \donttest{
# Copy the mf04p .ssn data to a local directory and read it into R
# When modeling with your .ssn object, you will load it using the relevant
# path to the .ssn data on your machine
copy_lsn_to_temp()
temp_path <- paste0(tempdir(), "/MiddleFork04.ssn")
mf04p <- ssn_import(temp_path, overwrite = TRUE)
transformed <- ssn_decorrelate_data(
  Summer_mn ~ ELEV_DEM, mf04p, additive = "afvArea",
  tailup_params = tailup_params("exponential", de = 1, range = 10000),
  nugget_params = nugget_params("nugget", nugget = 0.1)
)
#> Error in ssn_decorrelate_data(Summer_mn ~ ELEV_DEM, mf04p, additive = "afvArea",     tailup_params = tailup_params("exponential", de = 1, range = 10000),     nugget_params = nugget_params("nugget", nugget = 0.1)): could not find function "ssn_decorrelate_data"
head(cbind(response = transformed$y, transformed = transformed$ty))
#> Error in eval(expr, envir, enclos): object 'transformed' not found
# }