R/predict.CCM.R

Defines functions predict.CCM

Documented in predict.CCM

predict.CCM <-
function(object, y, func = mean, ret.scores = FALSE, ...) {
  keep = !is.na(y)
  y = y[keep]
  object = object[,keep]
  preds = rep(NA,nrow(object)) 
  scores = NULL
  for (i in 1:nrow(object)) {
    s = split(object[i,], y)
    l = (lapply(s,func, na.rm=TRUE, ...))
    w = which.max(l)
    if (ret.scores) scores = rbind(scores, unlist(l))
    preds[i] = names(w)
  }
  if (ret.scores) {
        scores = t(scores)
	return(scores)
  }
  if (is.numeric(y)) preds = as.numeric(preds)
  if (is.factor(y)) preds = as.factor(preds)

  return(preds)
}

Try the CCM package in your browser

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

CCM documentation built on April 12, 2018, 5:03 p.m.