Goodness-of-fit test using Kolmogorov-Smirnov I have a problem when I run the Komogorov-Smirnov test.
I have to samples of daily prices distributions estimated with density(). Now I would like to compare these two distributions with each other.
data.1:
Date           price
01.01.2010     1.2
02.01.2010     1.5
etc.

data.2:
Date           price
01.01.2009     0.1
02.01.2009     0.05
etc.

For the probability density, I calculated
density.1 <- density(data.1$price)
density.2 <- density(data.2$price)

Now I wanted to run the KS-test:
ks <- ks.test(density.1$x, density.2$x)

and got the results that p=1, hence the two distributions are the same. However, it is already observable from eye that they differ quite heavily from each other.
Where is my mistake?
Thank you, Dani
 A: First of all, you don't calculate the ks on an estimated density, as the ks test works on the empiric cumulative distribution function (ecdf). So you add the raw data:
ks.test(data.1$return, data.2$return)

Second, the $x is not the density, but the uniformly distributed grid constructed by the density function. So off course they are rather alike if the means are alike.
x <- rnorm(100,3)
y <- runif(100,min(x),max(x))
xx <- density(x)$x
yy <- density(y)$x
ks.test(xx,yy)
qqplot(xx,yy)
ks.test(x,y)
qqplot(x,y)

Last, please read in on a test if you use it before using it. Many mistakes in statistics are made by people that have no clue what they're actually doing. I don't say this to be rude, I just see things like this happen on an almost daily basis...
A: ks.test receives values, not densities. So you don't need to call density().
Probably what you should do is simply:
ks.test(data.1$return, data.2$return)

and the reason why you get p=1 is that you passed return.density.1$x instead of return.density.1$y.
density(foo)$x is the n coordinates of the points where the density is estimated.
