smi
smi

Reputation: 93

Problems with ks.test and ties

I have a distribution, for example:

d 
#[1]  4 22 15  5  9  5 11 15 21 14 14 23  6  9 17  2  7 10  4

Or, the vector d in dput format.

d <- c(4, 22, 15, 5, 9, 5, 11, 15, 21, 14, 14, 23, 6, 9, 17, 2, 7, 10, 4)

And when I apply the ks.test,:

gamma <- ks.test(d, "pgamma", shape = 3.178882, scale = 3.526563) 

This gives the following warning:

Warning message: In ks.test(d, "pgamma", shape = 3.178882, scale = 3.526563) : ties should not be present for the Kolmogorov-Smirnov test

I tried put unique(d), but obvious my data reduce the values and I wouldn't like this happen.
And the others manners and examples online, this example happen too, but the difference is the test show some results with the warning message, not only the message without values of ks.test.

Some help?

Upvotes: 5

Views: 16888

Answers (1)

Terru_theTerror
Terru_theTerror

Reputation: 5017

In gamma you can find your result, warning message is not blocking

d <- c(4, 22, 15, 5, 9, 5, 11, 15, 21, 14, 14, 23, 6, 9, 17, 2, 7, 10, 4)
gamma <- ks.test(d, "pgamma", shape = 3.178882, scale = 3.526563)

Warning message: In ks.test(d, "pgamma", shape = 3.178882, scale = 3.526563) : ties should not be present for the Kolmogorov-Smirnov test

gamma

    One-sample Kolmogorov-Smirnov test

data:  d
D = 0.14549, p-value = 0.816
alternative hypothesis: two-sided

You find an explanation of the warning in the help page ??ks.test

The presence of ties always generates a warning, since continuous distributions do not generate them. If the ties arose from rounding the tests may be approximately valid, but even modest amounts of rounding can have a significant effect on the calculated statistic.

As you can see some rounding is applied and the test is "approximately" valid.

Upvotes: 8

Related Questions