I have data with continuous frequency and a continuous support which I'd like to analyze and plot using a kernel density estimate in R. I can create the basic plot in JMP fairly easily using the Distribution platform making using of the Freq option as shown below. It generates a histogram from which I can quickly overlap a density estimate.

JMP's handy distribution form

What's the equivalent of this Freq option in R?

Read on if you are interested in why I'm trying to do this. I am aiming to add vertical lines at the specific local maximums in the density, and that isn't so easy to do with JMP in an automated fashion. Plus, I'd like to improve my R knowledge. Below is a plot that very roughly captures what I'm trying to get to with this data. The curve is a kernel density estimate. I don't care about the shadowgram, but I couldn't get JMP to make the plot without either a histogram or a shadowgram visible. I couldn't find any tutorials showing how to do anything like this in R. Could you point me in the right direction?

density plot with a random shadowgram thrown in

Here is the data set I used to make the plot above.

x   y
0   0.5314379598
0.1 1.3521410475
0.2 0.0449186138
0.3 0.4225592288
0.4 0.0496982985
0.5 1.1107962989
0.6 0.2438757387
0.7 0.7023629225
0.8 1.7466573415
0.9 0.7134595708
1   1.1313968897
1.1 0.6055951286
1.2 0.2924553991
1.3 0.2913429266
1.4 0.3221193803
1.5 0.4683161595
1.6 0.682958405
1.7 0.1082714352
1.8 0.0489443405
1.9 0.3309649262
  • $\begingroup$ I'm sorry, I got a little lost in all that. What exactly is it you want to do? As far as I can discern, you want (a) a kernel density estimate, (b) to estimate the peak locations, (c) do a plot with both ... and what else? Did you want any of the other things you mentioned or not? $\endgroup$ – Glen_b -Reinstate Monica Nov 25 '14 at 22:02
  • $\begingroup$ What's the data you have there? is that the density estimate itself, rather than the raw data from which an estimate is generated? $\endgroup$ – Glen_b -Reinstate Monica Nov 25 '14 at 22:06
  • $\begingroup$ 1) I mainly want to know how to generate the density estimate using this kind of data. It's a two click operation in JMP, but I'm not sure how to approach it with R. $\endgroup$ – wdkrnls Nov 25 '14 at 23:25
  • $\begingroup$ 2) the data I have there was used as input to make the density estimate using the form I show in the JMP dialog screenshot. $\endgroup$ – wdkrnls Nov 25 '14 at 23:26
  • $\begingroup$ I have a set of empirical density points already (since that is what my process is measuring), and I want to fit that with a density function where I can play with the bandwidth and then do the other things I mentioned, but I'm not sure how to approach getting access to the bandwidth when I am fitting from frequencies already. $\endgroup$ – wdkrnls Dec 1 '14 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.