bard | R Documentation |

Implements the BARD (Bayesian Abnormal Region Detector) procedure of Bardwell and Fearnhead (2017). BARD is a fully Bayesian inference procedure which is able to give measures of uncertainty about the number and location of anomalous regions. It uses negative binomial prior distributions on the lengths of anomalous and non-anomalous regions as well as a uniform prior for the means of anomalous regions. Inference is conducted by solving a set of recursions. To reduce computational and storage costs a resampling step is included.

```
bard(
x,
p_N = 1/(nrow(x) + 1),
p_A = 5/nrow(x),
k_N = 1,
k_A = (5 * p_A)/(1 - p_A),
pi_N = 0.9,
paffected = 0.05,
lower = 2 * sqrt(log(nrow(x))/nrow(x)),
upper = max(x),
alpha = 1e-04,
h = 0.25
)
```

`x` |
A numeric matrix with n rows and p columns containing the data which is to be inspected. The time series data classes ts, xts, and zoo are also supported. |

`p_N` |
Hyper-parameter of the negative binomial distribution for the length of non-anomalous segments (probability of success). Defaults to |

`p_A` |
Hyper-parameter of the negative binomial distribution for the length of anomalous segments (probability of success). Defaults to |

`k_N` |
Hyper-parameter of the negative binomial distribution for the length of non-anomalous segments (size). Defaults to 1. |

`k_A` |
Hyper-parameter of the negative binomial distribution for the length of anomalous segments (size). Defaults to |

`pi_N` |
Probability that an anomalous segment is followed by a non-anomalous segment. Defaults to 0.9. |

`paffected` |
Proportion of the variates believed to be affected by any given anomalous segment. Defaults to 5%. This parameter is relatively robust to being mis-specified and is studied empirically in Section 5.1 of \insertCitebardwell2017;textualanomaly. |

`lower` |
The lower limit of the the prior uniform distribution for the mean of an anomalous segment |

`upper` |
The upper limit of the prior uniform distribution for the mean of an anomalous segment |

`alpha` |
Threshold used to control the resampling in the approximation of the posterior distribution at each time step. A sensible default is 1e-4. Decreasing alpha increases the accuracy of the posterior distribution but also increases the computational complexity of the algorithm. |

`h` |
The step size in the numerical integration used to find the marginal likelihood.
The quadrature points are located from |

An instance of the S4 object of type `.bard.class`

containing the data `x`

, procedure parameter values, and the results.

This function gives certain default hyper-parameters for the two segment length distributions.
We chose these to be quite flexible for a range of problems. For non-anomalous segments a geometric distribution
was selected having an average segment length of `n`

with the standard deviation being of the same order.
For anomalous segments we chose parameters that gave an average length of 5 and a variance of `n`

.
These may not be suitable for all problems and the user is encouraged to tune these parameters.

bardwell2017anomaly

`sampler`

```
library(anomaly)
data(simulated)
# run bard
bard.res<-bard(sim.data, alpha = 1e-3, h = 0.5)
sampler.res<-sampler(bard.res)
collective_anomalies(sampler.res)
plot(sampler.res,marginals=TRUE)
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.