The goal of mask is to provide a framework to detect spatial anomalies in multivariate spatio-temporal data (tensor data, multiway data). An anomaly is a spatial point or region that deviates significantly from the global and/or local distribution of a given network
You can install mask from github with:
# install.packages("devtools")
devtools::install_github("pridiltal/mask")
This is a basic example which shows you how to solve a common problem:
library(mask)
library(rrcov3way)
data(Arno)
result <- find_spatial_outlier(
data = Arno,
tensor_decom = "Tucker3")
p <- plot_spatial_outliers(X = result$out_data)
print(p)
library(tidyverse)
library(purrr)
data <- purrr::array_tree(Arno, 3) %>%
combine() %>%
as_tibble() %>%
setNames(., colnames(Arno)) %>%
mutate(
site = rep(rownames(Arno), dim(Arno)[3]),
time = rep(dimnames(Arno)[[3]], each = dim(Arno)[1]),
type = rep(result$out_data$type, dim(Arno)[3])
) %>%
pivot_longer(1:11, names_to = "ID")
p <- data %>% ggplot(aes(x = ID, y = value, colour = type, group = site)) +
geom_line() +
facet_wrap(~time, ncol = 1, scales = "free_y") +
scale_color_viridis_d()
print(p)