predictTrgs: Impute response variables across the landscape

Description Usage Arguments Details Value See Also Examples

View source: R/predictTrgs.R

Description

This function finds the k-NN of target observations and imputes response variables. X is a raster object where each layer correspond to one of the predictor variable used to train the k-NN model model obtained from trainNN.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
predictTrgs(
  model = NULL,
  x = NULL,
  nrows = 200,
  nnID = TRUE,
  nnDist = TRUE,
  filename = "",
  par = FALSE,
  threads = 2,
  progress = TRUE,
  ...
)

Arguments

model

A trained kNN model obtained from trainNN

x

Raster object where each layer corresponds to a predictor variable calculated at targets

nrows

number of rows processed at a time. Default is 200 .

nnID

Logical. Should the ID of each target's nearest neighbor used for imputation be returned?

nnDist

Logical. Should the distance to each target's nearest neighbor used for imputation be returned?

filename

Character. Output file name including path to directory and eventually extension.Default is "" (output not written to disk).

par

Logical. Should imputation be performed on parallel threads?

threads

Integer. Number of parallel threads (relevant only if par=TRUE)

progress

Logical. If TRUE (default) a progress bar is displayed.

...

Other arguments passed to writeRaster

Details

The method used to impute the NN is set from the kNN model trained by trainNN. If k=1 the value of the single closest NN is imputed. If k>1, the closest, mean, median or weighted distance mean (default) of all k NN values is imputed. This is set using the impute.cont and impute.fac arguments of trainNN.

The raster x is processed as blocks of nrows to avoid creating very large objects (several Gb) that couldn't be stored in memory. However, low values of nrows slow down processing. Depending on the amount of RAM available on your computer and on the size of the area where k-NN need to be calculated, it is possible to process more rows at the same time and considerably reduce processing time.

Value

A RasterStack object where the first layers correspond to the imputed response variables and the remaining layers to the nearest neighbor(s) ID (if nnID = TRUE) and nearest neighbor(s) distance (if nnDist = TRUE)

See Also

newtargets, impute.yai

Examples

1
2
3
4
5
6
7
8
# Load data
# kNN_model: trained kNN model (from trainNN)
# X_vars: RasterStack of predictor variables
load(system.file("extdata/examples/example_predictTrgs.RData", package =
"foster"))

Y_imputed <- predictTrgs(model=kNN_model, x = X_vars, nnID = TRUE,
nnDist = TRUE)

foster documentation built on March 30, 2021, 5:11 p.m.