Difference between two density plots

前端 未结 2 1044
暖寄归人
暖寄归人 2021-01-15 12:04

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

2条回答
  •  不知归路
    2021-01-15 12:50

    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) 
    

提交回复
热议问题