Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • ksmirnov test

    Can anyone see what I'm doing wrong here -- all tests reject uniform distribution when I think I have generated uniform test data.
    Regards
    Laurence

    Code:
    drop _all
    set obs 100
    capture drop test?
    gen      testV=1 // constant
    gen byte testX = 1+int((10-1+1)*runiform()) // uniform over 1 to 10
    gen      testY = runiform() // uniform
    gen byte testZ = 10+rnormal() // normal 7 to 12
    browse test*
    ksmirnov testV  = runiform()
    ksmirnov testX  = runiform()
    ksmirnov testY  = runiform()
    ksmirnov testZ  = runiform()

  • #2
    Well, of course testV, and testZ are not uniformly distributed. Neither is testX because it is generated as a byte, so it takes on only integer values from 1 to 10.

    TestY is, indeed, a standard (on [0,1]) uniform variate. The problem is that the expression on the right side of the equals sign in ksmirnov has to be a functional representation of the cumulative distribution of the variable, F(). runiform() is not a distribution function at all: it is a function that returns pseudo-random numbers. For the uniform distribution on [0,1], F(x) = x. So the syntax you need is -ksmirnov testY = testY-, and you will see that this hypothesis is (usually) not rejected. If you read the example for a normally distributed variable in the help for -ksmirnov-, perhaps this will become clearer.

    Comment


    • #3
      Thanks Clyde. Can I impose -- I don't follow the help for the ksmirnov. I (think) understand the example for normal, but how does [ksmirnov testY = testY] tell me that I am testing a particular form of distribution? The RHS must specify the cumulative function, but for a uniform distribution the cumulative F(x) is not equal to p(x) so I don't see how that would work: I'm missing something.

      Regarding the distribution of testX: if a uniform distribution is 'rectangular' with equal probability I'm not sure why testX (interger over 1 to 10) is not a uniform (discrete) distribution-- it looks uniform from the histogram: again I seem to be missing something.

      Regards
      Laurence

      Comment


      • #4
        The cumulative densitiy function for a standard continuous uniform distribution F(x) = x. The variable x ranges from 0 to 1 and each value is equaly likely, so we can expect a proportion of .10 to have a value less than .10, a proportion of .20 to have a value less than .20, etc. As a consequence the ksmirnov should be ksmirnov testY = testY.

        As to testX not being a uniform distribution, well yes and no. The key problem is that "uniform distribution" can mean many things, which is why I used the term "standard (ranging between 0 and 1) continuous (not discrete) uniform distribution". The cumulative distribution is ofcourse different, now it is F(x) = x/10, so the corresponding command is ksmirnov testX = testX/10.
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          To close the thread: thanks Maarten (and Clyde) -- 'penny just dropped' why the test is X = X (in a perfectly uniform distribution the cumulative function is linear (upward sloping)).
          Regards
          Laurence

          Comment

          Working...
          X