View source: R/general.purpuse.utilities.R
pointKde2d | R Documentation |
similar to MASS::kde2d but calculates density for supplied points
pointKde2d(
x,
y,
kernel = dnorm,
approx = length(x) > 2000,
random_seed = 123,
k = min(length(x), 1000)
)
x , y |
data coordinates |
kernel |
kernel to be used (dnorm by default) |
approx |
logical, should density be estimated on subset of point. Approximate mode is much faster for large (length(x)>5000) datasets |
random_seed |
random seed to chose subset in approximate mode |
k |
subset size to use in approximate mode. 1000 is good starting point |
numeric vector with density estimates
x = rnorm(10000,mean = c(-300,300,300),sd=100)
y = rnorm(10000,x*c(-1,1),sd=100)
system.time(d1 <- pointKde2d(x,y,approx = F))
system.time(d2 <- pointKde2d(x,y,approx = T,k=100))
system.time(d3 <- pointKde2d(x,y,approx = T,k=1000))
par(mfrow=c(2,2))
plot(x,y,col=num2col(d1),pch=19,cex=0.2)
plot(x,y,col=num2col(d2),pch=19,cex=0.2)
plot(x,y,col=num2col(d3),pch=19,cex=0.2)
plot(d1,d3,pch=16,cex=0.2)
abline(a=0,b=1,col='red')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.