Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I achieve the R kernel density estimate plot using D3.js?

This is my R code:

x <- c(5.89,6.81,6.69,7.61,5.44,6.17)
y <- c(1,0.09392423,0.07090779,0.0687634,0.06819157,0.06261615)

plot(density(x, bw=0.050, adjust=1, kernel="gaussian",weights=(y),n=1000))

I'm trying to achieve the same result using D3.js or any other equivalent JavaScript library..

Can somebody please help?

like image 742
giorgioca Avatar asked Apr 22 '13 12:04

giorgioca


People also ask

How do you calculate kernel density in R?

The statistical properties of a kernel are determined by σ K 2 = ∫ t 2 K ( t ) d t \sigma^2_K = \int t^2 K(t) dt σK2=∫t2K(t)dt which is always =1 for our kernels (and hence the bandwidth bw is the standard deviation of the kernel) and R ( K ) = ∫ K 2 ( t ) d t R(K) = \int K^2(t) dt R(K)=∫K2(t)dt .

How is kernel density estimate calculated?

Kernel Density Estimation (KDE) It is estimated simply by adding the kernel values (K) from all Xj. With reference to the above table, KDE for whole data set is obtained by adding all row values. The sum is then normalized by dividing the number of data points, which is six in this example.

What is kernel density estimation plot?

A kernel density estimate (KDE) plot is a method for visualizing the distribution of observations in a dataset, analogous to a histogram. KDE represents the data using a continuous probability density curve in one or more dimensions.

Which method is used for density estimation?

Some of the most popular and useful density estimation techniques are mixture models such as Gaussian Mixtures ( GaussianMixture ), and neighbor-based approaches such as the kernel density estimate ( KernelDensity ).


1 Answers

Have you seen the kernel density estimation example?

kernel density estimation

Admittedly it uses the Epanechnikov kernel rather than Gaussian, but that part could be modified.

like image 139
mbostock Avatar answered Oct 01 '22 02:10

mbostock