R/Fx_cube.R

Defines functions Fx_cube

Documented in Fx_cube

Fx_cube <- function(formula, lower=NULL, upper=NULL, n.levels=NULL, echo=TRUE) {
  # Generate Fx for a linear factor model (on a cuboid grid)
 
  cl <- match.call()
  verify(cl, formula = formula, lower = lower, upper = upper,
         n.levels = n.levels, echo = echo)
 
  av <- all.vars(formula); d <- length(av)
  if (is.null(lower)) lower <- rep(-1, d)
  if (is.null(upper)) upper <- rep(1, d)
  if (is.null(n.levels)) n.levels <- rep(2, d)

  lst <- labs <- c()
  for (i in 1:d) {
    lst <- c(lst, list(seq(lower[i], upper[i], length = n.levels[i])))
    labs <- c(labs,paste("x", as.character(i), sep = ""))
  }
  data <- expand.grid(lst)
  names(data) <- labs
  mf <- model.frame(formula, data)
  Fx <- as.data.frame(model.matrix(attr(mf, "terms"), mf))
  
  return(as.matrix(Fx))
}

Try the OptimalDesign package in your browser

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

OptimalDesign documentation built on March 26, 2020, 9:35 p.m.