This vignette illustrates two-dimensional density estimation and visualization. It complements the estimator-choice vignette by focusing on the 2D workflow.
The example uses a small reproducible mixture so the vignette remains quick to build.
grid_fit <- glbfp_estimate(x, b = b, m = c(1, 1), grid_size = 20)
summary(grid_fit)
#> Method: GLBFP
#> Dimension: 2
#> Grid points: 400
#> Grid type: rectangular
#> Grid dimensions: 20 x 20
#> Bandwidths (b): 0.321036127107069, 0.315953610723842
#> Shifts (m): 1, 1
#> Density range: 0 to 0.210331281836707
#> Density quartiles: 0, 0.00348642703612869, 0.0356905349965338
#> Density median: 0.003486427
#> Density mean: 0.02480127
#> Zero densities: 188
#> Standard error median: 0.007210991
#> Median visited cells: 1
#> Median prefix nodes: 6
head(as.data.frame(grid_fit))
#> x1 x2 density sd IC_lower IC_upper visited prefix_nodes
#> 1 -2.974658 -2.888704 0 0 0 0 0 6
#> 2 -2.657723 -2.888704 0 0 0 0 0 6
#> 3 -2.340789 -2.888704 0 0 0 0 0 6
#> 4 -2.023855 -2.888704 0 0 0 0 0 6
#> 5 -1.706920 -2.888704 0 0 0 0 0 6
#> 6 -1.389986 -2.888704 0 0 0 0 0 6For two-dimensional regular grids, contour = TRUE
returns a static ggplot2 contour plot.
With contour = FALSE, the plot method returns an
interactive plotly surface. This is useful for exploration.
Static contours are usually easier to reproduce in manuscripts.
The number of evaluation points grows quickly with
grid_size in two dimensions. For manuscript figures, start
with a moderate grid and increase it only after confirming that the
visual conclusions are stable.