| Title: | General Linear Blend Frequency Polygon Density Estimation |
|---|---|
| Description: | Implements nonparametric density estimation with Averaged Shifted Histogram (ASH), Linear Blend Frequency Polygon (LBFP), and General Linear Blend Frequency Polygon (GLBFP) estimators. The package provides pointwise and grid-based estimation workflows, sparse-prefix grid-count computation, fixed-grid leave-one-out self-support scores, plotting helpers, and plug-in bandwidth selection. |
| Authors: | Aurélien Nicosia [aut, cre], Thierry Duchesne [aut], Michel Carbon [aut] |
| Maintainer: | Aurélien Nicosia <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.5.2.9000 |
| Built: | 2026-06-17 17:57:09 UTC |
| Source: | https://github.com/aureliennicosiaulaval/glbfp |
GLBFP provides one-point and grid-based density estimators based on
ASH, LBFP and GLBFP methodology, with sparse-prefix computation,
leave-one-out self-support scores, visualization helpers and bandwidth
selection utilities.
Main entry points:
Lowercase aliases such as glbfp() and glbfp_estimate() are also provided for users who prefer lower-snake-case function names.
Maintainer: Aurélien Nicosia [email protected]
Useful links:
Report bugs at https://github.com/AurelienNicosiaULaval/GLBFP/issues
Convert GLBFP objects to data frames
## S3 method for class 'glbfp_grid' as.data.frame(x, row.names = NULL, optional = FALSE, ...) ## S3 method for class 'glbfp_di' as.data.frame(x, row.names = NULL, optional = FALSE, ...)## S3 method for class 'glbfp_grid' as.data.frame(x, row.names = NULL, optional = FALSE, ...) ## S3 method for class 'glbfp_di' as.data.frame(x, row.names = NULL, optional = FALSE, ...)
x |
A GLBFP grid object or a |
row.names |
Optional row names. |
optional |
Passed to |
... |
Additional arguments (unused). |
A data frame representation of the object.
Computes the ASH density estimate at point x.
ASH( x, data, b = compute_bi_optim(data, m = rep(1, ncol(data))), m = rep(1, ncol(data)), min_vals = apply(data, 2, min), max_vals = apply(data, 2, max) ) ## S3 method for class 'ASH' print(x, ...)ASH( x, data, b = compute_bi_optim(data, m = rep(1, ncol(data))), m = rep(1, ncol(data)), min_vals = apply(data, 2, min), max_vals = apply(data, 2, max) ) ## S3 method for class 'ASH' print(x, ...)
x |
Object of class |
data |
Numeric matrix or data frame of observations ( |
b |
Positive numeric vector of bandwidths (length |
m |
Positive integer vector of shifts (length |
min_vals |
Numeric vector of lower grid bounds (length |
max_vals |
Numeric vector of upper grid bounds (length |
... |
Additional arguments (unused). |
m controls the number of shifted histograms used in each dimension. Missing
and non-finite values are not accepted; remove or impute them before calling
the estimator.
A list with class c("glbfp_fit", "ASH") containing:
x, estimation, b, m, method, and dimension.
print(ASH): Print method for object of class "ASH".
Scott, D. W. (1992). Multivariate Density Estimation: Theory, Practice, and Visualization. Wiley. doi:10.1002/9780470316849.
ASH_estimate(), LBFP(), GLBFP(), compute_bi_optim()
x <- c(200, 30) b <- c(0.5, 0.5) m <- c(1, 1) ASH(x, ashua[, -3], b = b, m = m)x <- c(200, 30) b <- c(0.5, 0.5) m <- c(1, 1) ASH(x, ashua[, -3], b = b, m = m)
Computes ASH density estimates on a regular or user-supplied grid.
ASH_estimate( data, b = compute_bi_optim(data, m = rep(1, ncol(data))), m = rep(1, ncol(data)), grid_size = 20, grid_points = NULL, min_vals = apply(data, 2, min), max_vals = apply(data, 2, max) ) ## S3 method for class 'ASH_estimate' print(x, ...) ## S3 method for class 'ASH_estimate' plot(x, contour = FALSE, ...)ASH_estimate( data, b = compute_bi_optim(data, m = rep(1, ncol(data))), m = rep(1, ncol(data)), grid_size = 20, grid_points = NULL, min_vals = apply(data, 2, min), max_vals = apply(data, 2, max) ) ## S3 method for class 'ASH_estimate' print(x, ...) ## S3 method for class 'ASH_estimate' plot(x, contour = FALSE, ...)
data |
Numeric matrix or data frame of observations ( |
b |
Positive numeric vector of bandwidths (length |
m |
Positive integer vector of shifts (length |
grid_size |
Integer number of grid points per dimension when
|
grid_points |
Optional matrix/data frame of explicit evaluation points. |
min_vals |
Numeric vector of lower grid bounds (length |
max_vals |
Numeric vector of upper grid bounds (length |
x |
Object from |
... |
Additional arguments (unused). |
contour |
If |
When grid_points is NULL, a regular grid is constructed from min_vals to
max_vals. Custom grids may be irregular; in that case plotting uses point or
scatter representations instead of a surface.
A list with class c("glbfp_grid", "ASH_estimate") containing
grid coordinates, densities, and grid metadata.
print(ASH_estimate): Print method for object of class "ASH_estimate".
plot(ASH_estimate): Plot method for object of class "ASH_estimate".
ASH(), LBFP_estimate(), GLBFP_estimate()
b <- c(0.5, 0.5) # Use a small, representative subset so examples remain fast in checks. sample_data <- as.matrix(ashua[seq_len(120), -3]) out <- ASH_estimate(sample_data, b = b, m = c(1, 1), grid_size = 10) outb <- c(0.5, 0.5) # Use a small, representative subset so examples remain fast in checks. sample_data <- as.matrix(ashua[seq_len(120), -3]) out <- ASH_estimate(sample_data, b = b, m = c(1, 1), grid_size = 10) out
Daily observations of river flow and level for the Ashuapmushuan river.
ashuaashua
A data frame with 4,389 rows and 3 variables:
Flow rate in cubic meters per second.
Water level in meters.
Day code as integer in YYYYDDD format.
Data cover 22 March 1992 to 30 September 2007 with a small number of missing calendar days.
Environment and Climate Change Canada, Historical Hydrometric Data.
The exact extraction query still needs to be documented in data-raw/.
data(ashua) summary(ashua)data(ashua) summary(ashua)
Computes a plug-in bandwidth vector used by GLBFP/LBFP/ASH estimators. The function validates numeric inputs, stabilizes near-singular covariance matrices with a small ridge if needed, and returns strictly positive bandwidths.
compute_bi_optim(data, m = rep(1, ncol(data)))compute_bi_optim(data, m = rep(1, ncol(data)))
data |
A numeric matrix or data frame where rows are observations and columns are variables. |
m |
A positive integer vector of shifts, one value per dimension. |
The returned vector is intended as a starting value for examples and routine workflows. For applied analysis, sensitivity to the bandwidth should still be checked.
The plug-in expression follows the optimal cell-width calculation for multivariate frequency polygons in Carbon and Duchesne (2024).
Near-singular covariance matrices are stabilized with a small ridge term. If this fails, the function returns an error rather than silently producing non-finite bandwidths.
A numeric vector of positive bandwidths with one value per column in
data.
Carbon, M. and Duchesne, T. (2024). Multivariate frequency polygon for stationary random fields. Annals of the Institute of Statistical Mathematics, 76(2), 263-287. doi:10.1007/s10463-023-00883-5.
set.seed(1) x <- cbind(rnorm(200), rnorm(200)) compute_bi_optim(x, m = c(1, 1))set.seed(1) x <- cbind(rnorm(200), rnorm(200)) compute_bi_optim(x, m = c(1, 1))
Computes the fixed-grid leave-one-out score
for observations in data. The grid, bandwidths, and estimator parameters
are held fixed when the contribution of observation i is removed.
compute_Di( data, b = compute_bi_optim(data, m = rep(1, ncol(data))), m = rep(1, ncol(data)), estimator = c("GLBFP", "LBFP", "ASH"), min_vals = apply(data, 2, min), max_vals = apply(data, 2, max) )compute_Di( data, b = compute_bi_optim(data, m = rep(1, ncol(data))), m = rep(1, ncol(data)), estimator = c("GLBFP", "LBFP", "ASH"), min_vals = apply(data, 2, min), max_vals = apply(data, 2, max) )
data |
Numeric matrix or data frame of observations ( |
b |
Positive numeric vector of bandwidths (length |
m |
Positive integer vector of shifts (length |
estimator |
Character string. One of |
min_vals |
Numeric vector of lower grid bounds (length |
max_vals |
Numeric vector of upper grid bounds (length |
A list with class "glbfp_di" containing the score vector D,
fitted densities, leave-one-out densities, self-weights, and metadata.
x <- as.matrix(ashua[seq_len(80), -3]) b <- c(0.5, 0.5) out <- compute_Di(x, b = b, m = c(1, 1), estimator = "GLBFP") summary(out)x <- as.matrix(ashua[seq_len(80), -3]) b <- c(0.5, 0.5) out <- compute_Di(x, b = b, m = c(1, 1), estimator = "GLBFP") summary(out)
bandwidth constantComputes the dimension-dependent constant used by
compute_bi_optim().
compute_G_star(d)compute_G_star(d)
d |
A single positive integer giving the data dimension. |
The implemented formula is
A positive numeric scalar.
compute_bi_optim(), G_i(), K_mi()
compute_G_star(1) compute_G_star(2)compute_G_star(1) compute_G_star(2)
bandwidth constantComputes the scalar constant used by compute_bi_optim().
G_i(mi)G_i(mi)
mi |
A single positive numeric value. In package estimators, |
The implemented formula is
A positive numeric scalar.
compute_bi_optim(), K_mi(), compute_G_star()
G_i(1) G_i(2)G_i(1) G_i(2)
Computes the GLBFP density estimate at point x.
GLBFP( x, data, b = compute_bi_optim(data, m = rep(1, ncol(data))), m = rep(1, ncol(data)), min_vals = apply(data, 2, min), max_vals = apply(data, 2, max) ) ## S3 method for class 'GLBFP' print(x, ...)GLBFP( x, data, b = compute_bi_optim(data, m = rep(1, ncol(data))), m = rep(1, ncol(data)), min_vals = apply(data, 2, min), max_vals = apply(data, 2, max) ) ## S3 method for class 'GLBFP' print(x, ...)
x |
Object returned by |
data |
Numeric matrix or data frame of observations ( |
b |
Positive numeric vector of bandwidths (length |
m |
Positive integer vector of shifts (length |
min_vals |
Numeric vector of lower grid bounds (length |
max_vals |
Numeric vector of upper grid bounds (length |
... |
Additional arguments (unused). |
GLBFP() generalizes the linear blend frequency polygon workflow through the
positive integer shift vector m. Missing and non-finite values are not
accepted; remove or impute them before calling the estimator.
A list with class c("glbfp_fit", "GLBFP") containing:
x, estimation, sd, IC, b, m, method, and dimension.
print(GLBFP): Print method for object of class "GLBFP".
Scott, D. W. (1992). Multivariate Density Estimation: Theory, Practice, and Visualization. Wiley. doi:10.1002/9780470316849.
The complete methodological citation for GLBFP has not yet been verified in this repository. Add it before using this help page as publication text.
GLBFP_estimate(), ASH(), LBFP(), compute_bi_optim()
x <- c(200, 30) b <- c(0.5, 0.5) m <- c(1, 1) GLBFP(x, ashua[, -3], b = b, m = m)x <- c(200, 30) b <- c(0.5, 0.5) m <- c(1, 1) GLBFP(x, ashua[, -3], b = b, m = m)
Computes GLBFP density estimates on a regular or user-supplied grid.
GLBFP_estimate( data, b = compute_bi_optim(data, m = rep(1, ncol(data))), m = rep(1, ncol(data)), grid_size = 20, grid_points = NULL, min_vals = apply(data, 2, min), max_vals = apply(data, 2, max) ) ## S3 method for class 'GLBFP_estimate' print(x, ...) ## S3 method for class 'GLBFP_estimate' plot(x, contour = FALSE, ...)GLBFP_estimate( data, b = compute_bi_optim(data, m = rep(1, ncol(data))), m = rep(1, ncol(data)), grid_size = 20, grid_points = NULL, min_vals = apply(data, 2, min), max_vals = apply(data, 2, max) ) ## S3 method for class 'GLBFP_estimate' print(x, ...) ## S3 method for class 'GLBFP_estimate' plot(x, contour = FALSE, ...)
data |
Numeric matrix or data frame of observations ( |
b |
Positive numeric vector of bandwidths (length |
m |
Positive integer vector of shifts (length |
grid_size |
Integer number of grid points per dimension when
|
grid_points |
Optional matrix/data frame of explicit evaluation points. |
min_vals |
Numeric vector of lower grid bounds (length |
max_vals |
Numeric vector of upper grid bounds (length |
x |
Object returned by |
... |
Additional arguments (unused). |
contour |
If |
When grid_points is NULL, a regular grid is constructed from min_vals to
max_vals. Custom grids may be irregular; in that case plotting uses point or
scatter representations instead of a surface.
A list with class c("glbfp_grid", "GLBFP_estimate") containing
grid coordinates, densities, uncertainty estimates, and grid metadata.
print(GLBFP_estimate): Print method for object of class "GLBFP_estimate".
plot(GLBFP_estimate): Plot method for object of class "GLBFP_estimate".
GLBFP(), ASH_estimate(), LBFP_estimate()
b <- c(0.5, 0.5) # Use a small, representative subset so examples remain fast in checks. sample_data <- as.matrix(ashua[seq_len(120), -3]) out <- GLBFP_estimate(sample_data, b = b, m = c(1, 1), grid_size = 10) outb <- c(0.5, 0.5) # Use a small, representative subset so examples remain fast in checks. sample_data <- as.matrix(ashua[seq_len(120), -3]) out <- GLBFP_estimate(sample_data, b = b, m = c(1, 1), grid_size = 10) out
bandwidth constantComputes the scalar constant used by compute_bi_optim().
K_mi(mi)K_mi(mi)
mi |
A single numeric value greater than 0.5. In package estimators,
|
The implemented formula is
A positive numeric scalar.
compute_bi_optim(), G_i(), compute_G_star()
K_mi(1) K_mi(2)K_mi(1) K_mi(2)
Computes the LBFP density estimate at point x.
LBFP( x, data, b = compute_bi_optim(data, m = rep(1, ncol(data))), min_vals = apply(data, 2, min), max_vals = apply(data, 2, max) ) ## S3 method for class 'LBFP' print(x, ...)LBFP( x, data, b = compute_bi_optim(data, m = rep(1, ncol(data))), min_vals = apply(data, 2, min), max_vals = apply(data, 2, max) ) ## S3 method for class 'LBFP' print(x, ...)
x |
Object from |
data |
Numeric matrix or data frame of observations ( |
b |
Positive numeric vector of bandwidths (length |
min_vals |
Numeric vector of lower grid bounds (length |
max_vals |
Numeric vector of upper grid bounds (length |
... |
Additional arguments (unused). |
The estimate is obtained by linear blending of neighboring histogram bin heights. Missing and non-finite values are not accepted; remove or impute them before calling the estimator.
A list with class c("glbfp_fit", "LBFP") containing:
x, estimation, sd, IC, b, method, and dimension.
print(LBFP): Print method for object of class "LBFP".
Scott, D. W. (1992). Multivariate Density Estimation: Theory, Practice, and Visualization. Wiley. doi:10.1002/9780470316849.
Terrell, G. R., and Scott, D. W. (1985). Oversmoothed Nonparametric Density Estimates. Journal of the American Statistical Association, 80(389), 209-214. doi:10.1080/01621459.1985.10477163.
LBFP_estimate(), ASH(), GLBFP(), compute_bi_optim()
x <- c(200, 30) b <- c(0.5, 0.5) LBFP(x, ashua[, -3], b = b)x <- c(200, 30) b <- c(0.5, 0.5) LBFP(x, ashua[, -3], b = b)
Computes LBFP density estimates on a regular or user-supplied grid.
LBFP_estimate( data, b = compute_bi_optim(data, m = rep(1, ncol(data))), grid_size = 20, grid_points = NULL, min_vals = apply(data, 2, min), max_vals = apply(data, 2, max) ) ## S3 method for class 'LBFP_estimate' print(x, ...) ## S3 method for class 'LBFP_estimate' plot(x, contour = FALSE, ...)LBFP_estimate( data, b = compute_bi_optim(data, m = rep(1, ncol(data))), grid_size = 20, grid_points = NULL, min_vals = apply(data, 2, min), max_vals = apply(data, 2, max) ) ## S3 method for class 'LBFP_estimate' print(x, ...) ## S3 method for class 'LBFP_estimate' plot(x, contour = FALSE, ...)
data |
Numeric matrix or data frame of observations ( |
b |
Positive numeric vector of bandwidths (length |
grid_size |
Integer number of grid points per dimension when
|
grid_points |
Optional matrix/data frame of explicit evaluation points. |
min_vals |
Numeric vector of lower grid bounds (length |
max_vals |
Numeric vector of upper grid bounds (length |
x |
Object returned by |
... |
Additional arguments (unused). |
contour |
If |
When grid_points is NULL, a regular grid is constructed from min_vals to
max_vals. Custom grids may be irregular; in that case plotting uses point or
scatter representations instead of a surface.
A list with class c("glbfp_grid", "LBFP_estimate") containing
grid coordinates, densities, uncertainty estimates, and grid metadata.
print(LBFP_estimate): Print method for object of class "LBFP_estimate".
plot(LBFP_estimate): Plot method for object of class "LBFP_estimate".
LBFP(), ASH_estimate(), GLBFP_estimate()
b <- c(0.5, 0.5) out <- LBFP_estimate(ashua[, -3], b = b, grid_size = 15) out plot(out, contour = TRUE)b <- c(0.5, 0.5) out <- LBFP_estimate(ashua[, -3], b = b, grid_size = 15) out plot(out, contour = TRUE)
These aliases follow common R naming style while preserving the original uppercase function names used in earlier versions of the package.
ash(...) lbfp(...) glbfp(...) ash_estimate(...) lbfp_estimate(...) glbfp_estimate(...) compute_di(...)ash(...) lbfp(...) glbfp(...) ash_estimate(...) lbfp_estimate(...) glbfp_estimate(...) compute_di(...)
... |
Arguments passed to the corresponding uppercase function. |
The same object returned by the corresponding uppercase function.
Prediction helper for fitted GLBFP objects.
## S3 method for class 'glbfp_fit' predict(object, newdata = NULL, ...)## S3 method for class 'glbfp_fit' predict(object, newdata = NULL, ...)
object |
A fitted object of class |
newdata |
Optional matrix/data frame with points where prediction is
requested. For |
... |
Additional arguments (unused). |
Numeric vector of predicted densities.
Summarizes objects returned by ASH(), LBFP(), GLBFP() and
their grid counterparts.
## S3 method for class 'glbfp_fit' summary(object, ...)## S3 method for class 'glbfp_fit' summary(object, ...)
object |
A fitted object of class |
... |
Additional arguments (unused). |
A list with class "summary.glbfp_fit" or "summary.glbfp_grid".