# 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 <- cbind(field_1, field_2, field_3)
X <- as.matrix(field)
# white the data with the usual sample covariance
x_w_1 <- white_data(X)
# white the data with a ldiff matrix and ring kernel
kernel_params_ring <- c(0, 1)
ring_kernel_list <-
spatial_kernel_matrix(coords, 'ring', kernel_params_ring)
x_w_2 <- white_data(field, whitening = 'rob',
lcov = 'ldiff', kernel_mat = ring_kernel_list[[1]])
# Generate 5 % of global outliers to data
field_cont <- gen_glob_outl(field)[,1:3]
X <- as.matrix(field_cont)
# white the data using Hettmansperger-Randles location and scatter estimates
x_w_3 <- white_data(X, whitening = 'hr')
}
Run the code above in your browser using DataLab