Last data update: 2014.03.03

R: Kernel Density Estimation with Reflection
 density.reflected R Documentation

## Kernel Density Estimation with Reflection

### Description

The function `density.reflected` computes kernel density estimates for univariate observations using reflection in the borders.

### Usage

```## S3 method for class 'reflected'
density(x, lower = -Inf, upper = Inf, weights= NULL, ...)
```

### Arguments

 `x` a numeric vector of data from which the estimate is to be computed. `lower` the lower limit of the interval to which x is theoretically constrained, default -Inf. `upper` the upper limit of the interval to which x is theoretically constrained, default, Inf. `weights` numeric vector of non-negative observation weights, hence of same length as x. The default NULL is equivalent to weights = rep(1/length(x), length(x)). `...` further `density` arguments.

### Details

`density.reflected` is called by `dgeometric.test` and computes the density kernel estimate of a univariate random sample `x` of a random variable defined in the interval `(lower,upper)` using the default options of `density` and reflection in the borders. This avoids the density kernel estimate being underestimated in the proximity of `lower` or `upper`. For unbounded variables, `density.reflected` generates the same output as `density` with its default options.

### Value

An object of the class `density` with borders correction, whose underlying structure is a list containing the following components.

 `x` the `n` coordinates of the points where the density is estimated. `y` the estimated density values. These will be non-negative. `bw` the bandwidth used. `n` the sample size after elimination of missing values. `call` the call which produced the result. `data.name` the deparsed name of the `x` argument. `has.na` logical, for compatibility (always `FALSE`).

The `print` method reports `summary` values on the `x` and `y` components.

### Note

The function is based on `density`.

Jose M. Pavia

### References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) "The New S Language." Wadsworth & Brooks/Cole (for S version).

Scott, D. W. (1992) "Multivariate Density Estimation. Theory, Practice and Visualization." New York: Wiley.

Sheather, S. J. and Jones M. C. (1991) "A reliable data-based bandwidth selection method for kernel density estimation." J. Roy. Statist. Soc. B, 683–690.

Silverman, B. W. (1986) "Density Estimation." London: Chapman and Hall.

Venables, W. N. and Ripley, B. D. (2002) "Modern Applied Statistics with S." New York: Springer.

`dgeometric.test` and `density`

### Examples

```set.seed(234)
x <- runif(2000)
dx <- density.reflected(x,0,1)

## Plot of the density estimate with and without reflection
par(mfcol=c(1,2))
plot(dx, xlim=c(-0.1,1.1), ylim=c(0,1.1))
abline(h=1, col="red")

plot(density(x), xlim=c(-0.1,1.1), ylim=c(0,1.1))
abline(h=1, col="blue")
```

### Results

```
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(GoFKernel)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/GoFKernel/density.reflected.Rd_%03d_medium.png", width=480, height=480)
> ### Name: density.reflected
> ### Title: Kernel Density Estimation with Reflection
> ### Aliases: density density.reflected
> ### Keywords: density
>
> ### ** Examples
>
> set.seed(234)
> x <- runif(2000)
> dx <- density.reflected(x,0,1)
>
> ## Plot of the density estimate with and without reflection
> par(mfcol=c(1,2))
> plot(dx, xlim=c(-0.1,1.1), ylim=c(0,1.1))
> abline(h=1, col="red")
>
> plot(density(x), xlim=c(-0.1,1.1), ylim=c(0,1.1))
> abline(h=1, col="blue")
>
>
>
>
>
> dev.off()
null device
1
>

```