[R] loops

Heberto Ghezzo Heberto at meakins.lan.mcgill.ca
Tue Apr 25 20:20:33 CEST 2000


Hi R friends,
I havent asked a silly question in a long time so here it is:
Reading the last issue of Stat Can J. there is an article in a single 
degree of freedom test for non aditivity of interactions in anova 
tables with 1 obs per cell. The authors claim it is more powerfull than 
Tukey but for the case of multiplicative interaction, which is the 
alternative studied by Tukey. I tried to program it, and it works since 
the tables are 5 by 5 or 5 by 8 etc.
Just for the sake of neatness how can I reprogram the core of the 
program which is:
s <- NULL
k <- 0
for ( j in 1:(nc-1)) {
  for (jp in (j+1):nc ) {
    k <- k+1
    s[k] <- 0
    for (i in 1:(nr-1)) {
      for(ip in (i+1):nr) {
        a <- xr[i,j]+xr[ip,jp]-xr[i,jp]-xr[ip,j]
        s[k] <- s[k] + a*a
      }
    }
  }
}
cra <- max(s)

where nc=number of columns, nr number of rows and the xr's are 
the centered ranks.
the statistic being cra, there is a similar version where mean is 
replace by median in a previous step..
There must be a way in R to replace the 4 for loops i<i' and j<j' 
Thanks for your help.
I suppose the answer is already in the new V&R?
.
R. Heberto Ghezzo  Ph.D.
Meakins-Christie Labs
McGill University
Montreal - Canada
heberto at meakins.lan.mcgill.ca
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list