# strange results from density plot

I am getting some very weird results. I have created a density plot for various continuous response variables, which are independent of each other.

I have noticed that the Density value seems to be very small. I know the height is meaningless and what needs to be interpreted is the area under the curve. Therefore I have tried to check the area under my curve, but I have obtained value much smaller than 1 - namely -15411.15:

strassenverkehr.densities <-plot(density.gs8m, ylim = c(0, 0.03), col = 9, lty = 1,
xlab = "Abweichung in %", xlim = c(-100,100) )
lines(density.ks12m, col=1, col = 7, lty = 8)
lines(density.bruecke4m, col = 2,lty = 3)
lines(density.bruecke8m, col = 3,lty = 4)
lines(density.bruecke12m, col = 4,lty = 5)
lines(density.FeldwegKies, col = 5,lty = 6)
lines(density.FeldwegAsph, col = 6,lty = 7)

> density.bruecke4m <- density (diff.bruecke4m)
> trapz(density.bruecke4m$x[density.bruecke4m$x < -40])
[1] -15411.45


I am afraid there is something seriously wrong with my analysis. Any ideas?

• That should indeed not happen. Then again, it's hard to help you if we can't recreate your problem. Can you please edit your post to contain a minimum (!) working (!) example? Thanks! Jun 7, 2017 at 8:32
• Most of your curves have a base about 100 units long and typical densities about 0.01. That checks: 100 * 0.01 = 1. The height units are not meaningless at all: density is probability per unit deviation. That is no more meaningless than density in physical science being mass per unit volume or population density being people per unit area. Jun 7, 2017 at 10:11
• Please describe the calculation you're trying to do, so we can see that makes sense, and then (if it does) you can ask on a site that takes programming questions whether your code actually does that. Jun 7, 2017 at 10:16

trapz(density.bruecke4m$x[density.bruecke4m$x < -40])

index <- (density.bruecke4m$x < -40) trapz(x=density.bruecke4m$x[index], y=density.bruecke4m\$y[index])