2

I have two data sets that I am comparing using a ked2d contour plot on a log10 scale, Here I will use an example of the following data sets,

b<-log10(rgamma(1000,6,3))
a<-log10((rweibull(1000,8,2)))
density<-kde2d(a,b,n=100)
filled.contour(density,color.palette=colorRampPalette(c('white','blue','yellow','red','darkred')))

This produces the following plot, enter image description here

Now my question is what does the z values on the legend actually mean? I know it represents where most the data lies but 0-15 confuses me. I thought it could be a percentage but without the log10 scale I have values ranging from 0-1? And I have also produced plots with scales 1-1.2, 1-2 using my real data.

rene
  • 41,474
  • 78
  • 114
  • 152
  • does `plot(density(density$z))` help? or `range(density$z)` – rawr Feb 12 '14 at 18:35
  • I did try your suggestions but I still can't work out why the range(density$z) is as seen in the legend. – PhillipPhillipson Feb 22 '14 at 13:19
  • the z values are the estimated density. x and y in density are the coordinates in the plot that correspond to densities (z) at those points. If you plot the x values and y values with a color scale corresponding to the values of z, you will see a similar plot that `filled.contour` returns. As for why the raw values are what they are, you'd have to know how to estimate kernel densities. – rawr Feb 22 '14 at 17:50

1 Answers1

1

The colors represent the the values of the estimated density function ranging from 0 to 15 apparently. Just like with your other question about the odd looking linear regression I can relate to your confusion.

You just have to understand that a density's integral over the full domain has to be 1, so you can use it to calculate the probability of an observation falling into a specific region.

Community
  • 1
  • 1
Raffael
  • 19,547
  • 15
  • 82
  • 160