ASH2D: Bivariate density estimation for given observations

Description Usage Arguments Value See Also Examples

View source: R/ASH.R

Description

The ASH2D function performs bivariate density estimations based on the Average Shifted Histogram method implemented in ash2 followed by a bilinear interpolation of density values.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ASH2D(
  V,
  data = NULL,
  n = c(200, 200),
  k = c(5, 5),
  rx = c(1.1, 1.1),
  safe = TRUE,
  interpolation = c("fields", "akima"),
  ...
)

Arguments

V

numeric matrix with 2 columns.

data

numeric matrix with 2 columns (optional).

n

number of bins.

k

smoothing in number of bins.

rx

range expansion.

safe

logical (default = TRUE, yes).

interpolation

bilinear interpolation function, either "fields" (default, see interp.surface from package fields) or "akima" (see bilinear from package akima).

...

optional argument (kopt) forwarded to the ash2 function.

Value

ASH2D returns a numeric vector with estimated densities.

See Also

ASH1D

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
## Not run: 

n1 <- 10000
n2 <- 40000
g <- c(rep(1, n1), rep(2, n2))
V <- cbind(
  c(rnorm(n1, 0, 1), rnorm(n2, 0, 5)),
  c(rnorm(n1, 0, 1), rnorm(n2, 0, 5))
)

dt <- ASH2D(V, k = c(5, 5))
d1 <- ASH2D(V, data = V[g == 1, ], k = c(10, 10))
d2 <- ASH2D(V, data = V[g == 2, ], k = c(10, 10))

# Preview of densities using projection on the x axis

layout(matrix(1:4, 2, 2, byrow = TRUE))

ylim <- range(dt, d1, d2, d1 + d2)
r <- BivariateDensity(
  V[, 1], d1, ylim = ylim, xlab = "x", ylab = "d", main = "d1"
)
r <- BivariateDensity(
  V[, 1], d2, ylim = ylim, xlab = "x", ylab = "d", main = "d2"
)
r <- BivariateDensity(
  V[, 1], d1 + d2, ylim = ylim, xlab = "x", ylab = "d", main = "d1 + d2"
)
r <- BivariateDensity(
  V[, 1], dt, ylim = ylim, xlab = "x", ylab = "d", main = "dt"
)

# Scatteplots showing densities as shades of grey

o <- order(dt)
r <- range(V)

layout(matrix(1:4, 2, 2, byrow = TRUE))
par(pch = 20)

EmptyPlot(xlim = r, ylim = r, main = "d1")
points(V[o, ], col = colorize(d1[o], color = "WGB"), cex = 0.5)

EmptyPlot(xlim = r, ylim = r, main = "d2")
points(V[o, ], col = colorize(d2[o], color = "WGB"), cex = 0.5)

EmptyPlot(xlim = r, ylim = r, main = "d1 + d2")
points(V[o, ], col = colorize((d1 + d2)[o], color = "WGB"), cex = 0.5)

EmptyPlot(xlim = r, ylim = r, main = "dt")
points(V[o, ], col = colorize(dt[o], color = "WGB"), cex = 0.5)

## End(Not run)

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