Objects, summaries and plotting

GLBFP objects are ordinary S3 objects.

Object type Class Main helpers
Pointwise estimator "glbfp_fit" print(), summary(), predict()
Grid estimator "glbfp_grid" print(), summary(), predict(), plot(), as.data.frame()
library(GLBFP)

x <- matrix(rnorm(200), ncol = 1)
b <- compute_bi_optim(x, m = 1)

point_fit <- glbfp(0, x, b = b, m = 1)
class(point_fit)
#> [1] "glbfp_fit" "GLBFP"
summary(point_fit)
#> Method: GLBFP 
#> Dimension: 1 
#> Point: 0 
#> Estimation: 0.4829175 
#> Standard error: 0.08419406 
#> 95% CI: 0.454717631827197, 0.511117292426919 
#> Bandwidths (b): 0.171212730111743 
#> Shifts (m): 1 
#> Relative grid coordinate (u): 0.53632342188152 
#> Visited cells: 2 
#> Prefix nodes: 2
predict(point_fit)
#> [1] 0.4829175

Grid fits support summary(), predict(), plot() and as.data.frame().

grid_fit <- glbfp_estimate(x, b = b, m = 1, grid_size = 60)

class(grid_fit)
#> [1] "glbfp_grid"     "GLBFP_estimate"
summary(grid_fit)
#> Method: GLBFP 
#> Dimension: 1 
#> Grid points: 60 
#> Grid type: rectangular 
#> Grid dimensions: 60 
#> Bandwidths (b): 0.171212730111743 
#> Shifts (m): 1 
#> Density range: 0.00255212027556414 to 0.49645841138404 
#> Density quartiles: 0.0627489310286446, 0.137498703743326, 0.301536680584891 
#> Density median: 0.1374987 
#> Density mean: 0.1821547 
#> Zero densities: 0 
#> Standard error median: 0.04981216 
#> Median visited cells: 2 
#> Median prefix nodes: 2

grid_df <- as.data.frame(grid_fit)
head(grid_df)
#>          V1    density         sd   IC_lower   IC_upper visited prefix_nodes
#> 1 -2.574410 0.13141546 0.09795130 0.09860780 0.16422312       1            2
#> 2 -2.482236 0.08424967 0.04773746 0.06826056 0.10023879       1            2
#> 3 -2.390062 0.03708388 0.02354223 0.02919868 0.04496908       1            2
#> 4 -2.297888 0.01680318 0.01976786 0.01018216 0.02342420       1            2
#> 5 -2.205714 0.09541283 0.03904341 0.08233569 0.10848997       1            2
#> 6 -2.113540 0.12361294 0.04990770 0.10689693 0.14032895       2            2

Prediction from a grid fit uses nearest-grid lookup. This is intended as a lightweight helper for exploratory workflows.

new_points <- matrix(c(-1, 0, 1), ncol = 1)
predict(grid_fit, newdata = new_points)
#> [1] 0.1574531 0.4840192 0.1908743

Plot methods return ggplot objects for one-dimensional grids and for two-dimensional contour plots.

plot(grid_fit)

For two-dimensional grids, contour = TRUE gives a static ggplot object. The default two-dimensional display uses plotly.

x2 <- cbind(rnorm(120), rnorm(120))
grid_2d <- glbfp_estimate(x2, b = c(0.8, 0.8), m = c(1, 1), grid_size = 12)

plot(grid_2d, contour = TRUE)