R/ASCORE.Ord.R

Defines functions ASCORE.Ord

Documented in ASCORE.Ord

ASCORE.Ord <-
function(y, X, perm=100)
{   
  ## checking arguments
  Xy_perm = my_check(y, X, perm)
  y = Xy_perm$y
  X = Xy_perm$X
  perm = Xy_perm$perm
    
  ## get U and V
  getuv = my_getUV(y, X)
  U = getuv$U
  V = getuv$V
  ## run score method
  stat.sco = my_ascore_method(U, V)
  score.stat = stat.sco[2]
  
  ## permutations
  perm.pval = NA
  if (perm > 0)
  {
    x.perm = rep(0, perm)
    ymean = mean(y)
    for (i in 1:perm)
    {
      perm.sample = sample(1:length(y))
      # center phenotype y
      y.perm = y[perm.sample] - ymean
      # get score vector
      U.perm = colSums(y.perm * X, na.rm=TRUE)
      perm.sco = my_ascore_method(U.perm, V)
      x.perm[i] = perm.sco[2]
    }
    # p-value 
    perm.pval = sum(x.perm > score.stat) / perm	
  }
  
  ## results
  name = "ASCORE.Ord: Adaptive Score Test (Ordered)"
  arg.spec = c(sum(y), length(y)-sum(y), ncol(X), perm)
  names(arg.spec) = c("cases", "controls", "variants", "n.perms")	
  res = list(ascore.stat = score.stat, 
             perm.pval = perm.pval, 
             args = arg.spec, 
             name = name)
  class(res) = "assoctest"
  return(res)
}

Try the AssotesteR package in your browser

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

AssotesteR documentation built on May 2, 2019, 3:55 a.m.