ASH2D | R Documentation |
Bivariate density estimation for given observations
ASH2D(
V,
data = NULL,
n = c(200, 200),
k = c(5, 5),
rx = c(1.1, 1.1),
safe = TRUE,
interpolation = c("fields", "akima"),
...
)
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 (defautl = TRUE, yes). |
... |
optional argument forwarded to the ash2 function. |
ASH2D
returns a numeric vector with estimated densities.
ASH1D
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.