Is there a simple way to plot the difference between two probability density functions?
I can plot the pdfs of my data sets (both are one-dimensional vectors with r
It looks like you need to spend a little time learning how to use R (or any other language, for that matter). Help files are your friend.
From the output of ?density
:
Value [i.e. the data returned by the function]
If give.Rkern is true, the number R(K), otherwise an object with class "density" whose underlying structure is a list containing the following components.
x the n coordinates of the points where the density is estimated.
y the estimated density values. These will be non-negative, but can be zero [remainder of "value" deleted for brevity]
So, do:
foo<- density(data1)
bar<- density(data2)
plot(foo$y-bar$y)