R/getStandardizedCovariates.R

Defines functions getStandardizedCovariates

getStandardizedCovariates = function(formula, data) {
  
  matchCall = getFormulaInfo(formula, data)$matchCall
  matchCallAttributes = getFormulaInfo(formula, data)$matchCallAttributes
  
  y = model.response(matchCall, "numeric")
  X = model.matrix(matchCallAttributes, matchCall)
  
  standardizedX = X
  if(any(colnames(X) == "(Intercept)")) {
    standardizedX[, -which(colnames(standardizedX) == "(Intercept)")] = apply(standardizedX[, -which(colnames(standardizedX) == "(Intercept)"), drop = F] , 2, function(x) (x - mean(x)) / sd(x))
  } 
  else {
    standardizedX = apply(standardizedX , 2, function(x) (x - mean(x)) / sd(x))
  }
 
  return(list(y = y, X = X, standardizedX = standardizedX))
  
}

Try the netcmc package in your browser

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

netcmc documentation built on Nov. 10, 2022, 5:11 p.m.