Calculate scan statistics on a time series of graphs. This is done by calculating the local scan statistics for each graph and each vertex, and then normalizing across the vertices and across the time steps.

## Usage

`scan_stat(graphs, tau = 1, ell = 0, locality = c("us", "them"), ...)`

## Arguments

- graphs
A list of igraph graph objects. They must be all directed or all undirected and they must have the same number of vertices.

- tau
The number of previous time steps to consider for the time-dependent normalization for individual vertices. In other words, the current locality statistics of each vertex will be compared to this many previous time steps of the same vertex to decide whether it is significantly larger.

- ell
The number of previous time steps to consider for the aggregated scan statistics. This is essentially a smoothing parameter.

- locality
Whether to calculate the ‘us’ or ‘them’ statistics.

- ...
Extra arguments are passed to

`local_scan()`

.

## Value

A list with entries:

- stat
The scan statistics in each time step. It is

`NA`

for the initial`tau + ell`

time steps.- arg_max_v
The (numeric) vertex ids for the vertex with the largest locality statistics, at each time step. It is

`NA`

for the initial`tau + ell`

time steps.

## See also

Other scan statistics:
`local_scan()`

## Examples

```
## Generate a bunch of SBMs, with the last one being different
num_t <- 20
block_sizes <- c(10, 5, 5)
p_ij <- list(p = 0.1, h = 0.9, q = 0.9)
P0 <- matrix(p_ij$p, 3, 3)
P0[2, 2] <- p_ij$h
PA <- P0
PA[3, 3] <- p_ij$q
num_v <- sum(block_sizes)
tsg <- replicate(num_t - 1, P0, simplify = FALSE) %>%
append(list(PA)) %>%
lapply(sample_sbm, n = num_v, block.sizes = block_sizes, directed = TRUE)
scan_stat(graphs = tsg, k = 1, tau = 4, ell = 2)
#> $stat
#> [1] NA NA NA NA NA NA
#> [7] -0.6430518 -0.1333833 1.3249501 -0.6311328 -1.9344336 8.1072330
#> [13] -0.5423048 -0.1962345 -0.8213035 -0.8134046 3.6565819 -1.1332366
#> [19] -1.0476453 23.1593272
#>
#> $arg_max_v
#> [1] NA NA NA NA NA NA 10 6 17 9 8 4 1 19 8 13 3 7 19 20
#>
scan_stat(graphs = tsg, locality = "them", k = 1, tau = 4, ell = 2)
#> $stat
#> [1] NA NA NA NA NA NA
#> [7] 0.1176407 -0.7463203 0.7536797 -1.0000000 -1.1785113 3.5000000
#> [13] -0.4378022 0.2412764 -0.6821704 0.5303301 1.1111678 -2.0000000
#> [19] -1.6499158 12.0739418
#>
#> $arg_max_v
#> [1] NA NA NA NA NA NA 4 6 5 9 18 6 8 4 15 15 3 3 4 20
#>
```