FAQ Database Discussion Community


Overlay density plot excludes histogram values

r,ggplot2,frequency,kernel-density
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 and 1 since my binwidth is 0.1. However, density curve...

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

r,matlab,kernel-density
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 function ksdensity2d.m. In...

How to compare the distributions of two vectors in R?

python,r,distribution,kernel-density
Here is a screenshot of my dataset: Here's what it's about: Imagine that you work in a delivery company and, for some reason, the package fails to be delivered to the client. The distribution of the number of packages returned changes according to the monetary value of the package, which...

Custom histogram density evaluation in MatLab

matlab,histogram,kernel-density
Does MatLab have any built in function to evaluate the density of a random variable from a custom histogram? (I suspect there are probably lots of ways to do this, I am just looking to see if there is already any builtin MatLab functionality). Thanks.

Estimate pdf of a vector using Gaussian Kernel

matlab,statistics,probability,kernel-density,probability-density
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...

Inconsistency between gaussian_kde and density integral sum

python,numpy,kernel-density
Can one explain why after estimation of kernel density d = gaussian_kde(g[:,1]) And calculation of integral sum of it: x = np.linspace(0, g[:,1].max(), 1500) integral = np.trapz(d(x), x) I got resulting integral sum completely different to 1: print integral Out: 0.55618 ...

KDE in python with different mu, sigma / mapping a function to an array

python,arrays,kernel-density
I have a 2-dimensional array of values that I would like to perform a Gaussian KDE on, with a catch: the points are assumed to have different variances. For that, I have a second 2-dimensional array (with the same shape) that is the variance of the Gaussian to be used...