Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/binningDepth2d.R

A robust method of decreasing a sample size and therefore a complexity of a statistical procedure. The method may be used within a kernel density or a predictive distribution estimation.

1 2 3 4 5 6 7 8 | ```
binningDepth2D(
x,
binmethod = "LocDepth",
nbins = 8,
k = 1,
remove_borders = FALSE,
depth_params = list(method = "LP")
)
``` |

`x` |
bivariate matrix containing data. Each row is viewed as one two-dimensional observation. |

`binmethod` |
A method for calculation center and dispersion measures. "LocDepth" uses location-scale depth, MAD uses median and MAD in each dimension. |

`nbins` |
number of bins in each dimension |

`k` |
responsible for tightness of bins. |

`remove_borders` |
Logical, include or not marginal bins |

`depth_params` |
other arguments passed to depthMedian |

Let us recall, that binning is a popular method of decreasing a sample size. To bin a window of * n * points * {W}_{i, n} = ≤ft\{ {X}_{i - n + 1}, ..., {X}_{i} \right\} * to a grid * {{{X}'}_{1}}, ..., {{{X}'}_{m}} * we simply assign each sample point * {{X}_{i}} * to the nearest grid point * {{{X}'}_{j}} *. When binning is completed, each grid point * {{X}'}_{j} * has an associated number * {c}_{i} *, which is the sum of all the points that have been assigned to * {{X}'}_{j} *. This procedure replaces the data * {W}_{i, n} = ≤ft\{ {X}_{i - n + 1}, ..., {X}_{i} \right\} * with the smaller set * {{W}'}_{j, m} = ≤ft\{ {{X}'}_{j - m + 1}, ..., {{X}'}_{j} \right\} *. Although simple binning can speed up the computation, it is criticized for a lack of precise approximate control over the accuracy of the approximation. Robust binning however stresses properties of the majority of the data and decreases the computational complexity of the DSA at the same time.

For a 1D window * {W}_{i, n} *, let * {Z}_{i, n - k} * denote a 2D window created basing on * {W}_{i, n} * and consisted of * n - k * pairs of observations and the * k * lagged observations * {Z}_{i, n - k} = ≤ft\{≤ft( {X}_{i - n - k}, {X}_{i - n + 1} \right)\right\}, 1≤ i≤ n - k *. Robust 2D binning of the * {Z}_{i, n - p} * is a very useful technique in a context of robust estimation of the predictive distribution of a time series (see Kosiorowski:2013b).

Assume we analyze a data stream * \{{X}_{t}\} * using a moving window of a fixed length * n *, i.e., * {W}_{i, n} * and the derivative window * {Z}_{i, n - 1} *. In a first step we calculate the weighted sample * L ^ p * depth for * {W}_{i, n} *. Next we choose equally spaced grid of points * {l}_{1}, ..., {l}_{m} * in this way that * [{{l}_{1}}, {{l}_{m}}] \times [{{l}_{1}}, {{l}_{m}}] * covers fraction of the * β * central points of * {Z}_{i, n - 1} * w.r.t. the calculated * L ^ p * depth, i.e., it covers * {R} ^ {β}({Z}_{i, n - 1}) * for certain prefixed threshold * β \in (0, 1) *. For both * {X}_{t} * and * {X}_{t - 1} * we perform a simple binning using following bins: * (-∞, {l}_{1}) *, * ({l}_{1}, {l}_{2}) *, ..., * ({l}_{m}, ∞) *. For robust binning we reject "border" classes and further use only midpoints and binned frequencies for classes * ({l}_{1}, {l}_{2}) *, * ({l}_{2}, {l}_{3}) *, ..., * ({l}_{m - 1}, {l}_{m}) *.

freq: a matrix containing the binned frequencies

mid_x: mid points for x

mid_y: mid points for y

breaks_x: breaks for x

breaks_y: breaks for y

input_data: max_depth_x and max_depth_y:

Daniel Kosiorowski and Zygmunt Zawadzki from Cracow University of Economics.

Hall, P., Wand, M. P. (1996) On the Accuracy of Binned Kernel Density Estimators, Journal of Multivariate Analysis archive, Volume 56 Issue 2, 165–184

Holmstrom, L. (2000) The Accuracy and the Computational Complexity of a Multivariate Binned Kernel Density Estimator, Journal of Multivariate Analysis, Volume 72, Issue 2, 264–309, doi: 10.1006/jmva.1999.1863. (https://www.sciencedirect.com/science/article/pii/S0047259X99918638)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ```
# EXAMPLE 1
Sigma1 <- matrix(c(10, 3, 3, 2), 2, 2)
X1 <- mvrnorm(n = 8500, mu = c(0, 0), Sigma1)
Sigma2 <- matrix(c(10, 0, 0, 2), 2, 2)
X2 <- mvrnorm(n = 1500, mu = c(-10, 6), Sigma2)
BALLOT <- rbind(X1, X2)
train <- sample(1:10000, 500)
data <- BALLOT[train, ]
plot(data)
b1 <- binningDepth2D(data, remove_borders = FALSE, nbins = 12, k = 1)
b2 <- binningDepth2D(data, nbins = 12, k = 1, remove_borders = TRUE)
plot(b1)
plot(b2)
# EXAMPLE 2
data(under5.mort)
data(maesles.imm)
data2011 <- cbind(under5.mort[, 22], maesles.imm[, 22])
plot(binningDepth2D(data2011, nbins = 8, k = 0.5, remove_borders = 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.