News

New paper!

Monday, December 3, 2018

R: Steel-Dwass



Steel-Dwass in R language, general explanations for multiple comparison etc.
Steel-Dwass (群馬大学・青木先生のコード) The code below is from this link.
多重比較法の要約(滋賀大学・小山先生)
多重比較法などの説明(東北大学・池田先生)
Steel.Dwass <- function(data,   # data vector
   group)      # vector of group indeces
{
 OK <- complete.cases(data, group)   # data shouldn't include missing values
 data <- data[OK]
 group <- group[OK]
 n.i <- table(group)      # the number of data in each group
 ng <- length(n.i)      # the number of groups
 t <- combn(ng, 2, function(ij) {
  i <- ij[1]
  j <- ij[2]
  r <- rank(c(data[group == i], data[group == j])) # rank all data in group i and j
  R <- sum(r[1:n.i[i]])     # test statistic
  N <- n.i[i]+n.i[j]     # the total number of data in group i and j
  E <- n.i[i]*(N+1)/2     # expectation of the test statistic
  V <- n.i[i]*n.i[j]/(N*(N-1))*(sum(r^2)-N*(N+1)^2/4) # variance of the test statistic
  return(abs(R-E)/sqrt(V))    # t value
 })
 p <- ptukey(t*sqrt(2), ng, Inf, lower.tail=FALSE)  # p value
 result <- cbind(t, p)
 rownames(result) <- combn(ng, 2, paste, collapse=":")
 return(result)
}