denspr {siggenes} | R Documentation

## Density Estimation

### Description

Estimates the density of a vector of observations by a Poisson regression fit to histogram counts.

### Usage

      denspr(x, n.interval = NULL, df = 5, knots.mode = TRUE,
          type.nclass = c("wand", "scott", "FD"), addx=FALSE)

### Arguments

`x` | a numeric vector containing the observations for which the density should be estimated.
`n.interval` | an integer specifying the number of cells for the histogram. If `NULL`, `n.interval` is estimated by the method specified by `type.nclass`.
`df` | integer specifying the degrees of freedom of the natural cubic spline used in the Poisson regression fit.
`knots.mode` | if `TRUE` the `df` - 1 knots are centered around the mode and not the median of the density, where the mode is estimated by the midpoint of the cell of the histogram that contains the largest number of observations. If `FALSE`, the default knots are used in the function `ns`. Thus, if `FALSE` the basis matrix will be generated by `ns(x, df = 5)`.
`type.nclass` | character string specifying the procedure used to compute the number of cells of the histogram. Ignored if `n.interval` is specified. By default, the method of Wand (1994) with `level = 1` (see the help page of `dpih` in the package KernSmooth) is used. For the other choices, see `nclass.scott`.
`addx` | should `x` be added to the output? Necessary when the estimated density should be plotted by `plot(out)` or `lines(out)`, where `out` is the output of `denspr`.

### Value

An object of class `denspr` consisting of

`y` | a numeric vector of the same length as `x` containing the estimated density for each of the observations
`center` | a numeric vector specifying the midpoints of the cells of the histogram
`counts` | a numeric vector of the same length as `center` composed of the number of observations of the corresponding cells
`x.mode` | the estimated mode
`ns.out` | the output of `ns`
`type` | the method used to estimate the numbers of cells
`x` | the input vector `x` if `addx = TRUE`; otherwise, `NULL`.

### Author(s)

Holger Schwender,holger.schw@gmx.de

### References

Efron, B., and Tibshirani, R. (1996). Using specially designed exponential families for density estimation. Annals of Statistics, 24, 2431–2461.

Wand, M.P. (1997). Data-based choice of histogram bin width. American Statistician, 51, 59–64.

### See Also

`cat.ebam`

### Examples

    ## Not run:
    # Generating some random data.
    x <- rnorm(10000)
    out <- denspr(x, addx=TRUE)
    plot(out)

    # Or for an asymmetric density.
    x <- rchisq(10000, 2)
    out <- denspr(x, df=3, addx=TRUE)
    plot(out)

    ## End(Not run)

[Package siggenes version 1.66.0 Index]