R/transformations.R

Defines functions donothing msqrt mlog reciproce mprobit mlogit transformation

Documented in donothing mlog mlogit mprobit msqrt reciproce transformation

#
# transformations.r
#
# Copyright (c) 2010-2012 GBIC: Danny Arends, Konrad Zych and Ritsert C. Jansen
# last modified Oct, 2012
# first written Oct, 2012
# Contains: transform, donothing, msqrt,mlog, reciproce, mprobit, mlogit
#

donothing <- function(x, ...){ invisible(return(x)) }
msqrt     <- function(x, ...){ invisible(return(sqrt(x))) }
mlog      <- function(x, ...){ invisible(return(log(x, ...))) }
reciproce <- function(x, ...){ invisible(return(1/x)) }
mprobit   <- function(x, ...){ invisible(return(probit(x, ...))) }
mlogit    <- function(x, ...){ invisible(return(logit(x, ...))) }

transformation <- function(x, transformations=c("nothing","log","sqrt","reciprocal","probit","logit"), ... , verbose=TRUE){
  optionsAvailable <- c("nothing","log","sqrt","reciprocal","probit","logit")
  chosen  <- pmatch(transformations, optionsAvailable)
  methodsChosen <- c(donothing, mlog, msqrt, reciproce, mprobit, mlogit)

  res <- vector("list",length(methodsChosen))
  idx <- 1
  for(n in chosen){
    if(verbose)cat("Applying",n,"a",optionsAvailable[n],"transformation to the data\n")
    res[[idx]] <- apply(x,1,function(t){
      (methodsChosen[n][[1]])(t, ...)
    })
  idx <- idx+1
  }
  res
}

Try the pheno2geno package in your browser

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

pheno2geno documentation built on May 2, 2019, 6:35 a.m.