[R] help on understanding a code

Mike Lawrence Mike.Lawrence at dal.ca
Tue Jun 2 16:53:57 CEST 2009


You haven't provided us enough information. You should also provide
examples where we can access all the called objects; for example,
ttest() is not a built-in function, so we have no idea what it is.
Same goes for dat and y.

On Tue, Jun 2, 2009 at 11:43 AM, Hongyuan Cao <hongyuancao at gmail.com> wrote:
> 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]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

Looking to arrange a meeting? Check my public calendar:
http://tr.im/mikes_public_calendar

~ Certainty is folly... I think. ~




More information about the R-help mailing list