R/quad.R

Defines functions quad

Documented in quad

#'@title quadratic
#'
#'@description quadratic
#'
#'@param formula The formula to be expanded
#'@keywords internal
#'@return Returns quadratic model from formula
quad = function(formula) {
  variables = all.vars(formula)
  quadratic = paste(variables, collapse = " + ")
  quadratic = paste("~", quadratic, sep = "")
  for (i in 1:length(variables)) {
    for (j in i:length(variables)) {
      if (i == j) {
        quadratic = paste(quadratic, " + I(", variables[i], "^2)", sep = "", collapse = "")
      } else {
        quadratic = paste(quadratic, " + ", variables[i], ":", variables[j], sep = "", collapse = "")
      }
    }
  }
  return(as.formula(quadratic))
}

Try the skpr package in your browser

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

skpr documentation built on July 9, 2023, 7:23 p.m.