LHC <- function(theMatrix, npoints) { ######################################################################## #Function: LHC(theMatrix,theNames) # #Parameters: theMatrix: an n by 2 matrix. Each row is the lower # and upper bound of the range of the variable. # colNames: names of the variables # npoints: number of points each factor is chopped in (assuming uniform sampling) ######################################################################## #Description: Function partitions the range of each variable into # evenly spaced intervals. The number of intervals is # specified. The function then randomly permutes # the order of the intervals. The value returned by the # function is matrix, where each row is a design point. f <- function(m, n) { lb <- m[1] #lower bound ub <- m[2] #upper bound i <- (m[2] - m[1])/ (n-1) # interval step size return(seq(m[1] , m[2] , i)) } hyper.design.temp <- apply(theMatrix, 1, f, npoints); # hyper.design.temp hyper.design <- apply(hyper.design.temp, 2, sample); # hyper.design return(hyper.design) } #-----------------test material temp <- matrix(c(10,0,5,20,2,10), ncol=2); temp npoints <- 21 out.design <- LHC(temp, npoints) out.design