[R] Parametric bootstrapped Kolmogorov-Smirnov GoF: what's wrong

From: Shiazy Fuzzy <shiazy_at_gmail.com>
Date: Mon, 28 May 2007 00:07:41 +0200


Dear R-users,

I want to perform a One-Sample parametric bootstrapped Kolmogorov-Smirnov GoF test (note package "Matching" provides "ks.boot" which is a 2-sample non-parametric bootstrapped K-S version). So I wrote this code:

---[R Code] ---

ks.test.bootnp <- function( x, dist, ..., alternative=c("two.sided", "less", "greater"), B = 1000 )
{

        n.x <- length(x);

        cdf <- paste( "p", dist, sep="" );
        rvg <- paste( "r", dist, sep="" ) ;
        rvg <- get( rvg, mode = "function" );

        ks <- ks.test( x, cdf, ..., alternative = alternative ); # KS stat
from sample
        # bootstrapping K-S ...
        ks.pval <- 0;
        for ( i in 1:B )
        {
                # Samples from the theoretical distribution
                y <- rvg( n.x, ... );

                # Performs a K-S test
                ks.boot <- ks.test( x, y, alternative = alternative );

                # Updates p-value
                if ( ks.boot$statistic >= ks$statistic )
                {
                        ks.pval <- ks.pval + 1;
                }
        }
        ks.pval <- ks.pval / B;

        return( list( statistic = ks$statistic, p.value = ks$p.value,
p.value.boot = ks.pval ) );
}
---[/R Code] ---

If you try to run:

---[R Code] ---

set.seed(1);
x <- rweibull( 200, 1.3, 8.7 );
ks.test.bootnp(x,"norm",100,10,B=1000);
---[/R Code] ---

you obtain something like this:

---[R Code] ---

$statistic
D
1

$p.value
[1] 0

$p.value.boot
[1] 1
---[/R Code] ---

very bad!!!!

So what's wrong?!?

Thank you very much!

Best Regards,

        [[alternative HTML version deleted]]



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 27 May 2007 - 22:15:46 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 May 2007 - 15:01:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.