# Plotting density in two different ways gives wildly different looking curves

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: And the other two curves look very similar. But! When I plot them all onto one graph for comparison, I get very different results: 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? - It may be easier for people to help you if you provide a reproducible example that others can run themselves that illustrates this behavior. – joran Aug 21 '11 at 1:39 ## 1 Answer 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

-
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. – Wayne Aug 21 '11 at 15:15
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. – EpiGrad Aug 22 '11 at 1:09