Skip to content
Snippets Groups Projects
DOEGen.R 1.49 KiB
##########################################################################################
##################       Function to create new set of DOE     ##########################
##########################################################################################

newDOE <- function(df){
  # Create a list of list of percentages to use and output a set of design points for the model
  
  set.seed(1234)    # sent seed for the NOLH creation
  blank <- nolhDesign(nrow(df))
  # Code found at
  # https://rdrr.io/cran/DiceDesign/man/nolhDesign.html
  
  # Create a data frame of ranges for each factor
  ammo <- data.frame(matrix(ncol = blank$n, nrow = nrow(df)))
  for (i in 1:nrow(df)){
    ammo[i,] <- df$max[i] - df$min[i]
  }
  
  # transpose NOLH percentages for matrix math operations
  blank2 <- as.data.frame(t(blank$design))
  
  # create a data frame of ranges * NOLH percentages values to get value to add to min of each range of each factor 
  add2min <- as.data.frame(ammo * blank2)
  
  # create a data frame of all the min value ranges for each factor
  ammoMin <- data.frame(matrix(ncol = blank$n, nrow = nrow(df)))
  for (i in 1:nrow(df)){
    ammoMin[i,] <- df$min[i]
  }
  
  # create the DOE
  ammoDOE <- as.data.frame(as.matrix(ammoMin) + as.matrix(add2min))
  
  # Change the Row names of the DOEs
  designPoints <- NULL
  for (i in  1:blank$n){
    designPoints[i] <- paste("DP",i, sep = " ")  
  }
  colnames(ammoDOE) <- designPoints
  row.names(ammoDOE) <- df$UnitId
  
  return(ammoDOE)
}