R/predict.crm.R

predict.crm <- function (object, newdata = NULL, ...) {
  # check inputs
  if (missing(object)) {
    stop("argument 'object' is missing, with no default")
  }
  if (!is(object, "crm")) {
    stop("argument 'object' must be of class 'crm'")
  }

  # predict response values
  if (is.null(newdata)) {
    return(object$fitted.values)
  } else {
    X <- model.matrix(delete.response(object$terms), newdata)
    predicted.values <- as.numeric(X %*% object$coefficients)
    names(predicted.values) <- rownames(newdata)
    return(predicted.values)
  }
}

Try the crmReg package in your browser

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

crmReg documentation built on June 8, 2025, 10:03 a.m.