Learn R Programming

deamer (version 1.0)

deamerKE: Density estimation with known error density

Description

deamerKE performs a deconvolution estimation of the density of a noisy variable ('y') under the hypothesis of a known density of the noise ("KE" for "known error"). deamerKE allows to choose between a Gaussian or a Laplace density for the noise. The standard deviation of the noise (resp. the scale parameter) is required. By default, deamerKE will consider the noise centered around zero.

Usage

deamerKE(y, mu, sigma, noise.type, grid.length = 100, from, to, na.rm = FALSE)

Arguments

y
Numeric. The vector of noisy observations
mu
Numeric. The (known) mean of the noise. Defaults to zero.
sigma
Numeric. The (known) standard deviation of the noise if noise.type="Gaussian" or scale if noise.type="Laplace"
noise.type
Character. Defines the type of density for the noise. Only "Gaussian" or "Laplace" are supported. Defaults to "Gaussian"
grid.length
Numeric. Optional. The number of points of the grid the estimation is performed on. Defaults to 100.
from
Numeric. Optional. The lower bound of the grid the estimation is performed on. Defaults to min(y).
to
Numeric. Optional. The upper bound of the grid the estimation is performed on. Defaults to max(y).
na.rm
Logical. Optional. If na.rm=TRUE, NAs will be removed before estimation. Defaults to FALSE.

Value

An object of class 'deamer'

Warning

deamerKE is not implemented for heteroscedastic errors.

Details

The model is $y = x + e$ where $x$ has an unknown density $f$ and $e$ is a symmetric variable around mu (either Laplace or Gaussian). Therefore, deamerKE can directly handle non-centered noise by specifying mu. The Gaussian mean and standard deviation have the general meaning. The Laplace density function is parameterized as: $$\frac{1}{2\sigma}exp\Big(-\frac{|x-\mu|}{\sigma}\Big)$$

References

Comte F, Rozenholc Y, Taupin M-L. Penalized Contrast Estimator for Adaptive Density Deconvolution. The Canadian Journal of Statistics / La Revue Canadienne de Statistique. 2006; 34(3):431-52.

See Also

deamer, deamerRO, deamerSE, deamer-class

Examples

Run this code

#########################################################
#EXAMPLE 1: known error, Laplacian

set.seed(12345)
n=1000
rff=function(x){
  u=rbinom(x, 1, 0.5)
  X=u*rnorm(x, -2, 1)+(1-u)*rnorm(x,2,1)
  return(X)
}
x <- rff(n) #a mixed gaussian distribution

# true density function:
f.true=function(x) (0.5/(sqrt(2*pi)))*(exp(-0.5*(x+2)^2) + exp(-0.5*(x-2)^2))

e <- rlaplace(n, 0, 0.5)
y <- x + e

est <- deamerKE(y, noise.type="laplace", sigma=0.5)
est

curve(f.true(x), -6, 6, lwd=2, lty=3)
lines(est, lwd=2)
lines(density(y), lwd=2, lty=4)
legend("topleft", bty="n", lty=c(1,3,4), lwd=2, legend=c("deamerKE", "true density", 
       "kernel density\nof noisy obs."))

#########################################################
#EXAMPLE 2: known error, Laplacian and non-centered 

set.seed(12345)
n=1000
rff=function(x){
  u=rbinom(x, 1, 0.5)
  X=u*rnorm(x, -2, 1)+(1-u)*rnorm(x,2,1)
  return(X)
}
x <- rff(n) #a mixed gaussian distribution

# true density function:
f.true=function(x) (0.5/(sqrt(2*pi)))*(exp(-0.5*(x+2)^2) + exp(-0.5*(x-2)^2))

e <- rlaplace(n, 2, 0.5) #mean=2 and not zero!
y <- x + e

est <- deamerKE(y, noise.type="laplace", mu=2, from=-4, to=4, sigma=0.5)
est

curve(f.true(x), -6, 6, lwd=2, lty=3)
lines(est, lwd=2)
lines(density(y), lwd=2, lty=4)
legend("topleft", bty="n", lty=c(1,3,4), lwd=2, legend=c("deamerKE", "true density", 
       "kernel density\nof noisy obs."))


Run the code above in your browser using DataLab