Parametric Bootstrapped Kolmogorov-Smirnov GoF test



Hi,

I want to perform a One-Sample parametric bootstrapped Kolmogorov-
Smirnov GoF test. Just after read some tutorial found on internet,
I've decided to do this:

1. Given sample X_i, i=1,...,n, estimate parameters theta (theta.hat)
for a certain theoretical distribution F(x; theta) obtaining F(x;
theta_hat)
2. Calculate K-S statistic from sample X and fi (say ks.stat) (one-
sample K-S test)
3. Execute B iterations (B=999); for each iteration i:
3.1 sample from F(x; theta_hat) a sample Y_j, j=1,...n
3.2 calculate K-S statistic from samples X and Y (say ks.bstats[i] )
(two-sample K-S test)
4 Calculate the p-value for the test: (1+count( ks.bstats >=
ks.stat ))/(B+1)
5 return( ks.stat, p-value )

but it seems it doesn't work.

Here below is the related R code and an example of bad behaviour:

---[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-1) )
{
# 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 <- (1+ks.pval) / (B+1);

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?!?

Any help is very appreciated.

Thank you very much!

[Note for R-users: package "Matching" provides "ks.boot" which is a 2-
sample non-parametric bootstrapped K-S version; not for me.]

Best Regards,

-- Marco

.



Relevant Pages