R/xBalance.makepooledsd.R

Defines functions xBalance.makepooledsd.single xBalance.makepooledsd

Documented in xBalance.makepooledsd

##' xBalance helper function
##'
##' Make pooled SD
##' @param zz Treatment
##' @param mm mm
##' @param pre.n pre.n
##' @return pooled SD
##' @keywords internal
xBalance.makepooledsd <- function(zz,mm,pre.n) {
  if (any(zz>0)) {
    s2.t <- apply(mm[(zz>0),,drop=FALSE],2,var,na.rm=TRUE)
  } else {
    s2.t <- 0
  }

  ##Variance of the covariates among the controls (zz==0)
  if (any(zz<=0)) {
    s2.c <- apply(as.matrix(mm[(zz<=0),,drop=FALSE]), 2, var,na.rm=TRUE)
  } else {
    s2.c <- 0
  }

  ##Pooled standard deviation.
  sqrt( (max(sum(zz>0)-1,0)*s2.t + max(sum(zz<=0)-1,0)*s2.c)/(pre.n-2) )
}

xBalance.makepooledsd.single <- function(zz,v,pre.n) {
  if (any(zz>0)) {
    s2.t <- var(v[zz > 0], na.rm = TRUE)
  } else {
    s2.t <- 0
  }

  ##Variance of the covariates among the controls (zz==0)
  if (any(zz<=0)) {
    s2.c <- var(v[zz <= 0], na.rm = TRUE)
  } else {
    s2.c <- 0
  }

  ##Pooled standard deviation.
  sqrt( (max(sum(zz>0)-1,0)*s2.t + max(sum(zz<=0)-1,0)*s2.c)/(pre.n-2) )
}

Try the RItools package in your browser

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

RItools documentation built on March 31, 2023, 7:17 p.m.