I'm using a KDE plot to analyze the distribution of a sample population in terms of count by division. However, if I want to see how that distribution looks by some value (for example, dollar amount), but with the same x-axis (division) previously mentioned is there a way to do this?

To expand, I can currently look at a KDE plot and get a count of transactions by division (I've numbered the division on the x-axis). Now, for those same numbered divisions, I'd like to see the dollar amount contribution for the density (and not the count) since some divisions have high counts but low dollar amounts, and that is also relevant.

Any thoughts?

  • $\begingroup$ I don't think I understand what you're asking. Can you clarify with an example? $\endgroup$ Aug 30, 2018 at 21:50
  • $\begingroup$ I expanded with an example and more detail. $\endgroup$ Aug 30, 2018 at 21:55
  • $\begingroup$ Do you understand what a density is? What you're asking doesn't really make sense. $\endgroup$ Aug 30, 2018 at 22:01
  • $\begingroup$ There are some divisions that have high density in terms of transaction count, but low density in terms of dollar amount. Is there another plot you might suggest that could accomplish what I'm trying to do? $\endgroup$ Aug 30, 2018 at 22:05
  • $\begingroup$ Comparing densities is hard because kernel densities are not normalized probabilities. Also, it's a bit of an odd thing to compare the kernel density between observations. One thing you can do is to compare the ranks of the kernel densities, e.g. on a simple scatterplot. What's the point of comparing densities like this? Are you trying to measure how much of an outlier each observation is? $\endgroup$ Aug 30, 2018 at 22:22

1 Answer 1


If I've understood your question correctly, it should be as simple as applying the same calculation to the dollar amount. (I assumed you're using univariate data; it would probably be helpful to provide your plot, as well).

KDE produces a smoothed estimate of probability density for some distribution. If the data you use is measuring count of transactions, it will show the probability of a transaction being at some x-value (it's not clear from the question what this x-axis is... e.g. months?). If you instead use the size (sum) of the transactions, then you will retrieve a smoothed estimate of the probability of a transaction at some x-value, weighted by the size of the transaction.

If you are instead saying you want to see the distribution of transaction size, along with the distribution of number of transactions, then it sounds like you have a bivariate problem, and so would need a 2D KDE. This would give you a probability surface, were you to plot it.

  • $\begingroup$ Yes, that's helpful. Let me take your example of months since it applies here. Let's say I have 2 months of data just to keep this simple, and I use a KDE to get the probability of a transaction happening on one of the given months. But let's say that January had 1,000 transactions that were each 1 dollar, while February had 5 transactions of 10,000 each. Here, I'd like to see the spike at February since that's more pertinent in my example. Perhaps a 2D-KDE is the way to go. $\endgroup$ Aug 30, 2018 at 22:11
  • $\begingroup$ It sounds like either of the approaches I mention could provide what you need; the 2D is conceptually cleaner though, in separating the two variables. $\endgroup$
    – Zac
    Aug 30, 2018 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.