# Kolmogorov-Smirnov test in R

I would like to optimize a physical model using kolmogorov-smirnov test between the experimental data and generated data. The output of ks.text(x,y) give me the distance D and the p-value. Which is the relation between them and which is suitable for my task? namely i should take the model that give me a smaller distance or a smaller p-value?

-

A low p-value means that it is likeley that the data is different from the model. So you want a high p-value to have a good fitting.