Open brentp opened 12 years ago
the permutation code is repeated in many places, could be factored out into a single function
my_perm_method <- function(my_method, y, X, perm=-1, my_stat=NA) { if(perm <= 0){ return NA } x.perm = rep(0, perm) my_stat = ifelse(is.na(my_stat, my_method(y, X), my_stat)) for(i in 1:perm) { perm.sample = sample(1:length(y)) x.perm[i] = my_method(y[perm.sample], X) } # p-value perm.pval = sum(x.perm > my_stat) / perm return(perm.pval) }
the permutation code is repeated in many places, could be factored out into a single function