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

Shiazy Fuzzy shiazy at gmail.com
Mon May 28 16:28:03 CEST 2007


(... sorry! the first post was in HTML format ...)

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,

-- Marco



More information about the R-help mailing list