Dear R user,

I am trying to understand this following code. Basically it's using a
permutation method to calculate p value. But I would like to know exactly
how the permutation works.

#calculates null statistics
tt0 <- 0
set.seed(123)
B <- 100
for(i in 1:B) {
v <- sample(y)
tt0 <- c(tt0,ttest(dat,v)$tt)
}
tt0 <- tt0[-1]
#form p-values
att <- abs(tt)
att0 <- abs(tt0)
v <- c(rep(T,m),rep(F,m*B))
v <- v[rev(order(c(att,att0)))]
u <- 1:length(v)
w <- 1:m
p <- (u[v==TRUE]-w)/(B*m)
p <- p[rank(-att)]

For some reason, I couldn't get any results for p. Maybe R encoded T and F
to corresponding numerical ones.

Any idea?

Thanks,
Hongyuan

	[[alternative HTML version deleted]]


