# 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)
# Generate 5 % local outliers to data
field_cont <- gen_loc_outl(field, coords, radius = 2,
swap_order = "regular")[,1:3]
X <- as.matrix(field_cont)
# apply sbss with three ring kernels
kernel_parameters <- c(0, 1, 1, 2, 2, 3)
robsbss_result <-
robsbss(X, coords, kernel_type = 'ring', kernel_parameters = kernel_parameters)
# print object
print(robsbss_result)
# plot latent field
plot(robsbss_result, colorkey = TRUE, as.table = TRUE, cex = 1)
# predict latent fields on grid
predict(robsbss_result, colorkey = TRUE, as.table = TRUE, cex = 1)
# unmixing matrix
w_unmix <- coef(robsbss_result)
}
Run the code above in your browser using DataLab