3
$\begingroup$

I have a very strange problem. I don't think it's a bug because I've tried it a few ways with similar results.

I have three sets of data that are all related to each other. When I make density plots of them individually (with the sm package), like so:

sm.density(sim$V2)

I get this curve:

One of the curves individually

And the other two curves look very similar. But! When I plot them all onto one graph for comparison, I get very different results:

All the curves together

The first curve I showed you has turned into one of those shorter, jagged curves in this plot. So, I can't figure out how the first smooth curve turns into something so jagged, with apparently an extra peak appearing as well.

Does anyone have any idea what might account for this? Could there be some difference in how the density is being calculated?

$\endgroup$
1
  • 2
    $\begingroup$ It may be easier for people to help you if you provide a reproducible example that others can run themselves that illustrates this behavior. $\endgroup$
    – joran
    Commented Aug 21, 2011 at 1:39

1 Answer 1

5
$\begingroup$

The sm.density function picks a smoothing parameter for you, unless you specify one. It seems like it chose different smoothing parameters for the different variables.

Try setting h to some fixed value. e.g.

sm.density(sim$v2, h = 1)

for each graph

$\endgroup$
2
  • 1
    $\begingroup$ Agreed, and since the blue curve is so different from other two, I imagine the smoothing parameter choice is difficult to get right. What smooths the smaller curves might mush the taller curve entirely. $\endgroup$
    – Wayne
    Commented Aug 21, 2011 at 15:15
  • 1
    $\begingroup$ I suspect this is the source of the problem as well - an automatic process choosing the smoothing parameter, and choosing a different one in each case. I agree that you should try fixing the smoothing parameter and rerunning the plots. $\endgroup$
    – Fomite
    Commented Aug 22, 2011 at 1:09

Your Answer

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

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