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
4
votes
1 answer

geom_density() grouped plot with discrete x axis is not smooth

I was working with a dataset that consists of two different groups of observations where the value is an integer. I wanted to plot the density of these to get a sense for how the different groups are distributed over the values. What happened was…
JasonAment
  • 223
  • 2
  • 7
4
votes
0 answers

Proportion of points within contours using stat_density_2d

How can I anticipate the proportion of points within the contours generated by stat_density_2d? For example creating 50 random points set.seed(2) points <- tibble(x = rnorm(50), y = rnorm(50)) And then ploting density contours ggplot(points, aes(x…
ColinTea
  • 998
  • 1
  • 9
  • 15
4
votes
4 answers

Density Value for each Return

I have a dataframe "foo" looking like this Date Return 1998-01-01 0.02 1998-01-02 0.04 1998-01-03 -0.02 1998-01-04 -0.01 1998-01-05 0.02 ... 1998-02-01 0.1 1998-02-02 -0.2 1998-02-03 -0.1 etc. I would like to add to this dataframe a new…
Dani
  • 2,325
  • 5
  • 24
  • 20
4
votes
2 answers

Pandas histogram plot with kde?

I have a Pandas dataframe (Dt) like this: Pc Cvt C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 0 1 2 0.08 0.17 0.16 0.31 0.62 0.66 0.63 0.52 0.38 1 2 2 0.09 0.15 0.13 0.49 0.71 …
Xhoan
  • 310
  • 2
  • 5
  • 13
4
votes
1 answer

rpy2 passing python reserved keyword arguments

I am trying to use r's density function through python, and I have to pass the 'from', 'to' arguments to the density functions. However, since the word 'from' is a reserved ketyword in python, how can I achieve this? Thank you. Here is the code so…
ssm
  • 620
  • 6
  • 24
4
votes
1 answer

Python - integrate 2D Kernel Density Estimation within contour lines

I would like to draw a contour plot of a Kernel Density Estimation, where the KDE is integrated within each of the contour plot filled areas. As an example, imagine I calculate the KDE of 2D data: data = np.random.multivariate_normal((0, 0), [[1,…
Laura
  • 360
  • 2
  • 15
4
votes
1 answer

R - simulate data for probability density distribution obtained from kernel density estimate

First off, I'm not entirely sure if this is the correct place to be posting this, as perhaps it should go in a more statistics-focussed forum. However, as I'm planning to implement this with R, I figured it would be best to post it here. Please…
nikUoM
  • 639
  • 1
  • 8
  • 18
4
votes
1 answer

How to extrapolate beyond the x points passed to `ksmooth`?

I have a kernel function like so: x <- 1:100 y <- rnorm(100, mean=(x/2000)^2) plot(x,y) kernel <- ksmooth(x,y, kernel="normal", bandwidth=10) print(kernel$y) If I try to predict at a point outside of the range of x values, it will give me NaN,…
makansij
  • 9,303
  • 37
  • 105
  • 183
4
votes
1 answer

3D density plot with multiple groups ( regression lines)

I would like to create plot something like this : Here we have two variables X = midyear and Y = yearend. I would like to create density plot for each level of X for Y. I could go to this point, but do not look pretty like what I have in mind…
jon
  • 11,186
  • 19
  • 80
  • 132
4
votes
2 answers

Overlay ggplot2 stat_density2d plots with alpha channels constant across groups

I would like to plot multiple groups in a stat_density2 plot with alpha values related to the counts of observations in each group. However, the levels formed by stat_density2d seem to be normalized to the number of observations in each group. For…
Guy
  • 61
  • 5
4
votes
1 answer

Estimate pdf of a vector using Gaussian Kernel

I am using Gaussian kernel to estimate a pdf of a data based on the equation where K(.) is Gaussian kernel, data is a given vector. z is bin from 1 to 256. size of bin is 1. I implemented by matlab code. However, the result show the amplitude of…
4
votes
1 answer

Why does scikit learn return log-density?

The function score_samples from sklearn.neighbors.kde.KernelDensity returns the log of the density. What is the advantage of that over returning the density it self? I know that the logarithm makes sense for probabilities, which are between 0 and 1…
user3429986
  • 1,035
  • 1
  • 7
  • 8
4
votes
1 answer

Implementing a different Kernel for 2D Kernel Density Estimation in R

I'm looking for some help understanding how to implement a 2-dimensional kernel density method, with a isotropic variance, and a bivariate normal kernel, kind of, but instead of using the typical distance, because the data is on the surface of the…
David Manheim
  • 2,553
  • 2
  • 27
  • 42
4
votes
2 answers

Finding 2D area defined by contour lines in Matlab

I am having difficulty with calculating 2D area of contours produced from a Kernel Density Estimation (KDE) in Matlab. I have three variables: X and Y = meshgrid which variable 'density' is computed over (256x256) density = density computed from the…
squishy
  • 344
  • 3
  • 12
4
votes
2 answers

KDE fails with two points?

The following trivial example returns a singular matrix. Why? Any ways to overcome it? In: from scipy.stats import gaussian_kde Out: In: points Out: (array([63, 84]), array([46, 42])) In: gaussian_kde(points) Out: (array([63, 84]), array([46,…
Josh
  • 11,979
  • 17
  • 60
  • 96