R/quality.R

Defines functions zprime

Documented in zprime

zprime = function(a, b, method=c('mahalanobis', 'robust', 'fixsd', 'original')) {
  method = match.arg(method)
  
  if (method=='mahalanobis') {
    if (is.null(dim(a))) a = matrix(a, ncol=1)
    if (is.null(dim(b))) b = matrix(b, ncol=1)
    mua = apply(a, 2, mean)
    mub = apply(b, 2, mean)
    dm = try(mahalanobis(mua, mub, cov(a) + cov(b)))
    if (class(dm)=='try-error') NA
    else 1-3/sqrt(dm)
  }
  else {
    if (method=='robust') 1-3*(mad(a)+mad(b))/abs(median(a)-median(b))
    else if (method=='fixsd') 1-3*sqrt(var(a)+var(b))/abs(mean(a)-mean(b))
    else 1-3*(sd(a)+sd(b))/abs(mean(a)-mean(b))
  }
}

Try the imageHTS package in your browser

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

imageHTS documentation built on Nov. 8, 2020, 8:29 p.m.