Questions tagged [kernel-density]

kernel density estimation is a non-parametric way to estimate the probability density function of a random variable.

Kernel density estimation is a fundamental data smoothing problem where inferences about the population are made, based on a finite data sample. Kernel density estimates are closely related to histograms, but can be endowed with properties such as smoothness or continuity by using a suitable kernel

http://en.wikipedia.org/wiki/Kernel_density_estimation

656 questions
5
votes
2 answers

Is there a way to make the density() function in R use counts vs. probability?

Is there a way to make the density() function in R use counts vs. probability? For example, I have two options when examining density distributions using the histogram function hist: hist(x,freq=F) #"graphic is a representation of frequencies, the…
5
votes
1 answer

How to implement Kernel density estimation in multivariate/3D

I have dataset like the following fromat and im trying to find out the Kernel density estimation with optimal bandwidth. data = np.array([[1, 4, 3], [2, .6, 1.2], [2, 1, 1.2], [2, 0.5, 1.4], [5, .5, 0], [0, 0, 0], [1, 4, 3], [5,…
jquery404
  • 653
  • 1
  • 12
  • 26
5
votes
1 answer

Difference in 2D KDE produced using kde2d (R) and ksdensity2d (Matlab)

While trying to port some code from Matlab to R I have run into a problem. The gist of the code is to produce a 2D kernel density estimate and then do some simple calculations using the estimate. In Matlab the KDE calculation was done using the…
mkr
  • 65
  • 1
  • 4
5
votes
1 answer

Overlay density plot excludes histogram values

I want to overlay a density curve to a frequency histogram I have constructed. For the frequency histogram I used aes(y=..counts../40) because 40 is my total sample number. I used aes(y=..density..*0.1) to force the density to be somewhere between 0…
Matias Andina
  • 4,029
  • 4
  • 26
  • 58
5
votes
1 answer

Find local minimum in bimodal distribution with r

My data are pre-processed image data and I want to seperate two classes. In therory (and hopefully in practice) the best threshold is the local minimum between the two peaks in the bimodal distributed data. My testdata is:…
Iris
  • 1,072
  • 3
  • 10
  • 22
5
votes
1 answer

Implementing a 2D, FFT-based Kernel Density Estimator in python, and comparing it to the SciPy implimentation

I need code to do 2D Kernel Density Estimation (KDE), and I've found the SciPy implementation is too slow. So, I've written an FFT based implementation, but several things confuse me. (The FFT implementation also enforces periodic boundary…
lnmaurer
  • 1,687
  • 4
  • 22
  • 32
5
votes
1 answer

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…
giorgioca
  • 713
  • 1
  • 8
  • 21
5
votes
3 answers

R ggplot2 - Simple plot- cannot specify log axis limits

I'm trying to create a simple densityplot in R in ggplot2. Here's my code which works great. d <- ggplot(result, aes(x=result$baseMeanA)) d + geom_density(colour="darkgreen", size=2, fill="darkgreen") + scale_x_log10() + scale_y_continuous(limits…
user1678000
  • 73
  • 1
  • 3
  • 9
4
votes
3 answers

ValueError: Multi-dimensional indexing (e.g. `obj[:, None]`) is no longer supported. Convert to a numpy array before indexing instead

I am trying to plot a histogram using seaborn. When I try to set kde=True this error is returned: ValueError: Multi-dimensional indexing (e.g. obj[:, None]) is no longer supported. Convert to a numpy array before indexing…
4
votes
2 answers

Emulating deprecated seaborn distplots

Seaborn distplot is now deprecated and will be removed in a future version. It is suggested to use histplot (or displot as a figure-level plot) as an alternative. But the presets differ between distplot and histplot: from matplotlib import pyplot as…
Mr. T
  • 11,960
  • 10
  • 32
  • 54
4
votes
0 answers

Is there a python equivalent function of Kde2d function in R, which returns us the same outputs in the form x, y and z?

I am getting different outputs from both R and Python on using these two equivalent functions on the same sample data. I am also computing the bandwidth separately in python to make sure its same as that of R. Can someone please help.. Running R in…
ButterCup
  • 71
  • 1
  • 4
4
votes
1 answer

scipy gaussian_kde produces different results depending on method used (weights vs no weights)

I have a series of coordinates that I want to apply a KDE to, and have been using scipy.stats.gaussian_kde to do so. The issue here is that this function expects a discrete set of coordinates, which it would then perform a density estimation…
Recessive
  • 1,780
  • 2
  • 14
  • 37
4
votes
2 answers

Calculate percentiles if we have probability density function data as x and y

I have data extracted from a pdf graph where x represents incubation times and y is the density in a csv file. I would like to calculate the percentiles, such as 95%. I'm a bit confused, should I calculate the percentile using the x values only,…
4
votes
2 answers

Seaborn KDEPlot - not enough variation in data?

I have a data frame containing ~900 rows; I'm trying to plot KDEplots for some of the columns. In some columns, a majority of the values are the same, minimum value. When I include too many of the minimum values, the KDEPlot abruptly stops showing…
iayork
  • 6,420
  • 8
  • 44
  • 49
4
votes
1 answer

Extracting boundaries of dense regions of 1s in a huge list of 1s and 0s

I'm not sure how to word my problem. But here it is... I have a huge list of 1s and 0s [Total length = 53820]. Example of how the list looks like - [0,1,1,1,1,1,1,1,1,0,0,0,1,1,0,0,0,0,0,0,1,1...........] The visualization is given below. x-axis:…
Darpan
  • 61
  • 5