predict.sbss {SpatialBSS} | R Documentation |
Predict Method for an Object of Class 'sbss'
Description
predict.sbss
predicts the estimated source random field on a grid with Inverse Distance Weighting (IDW) and plots these predictions.
Usage
## S3 method for class 'sbss'
predict(object, p = 2, n_grid = 50, which = 1:ncol(object$s), ...)
Arguments
object |
object of class |
p |
numeric. The positive power parameter for IDW. Default is 2. |
n_grid |
numeric. Each dimension of the spatial domain is divided by this integer to derive a grid for IDW predictions. Default is 50. |
which |
a numeric vector indicating which components of the latent field should be predicted. |
... |
further arguments to the plot method of |
Details
IDW predictions are made on a grid. The side lengths of the rectangular shaped grid cells are derived by the differences of the rounded maximum and minimum values divided by the n_grid
argument for each column of object$coords
. Hence, the grid contains a total of n_grid ^ 2
points. The power parameter of the IDW predictions is given by p
(default: 2).
The predictions are plotted with the corresponding plot method of class(x$s)
. Either spplot
for class(x$s)
is SpatialPointsDataFrame
or plot.sf
for class(x$s)
is sf
. If x$s
is a matrix then it is internally cast to SpatialPointsDataFrame
and spplot
is used for plotting. Arguments to the corresponding plot functions can be given through ...
as it is done by the method plot.sbss
.
Value
The return is dependent on the class of the latent field in the 'sbss'
object.
If class(object$s)
is a matrix then a list with the following entries is returned:
vals_pred_idw |
a matrix of dimension |
coords_pred_idw |
a matrix of dimension |
If class(object$s)
is SpatialPointsDataFrame
or sf
then the predicted values and their coordinates are returned as an object of the corresponding class.
The return is invisible.
See Also
sbss
, plot.sbss
, spplot
, plot.sf
Examples
# simulate coordinates
coords <- runif(1000 * 2) * 20
dim(coords) <- c(1000, 2)
coords_df <- as.data.frame(coords)
names(coords_df) <- c("x", "y")
# simulate random field
if (!requireNamespace('gstat', quietly = TRUE)) {
message('Please install the package gstat to run the example code.')
} else {
library(gstat)
model_1 <- gstat(formula = z ~ 1, locations = ~ x + y, dummy = TRUE, beta = 0,
model = vgm(psill = 0.025, range = 1, model = 'Exp'), nmax = 20)
model_2 <- gstat(formula = z ~ 1, locations = ~ x + y, dummy = TRUE, beta = 0,
model = vgm(psill = 0.025, range = 1, kappa = 2, model = 'Mat'),
nmax = 20)
model_3 <- gstat(formula = z ~ 1, locations = ~ x + y, dummy = TRUE, beta = 0,
model = vgm(psill = 0.025, range = 1, model = 'Gau'), nmax = 20)
field_1 <- predict(model_1, newdata = coords_df, nsim = 1)$sim1
field_2 <- predict(model_2, newdata = coords_df, nsim = 1)$sim1
field_3 <- predict(model_3, newdata = coords_df, nsim = 1)$sim1
field <- as.matrix(cbind(field_1, field_2, field_3))
# apply sbss with three ring kernels
kernel_borders <- c(0, 1, 1, 2, 2, 4)
res_sbss <- sbss(field, coords, 'ring', kernel_borders)
# predict latent fields on grid with default settings
predict(res_sbss)
# predict latent fields on grid with custom plotting settings
predict(res_sbss, colorkey = TRUE, as.table = TRUE, cex = 1)
# predict latent fields on a 60x60 grid
predict(res_sbss, n_grid = 60, colorkey = TRUE, as.table = TRUE, cex = 1)
# predict latent fields with a higher IDW power parameter
predict(res_sbss, p = 10, colorkey = TRUE, as.table = TRUE, cex = 1)
# predict latent fields and save the predictions
predict_list <- predict(res_sbss, p = 5, colorkey = TRUE, as.table = TRUE, cex = 1)
}