# simulate coordinates
n <- 1000
coords <- runif(n * 2) * 20
dim(coords) <- c(n, 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)
field_1 <- predict(model_1, newdata = coords_df, nsim = 1)$sim1
field_2 <- predict(model_2, newdata = coords_df, nsim = 1)$sim1
field_3 <- rnorm(n)
field_4 <- rnorm(n)
latent_field <- cbind(as.matrix(cbind(field_1, field_2)), field_3, field_4)
mixing_matrix <- matrix(rnorm(16), 4, 4)
observed_field <- latent_field %*% t(mixing_matrix)
# apply the bootstrap tests for a hypothetical latent white noise dimension of q
# q can lie between 0 and 3 in this case
# using one ring kernel function with the permute strategy
# and the null hypothesis q = 1
boot_res_1 <-
sbss_boot(observed_field, coords, q = 1, kernel_parameters = c(0, 1),
boot_method = 'permute', n_boot = 100)
# using two one ring kernel function with the parametric strategy
# and the null hypothesis q = 3
boot_res_2 <-
sbss_boot(observed_field, coords, q = 3, kernel_parameters = c(0, 1, 1, 2),
boot_method = 'parametric', n_boot = 100)
# the result is of class sbss_test which is inherited from htest and sbss
# print object (print method for an object of class htest)
print(boot_res_1)
print(boot_res_2)
# plot latent field (plot method for an object of class sbss)
plot(boot_res_1, colorkey = TRUE, as.table = TRUE, cex = 1)
# predict latent fields on grid (predict method for an object of class sbss)
predict(boot_res_1, colorkey = TRUE, as.table = TRUE, cex = 1)
# unmixing matrix (coef method for an object of class sbss)
w_unmix <- coef(boot_res_1)
}
Run the code above in your browser using DataLab