R/MGRtest.R

Defines functions MGRtest

MGRtest <- function(y, trt, n, dferror, mserror, alpha, dms.range)
{
    Ybar <- tapply(y, trt, mean)
    Ybar <- sort(Ybar)
  posmax <- as.integer(which.max(Ybar[2:n] - Ybar[1:(n - 1)]))
    qobs <- Ybar[n] - Ybar[1]
  groups <- rep(0, times = n)
      ng <- 1
  if (qobs <= dms.range) {
    groups[1:n] <- 1
  } else {
    groups[1:posmax] <- 1
    groups[(posmax+1):n] <- 2
    ng <- ng + 1
  }
  if ((any(groups!=1))) {
    continua1 = TRUE
  } else {
    continua1 = FALSE
  }
  if (continua1 == TRUE) {
    posI <- 1
     fim <- FALSE
    repeat {
      ini  <- groups[posI]
      posF <- max(which(groups == ini))
      if (((posF - posI) > 0) & (ini > 0)) {
        posmax <- as.integer(which.max(Ybar[(posI + 1):posF]
                                       - Ybar[posI:(posF - 1)]))
        qobs <- Ybar[posF] - Ybar[posI]
        aux <- groups[posI]
        if  (qobs <= dms.range) {
          groups[posI:posF] <- - aux
          posI <- posF + 1
          if (posI > n) {
            posI <- 1
          }
        } else {
          groups[(posI+posmax):posF] <- ng + 1
          ng <- ng + 1
          posI <- 1
        }
      } else posI <- posF + 1
      if (posI >= n) fim <- TRUE
      if (fim == TRUE) break
    }
    groups <- abs(groups)
  }
  result <- cbind(Ybar, groups)
  return(group.test2(result))
}

Try the MCPtests package in your browser

Any scripts or data that you put into this service are public.

MCPtests documentation built on Dec. 17, 2020, 5:09 p.m.