Is there a way to check if sample obeys the Latin Hypercube Sampling rule?

I was wondering if there is a way to check if a certain sample of a large size obeys the Latin Hypercube Sampling rule. I know that for smaller samples, I can easily visualize the sample points to see if they are stratified according to the Latin Hypercube rule, but was wondering if there would be way to check this for larger sizes of samples.

There are a couple of strategies for you to consider. I'll use R, but you should be able to adapt this to your language. These strategies assume a uniform Latin hypercube on (0,1). If you have already transformed the margins of the hypercube, you might want to transform them back.

# from the lhs package

require(lhs)

checkLatinHypercube <- function(X)
{
if (any(apply(X, 2, min) <= 0))
return(FALSE)
if (any(apply(X, 2, max) >= 1))
return(FALSE)
if (any(is.na(X)))
return(FALSE)
# check that the matrix is a latin hypercube
g <- function(Y)
{
# check that this column contains all the cells
breakpoints <- seq(0, 1, length = length(Y) + 1)
h <- hist(Y, plot = FALSE, breaks = breakpoints)
all(h\$counts == 1)
}
# check all the columns
return(all(apply(X, 2, g)))
}

set.seed(10923)
X <- randomLHS(10, 3)
checkLatinHypercube(X)

# if you are in another language, then you can use these strategies

# check all numbers are between 0 and 1
for (i in 1:3)
{
for (j in 1:10)
{
if (X[j,i] >= 1 | X[j,i] <= 0)
{
stop("error")
}
}
}

# check the sums in integer space
for (i in 1:3)
{
temp <- floor(X[,i] * 10) + 1
if (sum(temp) != 10*(10+1)/2)
{
stop("error")
}
}

# check you have exactly 3 of each bin
temp <- floor(X * 10) + 1
for (i in 1:10)
{
if (length(which(temp == i)) != 3)
{
stop("error")
}
}

• Thank you so much for your reply. I was able to adapt the code to the language I'm using. One question I have is, how would the condition for the sums in integer space be different for a hypercube sample with different margins for each variable? I'm not sure if the column values should add up to the same value. Commented May 11, 2020 at 17:08
• You are right to be concerned if you transformed the margins to different distributions. I definitely based my answer on uniform margins. If you know how you transformed the margins, you could likely transform them back before checking in integer space. You could also use a quantile function on the margins to find the "decile" that the observation calls in, and then transform that to integer space. Commented May 13, 2020 at 3:34
• Thanks a lot for the comment, that was really useful! Commented May 14, 2020 at 15:48
• Thanks again for your help. I was also wondering if you would know a good way to check for the degree by which the sample is stratified according to the LHS rule. I'm not sure if I can implement the above three conditions to individual sample points and count the ones that obey the rule since the above code tests for the entire sample X. Commented May 14, 2020 at 19:49
• I've never seen anything published on "the degree by which a sample is stratified according to the LHS rule," but this is how I might implement that... gist.github.com/bertcarnell/b633ecc2a6e133eeb89a2d77a062e482 Commented May 18, 2020 at 0:21