Description Usage Arguments Details Value See Also Examples
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
.
1 2 3 4 5 6 7 8 9 10 11 12 |
model |
A trained kNN model obtained from |
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 |
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 |
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.
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
)
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.