I was able to find that when setting up a randomly ordered vector of 0s and 1s, the script was using length(pertPair) instead of size(pertPair,2). This returns the length of pertPair (2 when a matrix, indicating 2 pairs. Also 2 when a vector containing just 1 pair, but the vector's length is 2) and causes an index out of bounds error. Size of the 2nd dimension should always return the correct number of pairs.
I was able to find that when setting up a randomly ordered vector of 0s and 1s, the script was using length(pertPair) instead of size(pertPair,2). This returns the length of pertPair (2 when a matrix, indicating 2 pairs. Also 2 when a vector containing just 1 pair, but the vector's length is 2) and causes an index out of bounds error. Size of the 2nd dimension should always return the correct number of pairs.