R/utils_internal.R

Defines functions create_mm

Documented in create_mm

#' Create Model Matrix for Predictions
#' 
#' @param m model
#' @param newdata dataset at which predictions should be made
#' @return model.matrix
create_mm = function(m, newdata) {
    
    # create model matrix
    x_vars = delete.response(m$terms)
    mf = model.frame(x_vars,
                    newdata,
                    xlev = m$xlevels)
    
    if (!is.null(cl <- attr(x_vars, "dataClasses")))
        .checkMFClasses(cl, m)
    
    X = model.matrix(x_vars,
                     mf,
                     contrasts.arg = m$contrasts)
    
    return(X)
}
baruuum/btoolbox documentation built on Aug. 17, 2020, 1:29 a.m.