Estimates a multidimensional probability density function (and its first derivatives) using local polynomial kernel smoothing of linearly binned data.

```
np.den(x, ...)
# Default S3 method
np.den(
x,
nbin = NULL,
h = NULL,
degree = 1 + as.numeric(drv),
drv = FALSE,
ncv = 0,
...
)
# S3 method for class 'bin.den'
np.den(x, h = NULL, degree = 1 + as.numeric(drv), drv = FALSE, ncv = 0, ...)
# S3 method for class 'bin.data'
np.den(x, h = NULL, degree = 1 + as.numeric(drv), drv = FALSE, ncv = 0, ...)
# S3 method for class 'svar.bin'
np.den(x, h = NULL, degree = 1 + as.numeric(drv), drv = FALSE, ncv = 0, ...)
```

- x
a (data) object used to select a method.

- ...
further arguments passed to or from other methods.

- nbin
vector with the number of bins on each dimension.

- h
(full) bandwidth matrix (controls the degree of smoothing; only the upper triangular part of h is used).

- degree
degree of the local polynomial used. Defaults to 1 (local linear estimation).

- drv
logical; if

`TRUE`

, the matrix of estimated first derivatives is returned.- ncv
integer; determines the number of cells leaved out in each dimension. Defaults to 0 (the full data is used) and it is not normally changed by the user in this setting. See "Details" below.

Returns an S3 object of class `np.den`

(locpol den + bin den + grid par.).
A `bin.den`

object with the additional (some optional) 3 components:

- est
vector or array (dimension

`nbin`

) with the local polynomial density estimates.- locpol
a list with 6 components:

`degree`

degree of the polinomial.`h`

bandwidth matrix.`rm`

residual mean (of the escaled bin counts).`rss`

sum of squared residuals (of the escaled bin counts).`ncv`

number of cells ignored (in each dimension).

- deriv
(if requested) matrix of first derivatives.

Standard generic function with a default method (interface to the
fortran routine `lp_data_grid`

), in which argument `x`

is a vector or matrix of covariates (e.g. spatial coordinates).
In this case, the data are binned (calls `bin.den`

) and the local fitting
procedure is applied to the scaled bin counts (calls `np.den.bin.den`

).

If parameter `nbim`

is not specified is set to `rep(25, ncol(x))`

.

A multiplicative triweight kernel is used to compute the weights.

If `ncv > 1`

, estimates are computed by leaving out cells with indexes within
the intervals \([x_i - ncv + 1, x_i + ncv - 1]\), at each dimension i, where \(x\)
denotes the index of the estimation position.

Wand, M.P. and Jones, M.C. (1995) *Kernel Smoothing*. Chapman and Hall, London.