#' Normal Scores #' #' This function applies a quantile-quantile transformation to #' the data, resulting in a distribution that is approximately normal #' but has the same ranks as the original data #' #' @param y A vector. #' @param ties.method The option \code{ties.method} in the \code{rank} function. #' #' @return A vector of the same length as \code{y}. #' #' @author Peter Hoff #' #' @export #' #' @examples #' y<-rexp(100) #' z<-zscores(y) #' par(mfrow=c(1,3)) #' hist(y) #' hist(z) #' plot(y,z) zscores<-function(y,ties.method="average") { z<-qnorm(rank(y,na.last="keep",ties.method=ties.method)/(sum(!is.na(y))+1) ) names(z)<-names(y) m<-dim(y) if(length(m)==2){ z<-matrix(z,nrow=m[1],ncol=m[2]) ; dimnames(z)<-dimnames(y) } if(length(m)>=3){ z<-array(z,dim=m) ; dimnames(z)<-dimnames(y) } z }