Skip to contents

Dispatches to a dedicated density estimator. Subject-occupation density estimation is one application: construct a sparse mass vector over a fixed support set and call this generic density layer.

Usage

fit.density(
  X,
  weights = NULL,
  method = c("empirical", "graph_random_walk"),
  graph = NULL,
  graph.control = list(),
  density.control = list(),
  return.details = TRUE,
  ...
)

Arguments

X

Numeric matrix with one row per support point.

weights

Optional nonnegative mass/count vector of length nrow(X). Required by count-based density methods.

method

Density method identifier.

graph

Optional precomputed graph object.

graph.control

Named list for random walks: walk.steps (or walk.step), affinity.method, affinity.scale, affinity.epsilon, and logical normalize. Underscore aliases are accepted, but conflicting aliases and unknown names are rejected. Must be empty for the empirical estimator.

density.control

List controlling clipping, normalization, and accounting checks. Recognized entries are mass.tol, neg.tol, logical clip.negative and renormalize, and diagnostic controls smoothness.adj.list and logical smoothness.auto.1d. Unknown or duplicated names are errors.

return.details

Logical; if TRUE, keep diagnostic details in the result.

...

Reserved for future methods; unused arguments are errors.

Value

A list of class "density_fit" with fields method.id, status, rho, empirical.rho, fitted.raw, theta, accounting, smoothness, timing, diagnostics, and warnings.

Examples

X <- matrix(seq(0, 1, length.out = 6), ncol = 1)
fit.density(X, weights = c(1, 0, 2, 0, 0, 1), method = "empirical")
#> Probability mass 
#>   Training rows: NA ; evaluation rows: 6 ; responses: 1 
#>   Observed responses: NA ; nonfinite fitted entries: 0 
#>   Output: ok 
#>   Convergence: unavailable (no stored stopping certificate) 
#>   Total mass: 1 ; positive support: 3 
#>   Accounting: mass=1e+00, min.rho=0e+00, max.rho=5e-01, raw.mass=1e+00,
#>     neg.mass=0e+00, clip.mass=0e+00, normalization.constant=1e+00,
#>     mass.tol=1e-08, neg.tol=1e-12 
#>   Prediction scope: mass on the stored support