ASH1D: Univariate density estimation for given observations

Description Usage Arguments Value See Also Examples

View source: R/ASH.R

Description

The ASH1D function performs univariate density estimations based on the Average Shifted Histogram method implemented in ash1 followed by a linear interpolation of density values.

Usage

1
ASH1D(x, data = NULL, n = 200, k = 5, r = NULL, rx = 1.1, safe = TRUE, ...)

Arguments

x

numeric vector.

data

numeric vector (optional).

n

number of bins.

k

smoothing in number of bins.

r

optional numeric vector determining the range of values to be considered.

rx

range expansion.

safe

logical (default = TRUE, yes).

...

optional argument (kopt) forwarded to the ash1 function.

Value

ASH1D returns a numeric vector with estimated densities.

See Also

ASH2D

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
## Not run: 

n1 <- 30000
n2 <- 60000
g <- c(rep(1, n1), rep(2, n2))
x <- c(rnorm(n1, 0, 1), rnorm(n2, 0, 5))

o <- order(x)
x <- x[o]
g <- g[o]

dt <- ASH1D(x, k = 5)
d1 <- ASH1D(x, data = x[g == 1], k = 10)
d2 <- ASH1D(x, data = x[g == 2], k = 10)

clr <- c(
  dt        = grey(0.0, 0.6),
  d1        = rgb(1.0, 0.5, 0.0, 0.6),
  d2        = rgb(0.0, 0.5, 1.0, 0.6),
  `d1 + d2` = rgb(1.0, 0.0, 0.0, 0.6)
)

EmptyPlot(xlim = range(x), ylim = range(dt, d1, d2, d1 + d2))
par(lwd = 1.5)
lines(x, d1 + d2, col = clr[4])
lines(x, dt, col = clr["dt"])
lines(x, d1, col = clr["d1"])
lines(x, d2, col = clr["d2"])
legend("topright", legend = names(clr), fill = clr, bty = "n")

## End(Not run)

benja0x40/QuickShift documentation built on Jan. 22, 2021, 7:43 p.m.