Computes a Hadamard matrix of dimension \((p+1)\times 2^k\), where p is a prime, and p+1 is a multiple of 4, using the Paley construction. Used by hadamard.

paley(n, nmax = 2 * n, prime=NULL, check=!is.null(prime))

is.hadamard(H, style=c("0/1","+-"), full.orthogonal.balance=TRUE)

Arguments

n

Minimum size for matrix

nmax

Maximum size for matrix. Ignored if prime is specified.

prime

Optional. A prime at least as large as n, such that prime+1 is divisible by 4.

check

Check that the resulting matrix is of Hadamard type

H

Matrix

style

"0/1" for a matrix of 0s and 1s, "+-" for a matrix of \(\pm 1\).

full.orthogonal.balance

Require full orthogonal balance?

Value

For paley, a matrix of zeros and ones, or NULL if no matrix smaller than

nmax can be found.

For is.hadamard, TRUE if H is a Hadamard matrix.

Details

The Paley construction gives a Hadamard matrix of order p+1 if p is prime and p+1 is a multiple of 4. This is then expanded to order \((p+1)\times 2^k\) using the Sylvester construction.

paley knows primes up to 7919. The user can specify a prime with the prime argument, in which case a matrix of order \(p+1\) is constructed.

If check=TRUE the code uses is.hadamard to check that the resulting matrix really is of Hadamard type, in the same way as in the example below. As this test takes \(n^3\) time it is preferable to just be sure that prime really is prime.

A Hadamard matrix including a row of 1s gives BRR designs where the average of the replicates for a linear statistic is exactly the full sample estimate. This property is called full orthogonal balance.

References

Cameron PJ (2005) Hadamard Matrices. In: The Encyclopedia of Design Theory http://www.maths.qmul.ac.uk/~lsoicher/designtheory.org/library/encyc/

See also

Examples


M<-paley(11)

is.hadamard(M)
#> [1] TRUE
## internals of is.hadamard(M)
H<-2*M-1
## HH^T is diagonal for any Hadamard matrix
H%*%t(H)
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
#>  [1,]   12    0    0    0    0    0    0    0    0     0     0     0
#>  [2,]    0   12    0    0    0    0    0    0    0     0     0     0
#>  [3,]    0    0   12    0    0    0    0    0    0     0     0     0
#>  [4,]    0    0    0   12    0    0    0    0    0     0     0     0
#>  [5,]    0    0    0    0   12    0    0    0    0     0     0     0
#>  [6,]    0    0    0    0    0   12    0    0    0     0     0     0
#>  [7,]    0    0    0    0    0    0   12    0    0     0     0     0
#>  [8,]    0    0    0    0    0    0    0   12    0     0     0     0
#>  [9,]    0    0    0    0    0    0    0    0   12     0     0     0
#> [10,]    0    0    0    0    0    0    0    0    0    12     0     0
#> [11,]    0    0    0    0    0    0    0    0    0     0    12     0
#> [12,]    0    0    0    0    0    0    0    0    0     0     0    12