Skip to content

Commit 7136d85

Browse files
committed
More polishing documentation
1 parent 4b6077f commit 7136d85

File tree

6 files changed

+118
-38
lines changed

6 files changed

+118
-38
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: spatstat.univar
2-
Version: 3.1-1.002
3-
Date: 2025-02-25
2+
Version: 3.1-1.003
3+
Date: 2025-02-26
44
Title: One-Dimensional Probability Distribution Support for the 'spatstat' Family
55
Authors@R: c(person("Adrian", "Baddeley",
66
role = c("aut", "cre", "cph"),

NEWS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CHANGES IN spatstat.univar VERSION 3.1-1.002
1+
CHANGES IN spatstat.univar VERSION 3.1-1.003
22

33
OVERVIEW
44

inst/doc/packagesizes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ date version nhelpfiles nobjects ndatasets Rlines srclines
55
"2024-09-05" "3.0-1" 30 60 0 1742 321
66
"2024-11-05" "3.1-0" 36 68 0 2571 2233
77
"2024-11-05" "3.1-1" 36 68 0 2571 2235
8-
"2025-02-25" "3.1-1.002" 36 68 0 2577 2235
8+
"2025-02-26" "3.1-1.003" 36 68 0 2577 2235

inst/info/packagesizes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ date version nhelpfiles nobjects ndatasets Rlines srclines
55
"2024-09-05" "3.0-1" 30 60 0 1742 321
66
"2024-11-05" "3.1-0" 36 68 0 2571 2233
77
"2024-11-05" "3.1-1" 36 68 0 2571 2235
8-
"2025-02-25" "3.1-1.002" 36 68 0 2577 2235
8+
"2025-02-26" "3.1-1.003" 36 68 0 2577 2235

man/densityBC.Rd

Lines changed: 111 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
\alias{densityBC}
33
\title{Kernel Density Estimation with Optional Boundary Correction}
44
\description{
5-
A simple implementation of fixed-bandwidth kernel density
5+
Fixed-bandwidth kernel density
66
estimation on the real line, or the positive real half-line,
7-
including optional corrections for a boundary at zero.
7+
including optional corrections for a boundary at zero.
88
}
99
\usage{
1010
densityBC(x, kernel = "epanechnikov", bw=NULL,
@@ -18,7 +18,7 @@
1818
internal=list())
1919
}
2020
\arguments{
21-
\item{x}{Numeric vector.}
21+
\item{x}{Numeric vector of observed values.}
2222
\item{kernel}{String specifying kernel.
2323
Options are
2424
\code{"gaussian"}, \code{"rectangular"},
@@ -27,12 +27,13 @@
2727
\code{"biweight"},
2828
\code{"cosine"} and \code{"optcosine"}.
2929
(Partial matching is used).
30+
Options are described in the help for \code{\link[stats]{density.default}}.
3031
}
3132
\item{bw,h}{
3233
Alternative specifications of the scale factor for the kernel.
3334
The bandwidth \code{bw} is the standard deviation of the
3435
kernel (this agrees with the argument \code{bw} in
35-
\code{\link[stats]{density.default}}.
36+
\code{\link[stats]{density.default}}).
3637
The rescale factor \code{h} is the factor by which
3738
the `standard form' of the kernel is rescaled. For the Epanechnikov
3839
kernel, \code{h = bw * sqrt(5)} is the
@@ -66,14 +67,13 @@
6667
String (partially matched) specifying a correction for the boundary effect
6768
bias at \eqn{r=0} when estimating a density on the positive
6869
half line. Possible values are
69-
\code{"none"}, \code{"weighted"}, \code{"convolution"}, \code{"reflection"}
70-
and \code{"bdrykern"}.
70+
\code{"none"}, \code{"weighted"}, \code{"convolution"},
71+
\code{"reflection"}, \code{"bdrykern"} and \code{"JonesFoster"}.
7172
}
7273
\item{fast}{
7374
Logical value specifying whether to perform the calculation rapidly
7475
using the Fast Fourier Transform (\code{fast=TRUE})
7576
or to use slower, exact code (\code{fast=FALSE}, the default).
76-
Option \code{zerocor="bdrykern"} is not available when \code{fast=TRUE}.
7777
}
7878
\item{internal}{
7979
Internal use only.
@@ -83,12 +83,38 @@
8383
}
8484
}
8585
\details{
86+
This function computes a fixed-bandwidth kernel estimate of
87+
a probability density on the real line, or the positive half-line,
88+
including optional boundary corrections
89+
for truncation of the density onto the positive half line.
90+
91+
Weighted estimates are supported, including negative weights.
92+
Weights are not renormalised to sum to 1. The resulting
93+
probability density estimate is not renormalised to integrate to 1.
94+
95+
Options for the smoothing kernel
96+
are described in the help for \code{\link[stats]{density.default}}.
97+
The default is the Epanechnikov (truncated quadratic) kernel.
98+
8699
If \code{zerocor} is missing, or given as \code{"none"},
87-
this function computes the fixed bandwidth kernel estimator of the
88-
probability density on the real line.
100+
this function computes the fixed-bandwidth kernel estimator of the
101+
probability density on the real line,
102+
using \code{\link[stats]{density.default}}.
103+
The estimated probability density (unnormalised) is
104+
\deqn{
105+
\widehat f(x) = \sum_{i=1}^n w_i \; \kappa(x - x_i)
106+
}{
107+
f(x) = sum[i=1,...,n] w[i] * kappa(x - x[i])
108+
}
109+
where \eqn{x_1,\ldots,x_n}{x[1], ..., x[n]} are the data values,
110+
\eqn{w_1,\ldots,w_n}{w[1], ..., w[n]} are the weights (defaulting
111+
to \eqn{w_i = 1/n}{w[i] = 1/n}),
112+
and \eqn{\kappa}{kappa} is the kernel, a probability density on the
113+
real line.
89114
90-
If \code{zerocor} is given, it is assumed that the density
91-
is confined to the positive half-line, and a boundary correction is
115+
If \code{zerocor} is given, the probability density is assumed to be
116+
confined to the positive half-line; the numerical values in \code{x}
117+
must all be non-negative; and a boundary correction is
92118
applied to compensate for bias arising due to truncation at the origin:
93119
\describe{
94120
\item{\code{zerocor="weighted"}:}{
@@ -97,53 +123,100 @@
97123
where \eqn{m(x) = 1 - F(-x)} is the total mass of the kernel centred on
98124
\eqn{x} that lies in the positive half-line, and \eqn{F(x)} is the
99125
cumulative distribution function of the kernel.
126+
The corrected estimate is
127+
\deqn{
128+
\widehat f_W(x) = \sum_{i=1}^n w_i \; \frac{\kappa(x - x_i)}{1-F(-x_i)}
129+
}{
130+
fW(x) = sum[i=1,...,n] w[i] * kappa(x - x[i])/(1-F(-x[i]))
131+
}
100132
This is the \dQuote{cut-and-normalization} method of
101133
Gasser and \ifelse{latex}{\out{M\"{u}ller}}{Mueller} (1979).
102134
Effectively the kernel is renormalized so that it integrates to 1,
103135
and the adjusted kernel conserves mass.
104136
}
105137
\item{\code{zerocor="convolution"}:}{
106-
The estimate of the density \eqn{f(r)} is
107-
weighted by the factor \eqn{1/m(r)} where \eqn{m(r) = 1 - F(-r)}
138+
The estimate of the density \eqn{f(x)} is
139+
weighted by the factor \eqn{1/m(x)} where \eqn{m(r) = 1 - F(-x)}
108140
is given above.
141+
The corrected estimate is
142+
\deqn{
143+
\widehat f_C(x) = \sum_{i=1}^n w_i \; \frac{\kappa(x - x_i)}{1-F(-x)}
144+
}{
145+
fC(x) = sum[i=1,...,n] w[i] * kappa(x - x[i])/(1-F(-x))
146+
}
109147
This is the \dQuote{convolution}, \dQuote{uniform}
110148
or \dQuote{zero-order} boundary correction method
111149
often attributed to Diggle (1985).
112150
This correction does not conserve mass.
151+
It is faster to compute than the weighted correction.
113152
}
114153
\item{\code{zerocor="reflection"}:}{
115154
if the kernel centred at data point \eqn{x_i}{x[i]}
116155
has a tail that lies on the negative half-line, this tail is
117156
reflected onto the positive half-line.
118-
This is the reflection method first proposed by
119-
Boneva et al (1971).
120-
This correction conserves mass.
157+
The corrected estimate is
158+
\deqn{
159+
\widehat f_R(x) = \sum_{i=1}^n w_i \;
160+
[ \kappa(x - x_i) + \kappa(-x - x_i) ]
161+
}{
162+
fR(x) = sum[i=1,...,n] w[i] * ( kappa(x - x[i]) + kappa(-x - x[i]) )
163+
}
164+
This is the \dQuote{reflection} method first proposed by
165+
Boneva et al (1971). This correction conserves mass.
166+
The estimated density always has zero derivative at the origin,
167+
\eqn{\widehat f_R^\prime(0) = 0}{fR'(0) = 0}, which may or
168+
may not be desirable.
121169
}
122170
\item{\code{zerocor="bdrykern"}:}{
123171
The density estimate is computed using the
124172
Linear Boundary Kernel associated with the chosen kernel
125173
(Wand and Jones, 1995, page 47).
126-
That is, when estimating the density \eqn{f(r)} for values of
127-
\eqn{r} close to zero (defined as \eqn{r < h} for all kernels
174+
The estimated (unnormalised) probability density is
175+
\deqn{
176+
\widehat f_B(x) = \sum_{i=1}^n w_i \;
177+
[ A(x) + (x-x_i) B(x)] \kappa(x - x_i)
178+
}{
179+
fB(x) = sum[i=1,...,n] w[i] *
180+
( A(x) + (x-x[i]) B(x)) * kappa(x - x[i])
181+
}
182+
where \eqn{A(x) = a_2(x)/D(x)}{A(x) = a[2](x)/D(x)} and
183+
\eqn{B(x) = -a_1(x)/D(x)}{B(x) = -a[1](x)/D(x)}
184+
with
185+
\eqn{D(x) = a_0(x) a_2(x) - a_1(x)^2}{D(x) = a[0](x) a[2](x) - a[1](x)^2}
186+
where
187+
\eqn{
188+
a_k(x) = \int_{-\infty}^x t^k \kappa(t) dt.
189+
}{
190+
a[k](x) = integral[-Inf,x] ( t^k * kappa(t) dt).
191+
}
192+
That is, when estimating the density \eqn{f(x)} for values of
193+
\eqn{x} close to zero (defined as \eqn{x < h} for all kernels
128194
except the Gaussian), the kernel contribution
129-
\eqn{k_h(r - x_i)}{k[h](r - x[i])} is multiplied by a
130-
term that is a linear function of \eqn{r - x_i}{r - x[i]},
131-
with coefficients depending on \eqn{r}.
195+
\eqn{k_h(x - x_i)}{k[h](x - x[i])} is multiplied by a
196+
term that is a linear function of \eqn{x - x_i}{x - x[i]},
197+
with coefficients depending on \eqn{x}.
132198
This correction does not conserve mass and may result in
133199
negative values, but is asymptotically optimal.
200+
Computation time for this estimate is greater than for
201+
the options above.
134202
}
135203
\item{\code{zerocor="JonesFoster"}:}{
136204
The modification of the Boundary Kernel estimate
137-
proposed by Jones and Foster (1996) is computed. This is equal to
138-
\eqn{
139-
\overline f(r) \exp( \hat f(r)/\overline f(r) - 1)
205+
proposed by Jones and Foster (1996) is computed:
206+
\deqn{
207+
\widehat f_{JF}(x) =
208+
\widehat f_C(x)
209+
\exp\left( \frac{\widehat f_B(x)}{\widehat f_C(r)} - 1 \right)
140210
}{
141-
f#(r) exp(f*(r)/f#(r) - 1)
211+
fJF(x) = fC(x) exp(fB(x)/fC(x) - 1)
142212
}
143-
where \eqn{\overline f(r)}{f#(r)} is the convolution estimator
144-
and \eqn{\hat f(r)}{f*(r)} is the linear boundary kernel estimator.
213+
where \eqn{\widehat f_C(r)}{fC(r)} is the convolution estimator
214+
and \eqn{\widehat f_B(r)}{fB(r)} is the linear boundary kernel estimator.
145215
This ensures that the estimate is always nonnegative
146-
and retains the asymptotic optimality of the linear boundary kernel.
216+
and retains the asymptotic optimality of the linear boundary
217+
kernel.
218+
Computation time for this estimate
219+
is greater than for all the options above.
147220
}
148221
}
149222
If \code{fast=TRUE}, the calculations are performed rapidly using
@@ -167,7 +240,14 @@
167240
legend(2, 0.8,
168241
legend=c("fixed bandwidth", "boundary kernel", "true density"),
169242
col=1:3, lty=rep(1,3))
243+
}
244+
\seealso{
245+
\code{\link[stats]{density.default}}.
246+
247+
\code{\link{dkernel}} for the kernel itself.
170248

249+
\code{\link{densityAdaptiveKernel.default}} for adaptive
250+
(variable-bandwidth) estimation.
171251
}
172252
\references{
173253
\ournewpaper
@@ -176,18 +256,18 @@
176256
Spline transformations: three new diagnostic aids for the
177257
statistical data-analyst (with discussion).
178258
\emph{Journal of the Royal Statistical Society, Series B},
179-
\bold{33}, 1-70.
259+
\bold{33}, 1--70.
180260

181261
Diggle, P.J. (1985)
182262
A kernel method for smoothing point process data.
183263
\emph{Journal of the Royal Statistical Society, Series C (Applied Statistics)},
184-
\bold{34} 138-147.
264+
\bold{34} 138--147.
185265

186266
Gasser, Th. and \ifelse{latex}{\out{M\"{u}ller}}{Mueller}, H.-G. (1979).
187267
Kernel estimation of regression functions.
188268
In Th. Gasser and M. Rosenblatt (editors)
189269
\emph{Smoothing Techniques for Curve Estimation}, pages
190-
23-68. Springer, Berlin.
270+
23--68. Springer, Berlin.
191271
192272
Jones, M.C. and Foster, P.J. (1996)
193273
A simple nonnegative boundary correction method for kernel density

man/macros/newdefns.Rd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
%% Extra macro definitions for this package
2-
\newcommand{\ournewpaper}{Baddeley, A., Chang, Y-M., Davies, T.M. and Hazelton, M. (2024) In preparation.}
3-
\newcommand{\ournewpapercite}{Baddeley, Chang, Davies and Hazelton (2024)}
2+
\newcommand{\ournewpaper}{Baddeley, A., Davies, T.M. and Hazelton, M. (2025) Submitted for publication.}
3+
\newcommand{\ournewpapercite}{Baddeley, Davies and Hazelton (2025)}

0 commit comments

Comments
 (0)