Thursday, September 15, 2016

Bag of Little Bootstrap for QR

In the never ending quest to speed up inference for large quantile regression problems,
I have started to look into the Kleiner, et al Bag of Little Bootstraps proposal.  After a
serious confusion on my part was corrected with the help of Xiaofeng Shao,  I've come
to the following code fragment added to summary.rq in my quantreg package:


 else if (se == "BLB"){ # Bag of Little Bootstraps
        n <- length(y)
        b <- ceiling(n^gamma)
        S <- n %/% b
        U <- matrix(sample(1:n, b * S), b, S)
        Z <- matrix(0, NCOL(x), S)
        for(i in 1:S){
            u <- U[,i]
           B <- matrix(0, NCOL(x), R)
           for(j in 1:R){
w <- c(rmultinom(1, n, rep(1/b, b)))
B[,j] <- rq.wfit(x[u,], y[u], tau, weights = w, method = "fnb")$coef
           }
            Z[,i] <- sqrt(diag(cov(t(B))))
        }
        serr <- apply(Z, 1, mean)
    }

In the eventual implementation I managed to embed the inner loop into fortran
which helps to speed things up a bit, although of course it would be eventually
helpful to allow this to be distributed across cluster nodes.
I should also mention that the implicit assumption here that BLB works for
moments, appears to be (presently) beyond the scope of the current theory,  

No comments:

Post a Comment