Fit a Local-Likelihood Density or Bernoulli Smoother
Source:R/local_likelihood.R
fit.local.likelihood.RdFits a local likelihood model around each evaluation point and returns
the fitted value at that point. When the aim is the occupation density of
a subject, convert the returned values with
normalize.density.
Usage
fit.local.likelihood(
X,
y,
X.eval = NULL,
likelihood.family = c("density", "bernoulli"),
support.size = min(15L, nrow(X)),
degree = 1L,
kernel = c("gaussian", "tricube", "epanechnikov", "triangular"),
bandwidth.multiplier = 1,
support.grid = NULL,
degree.grid = NULL,
kernel.grid = NULL,
bandwidth.multiplier.grid = NULL,
lambda.ridge.grid = NULL,
foldid = NULL,
cv.folds = 5L,
cv.seed = 1L,
coordinate.method = c("coordinates", "local.pca", "local.pls"),
chart.dim = NULL,
chart.dim.grid = NULL,
selection.strategy = c("grid", "sparse_kd", "plateau_kd"),
chart.dim.max = NULL,
design.margin = 2L,
auto.chart.support.metric = c("coordinates", "operator", "both"),
auto.chart.selection.metric = c("coordinates", "operator"),
quadrature.weights = NULL,
lambda.ridge = 1e-08,
min.local.mass = sqrt(.Machine$double.eps),
min.nonzero.mass = 1L,
fallback = c("degree0", "zero", "chart_kernel", "na"),
optimizer = c("newton", "optim"),
max.iter = 50L,
tol = 1e-08,
return.details = TRUE,
chart.geometry = c("legacy", "euclidean", "linf.simplex"),
unfold.faces = FALSE,
intercept.mass = 0.5
)Arguments
- X
Numeric matrix with one row per source/support point.
- y
Numeric response vector. For
likelihood.family = "density", this must be a nonnegative mass/intensity vector with positive total mass. For"bernoulli", values must lie in[0, 1].- X.eval
Optional numeric matrix of evaluation points. Defaults to
X.- likelihood.family
Local likelihood family.
- support.size
Number of source points in each local support.
- degree
Local chart feature degree. Supported values are 0, 1, and 2. The density branch omits an intercept because the intercept is not identifiable in the normalized local density likelihood. The Bernoulli branch includes an intercept in its internal logistic feature map.
- kernel
Kernel name. Supported values are
"gaussian","tricube","epanechnikov", and"triangular".- bandwidth.multiplier
Positive multiplier applied to the local support radius.
- support.grid
Optional integer candidate neighborhood sizes for cross-validation. CV selection is currently implemented for
likelihood.family = "bernoulli".- degree.grid
Optional local polynomial degree candidates for Bernoulli cross-validation.
- kernel.grid
Optional kernel candidates for Bernoulli cross-validation.
- bandwidth.multiplier.grid
Optional bandwidth-multiplier candidates for Bernoulli cross-validation.
- lambda.ridge.grid
Optional ridge-penalty candidates for Bernoulli cross-validation.
- foldid
Optional positive integer vector assigning source rows to cross-validation folds.
- cv.folds
Number of folds used when
foldidis not supplied.- cv.seed
Random seed used to generate folds when
foldidis not supplied.- coordinate.method
Local coordinate method.
"coordinates"uses centered ambient coordinates."local.pca"projects centered support points onto a local PCA basis.- chart.dim
Local PCA dimension when
coordinate.method = "local.pca". IfNULL, the dimension ismin(ncol(X), support.size - 1). The deployable input-only policies"auto"and"local.auto"use the same local-PCA dimension diagnostics asfit.lps;"auto"resolves one global chart dimension, while"local.auto"resolves one dimension per evaluation anchor.- chart.dim.grid
Optional candidate chart dimensions for experimental cross-validation. Numeric grids can be evaluated with
selection.strategy = "sparse_kd".- selection.strategy
Candidate-selection strategy.
"grid"evaluates the requested candidate grid."sparse_kd"evaluates a sparse support-size by chart-dimension skeleton whenchart.dim.gridis supplied."plateau_kd"uses the same geometry-only support-size and chart-dimension plateau rule asfit.lps.- chart.dim.max
Optional explicit maximum chart dimension for the sparse coupled candidate family.
- design.margin
Nonnegative integer feasibility margin used to screen local polynomial design size before candidate evaluation.
- auto.chart.support.metric
Support system used by
chart.dim = "auto"or"local.auto". Local-likelihood smoothers currently use coordinate supports for both coordinate and operator diagnostics.- auto.chart.selection.metric
Which auto chart-dimension diagnostic to use when both coordinate and operator summaries are requested.
- quadrature.weights
Optional positive reference-measure weights. Defaults to unit weights.
- lambda.ridge
Nonnegative ridge penalty on identifiable coefficients.
- min.local.mass
Minimum local kernel-weighted mass needed before attempting a higher-degree density fit. For Bernoulli fits this is used only as diagnostic telemetry.
- min.nonzero.mass
Minimum number of locally weighted positive-mass source points needed before attempting a higher-degree local fit.
- fallback
Fallback policy for underidentified or failed higher-degree local fits. Zero local mass always uses
"zero".- optimizer
Optimizer for nonzero-degree density fits.
"newton"is implemented;"optim"is accepted and delegates to BFGS.- max.iter
Maximum optimizer iterations.
- tol
Convergence tolerance for gradient norm and step norm.
- return.details
Logical; if
TRUE, keep per-evaluation diagnostics.- chart.geometry
Opt-in chart implementation. Default
"legacy"preserves existing behavior."euclidean"uses ambient distances;"linf.simplex"max-normalizes rows and uses intrinsic Euclidean distances, including intermediate faces. Both new modes support Bernoulli degree 0/1 fits, weighted"local.pca"or"local.pls", numeric dimensions and grid CV only. Supports and kernels use the original metric, independent of projection. Directions, weighted centering and score scaling are learned from training rows only, including within every CV fold.- unfold.faces
Certify and unfold local simplex neighborhoods using
unfold.simplex.chart? Requires simplex geometry. Unsupported charts use the declaredfallback:"degree0"or"na".- intercept.mass
In nonlegacy modes, positive symmetric pseudo-count for successes and failures at the weighted chart center. Default 0.5 keeps constant-response supports finite. Kernel times quadrature weights are normalized to support.size before fitting; slopes have the ridge penalty. Convergence requires the maximum absolute gradient below tol, not just a small step. Failed fits retain diagnostic status and use the fallback.
Value
A list with class "local_likelihood" containing
fitted.values, selected controls, and local solver diagnostics.
Details
The likelihood.family = "density" branch uses a local exponential
tilt of the chart reference measure. The "bernoulli" branch uses a
weighted local logistic likelihood and returns fitted probabilities at the
evaluation anchors.
Examples
X <- matrix(seq(0, 1, length.out = 21), ncol = 1)
y <- exp(-20 * (X[, 1] - 0.5)^2)
y <- y / sum(y)
fit.local.likelihood(X, y, likelihood.family = "density",
support.size = 7L, degree = 0L)
#> Local likelihood
#> Training rows: 21 ; evaluation rows: 21 ; responses: 1
#> Observed responses: 21 ; nonfinite fitted entries: 0
#> Output: finite output
#> Convergence: unavailable (no stored stopping certificate)
#> Selected: support.size=7, degree=0, kernel=gaussian, lambda.ridge=1e-08,
#> likelihood.family=density, cv.rmse.observed=NA, cv.brier.observed=NA,
#> cv.logloss.observed=NA
#> Local fallbacks: 0
#> Local status: ok=21
#> Prediction scope: stored evaluation rows; supply X.eval when fitting