% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/weights.R
\name{compute_kernel_weights}
\alias{compute_kernel_weights}
\title{Compute geographically weighted kernel weights}
\usage{
compute_kernel_weights(distance, bandwidth, kernel, adaptive)
}
\arguments{
\item{distance}{Numeric vector of distances from the focal unit to all
spatial units (length n).}

\item{bandwidth}{Numeric scalar.  For fixed bandwidth: distance scale.
For adaptive bandwidth: positive integer number of neighbours.}

\item{kernel}{Character scalar, one of `"bisquare"`, `"gaussian"`,
`"exponential"`, `"tricube"`, `"boxcar"`.}

\item{adaptive}{Logical.  `TRUE` for adaptive (kNN) bandwidth.}
}
\value{
A numeric vector of length n with non-negative kernel weights.
}
\description{
Given a numeric vector of distances from one focal unit to all others,
returns a weight for each unit according to the chosen kernel and bandwidth.
}
\details{
For **fixed** bandwidth (`adaptive = FALSE`) the bandwidth parameter is a
distance threshold or scale parameter used directly in the kernel formula.

For **adaptive** bandwidth (`adaptive = TRUE`) the bandwidth parameter is
the number of nearest neighbours k.  The function first identifies the
k-th smallest distance (among all units, including the focal unit itself at
distance 0) and uses that distance as the effective bandwidth in the kernel
formula.

Kernel formulae (d = distance, bw = effective bandwidth):
* `bisquare`:    `(1 - (d/bw)^2)^2` for `d <= bw`, else 0.
* `gaussian`:    `exp(-0.5 * (d/bw)^2)`.
* `exponential`: `exp(-d/bw)`.
* `tricube`:     `(1 - (d/bw)^3)^3` for `d <= bw`, else 0.
* `boxcar`:      `1` for `d <= bw`, else 0.
}
\keyword{internal}
