A contrast function based on regular factorials for number of levels a prime or prime power

contr.Power(n, s = 2, contrasts = TRUE)

Arguments

n

integer or vector; either an integer number of levels of the factor for which contrasts are created, which must be a a power of s; or a factor whose number of levels is a power of s; or a vector of levels whose number of elements is a power of s.

s

integer; prime or prime power

contrasts

logical; must be TRUE

Value

contr.Power yields a matrix of contrasts. It can be used in function model.matrix or anywhere where factors with the number of levels a power of $s$ are used with contrasts. The exponent for s

is determined from the number of levels.

Details

The function is a generalization (with slowest first instead of fastest first) of function contr.FrF2 from package DoE.base. It is in this package because it needs Galois field functionality from package lhs for non-prime s. Its purpose is (was) the calculation of the stratification (or space-filling) pattern by Tian and Xu (2022), see also Groemping (2022). The package now calculates the pattern with function contr.TianXu.

References

Groemping (2022) Tian and Xu (2022)

Examples

## the same n can yield different contrasts for different s
contr.Power(16, 2)
#>     1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
#> 1  -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
#> 2  -1 -1 -1 -1 -1 -1 -1  1  1  1  1  1  1  1  1
#> 3  -1 -1 -1  1  1  1  1 -1 -1 -1 -1  1  1  1  1
#> 4  -1 -1 -1  1  1  1  1  1  1  1  1 -1 -1 -1 -1
#> 5  -1  1  1 -1 -1  1  1 -1 -1  1  1 -1 -1  1  1
#> 6  -1  1  1 -1 -1  1  1  1  1 -1 -1  1  1 -1 -1
#> 7  -1  1  1  1  1 -1 -1 -1 -1  1  1  1  1 -1 -1
#> 8  -1  1  1  1  1 -1 -1  1  1 -1 -1 -1 -1  1  1
#> 9   1 -1  1 -1  1 -1  1 -1  1 -1  1 -1  1 -1  1
#> 10  1 -1  1 -1  1 -1  1  1 -1  1 -1  1 -1  1 -1
#> 11  1 -1  1  1 -1  1 -1 -1  1 -1  1  1 -1  1 -1
#> 12  1 -1  1  1 -1  1 -1  1 -1  1 -1 -1  1 -1  1
#> 13  1  1 -1 -1  1  1 -1 -1  1  1 -1 -1  1  1 -1
#> 14  1  1 -1 -1  1  1 -1  1 -1 -1  1  1 -1 -1  1
#> 15  1  1 -1  1 -1 -1  1 -1  1  1 -1  1 -1 -1  1
#> 16  1  1 -1  1 -1 -1  1  1 -1 -1  1 -1  1  1 -1
contr.Power(16, 4)
#>             1  2          3          4  5          6          7  8          9
#> 1  -1.3416408  1 -0.4472136 -1.3416408  1 -0.4472136 -1.3416408  1 -0.4472136
#> 2  -1.3416408  1 -0.4472136 -0.4472136 -1  1.3416408 -0.4472136 -1  1.3416408
#> 3  -1.3416408  1 -0.4472136  0.4472136 -1 -1.3416408  0.4472136 -1 -1.3416408
#> 4  -1.3416408  1 -0.4472136  1.3416408  1  0.4472136  1.3416408  1  0.4472136
#> 5  -0.4472136 -1  1.3416408 -1.3416408  1 -0.4472136 -0.4472136 -1  1.3416408
#> 6  -0.4472136 -1  1.3416408 -0.4472136 -1  1.3416408 -1.3416408  1 -0.4472136
#> 7  -0.4472136 -1  1.3416408  0.4472136 -1 -1.3416408  1.3416408  1  0.4472136
#> 8  -0.4472136 -1  1.3416408  1.3416408  1  0.4472136  0.4472136 -1 -1.3416408
#> 9   0.4472136 -1 -1.3416408 -1.3416408  1 -0.4472136  0.4472136 -1 -1.3416408
#> 10  0.4472136 -1 -1.3416408 -0.4472136 -1  1.3416408  1.3416408  1  0.4472136
#> 11  0.4472136 -1 -1.3416408  0.4472136 -1 -1.3416408 -1.3416408  1 -0.4472136
#> 12  0.4472136 -1 -1.3416408  1.3416408  1  0.4472136 -0.4472136 -1  1.3416408
#> 13  1.3416408  1  0.4472136 -1.3416408  1 -0.4472136  1.3416408  1  0.4472136
#> 14  1.3416408  1  0.4472136 -0.4472136 -1  1.3416408  0.4472136 -1 -1.3416408
#> 15  1.3416408  1  0.4472136  0.4472136 -1 -1.3416408 -0.4472136 -1  1.3416408
#> 16  1.3416408  1  0.4472136  1.3416408  1  0.4472136 -1.3416408  1 -0.4472136
#>            10 11         12         13 14         15
#> 1  -1.3416408  1 -0.4472136 -1.3416408  1 -0.4472136
#> 2   0.4472136 -1 -1.3416408  1.3416408  1  0.4472136
#> 3   1.3416408  1  0.4472136 -0.4472136 -1  1.3416408
#> 4  -0.4472136 -1  1.3416408  0.4472136 -1 -1.3416408
#> 5  -0.4472136 -1  1.3416408 -0.4472136 -1  1.3416408
#> 6   1.3416408  1  0.4472136  0.4472136 -1 -1.3416408
#> 7   0.4472136 -1 -1.3416408 -1.3416408  1 -0.4472136
#> 8  -1.3416408  1 -0.4472136  1.3416408  1  0.4472136
#> 9   0.4472136 -1 -1.3416408  0.4472136 -1 -1.3416408
#> 10 -1.3416408  1 -0.4472136 -0.4472136 -1  1.3416408
#> 11 -0.4472136 -1  1.3416408  1.3416408  1  0.4472136
#> 12  1.3416408  1  0.4472136 -1.3416408  1 -0.4472136
#> 13  1.3416408  1  0.4472136  1.3416408  1  0.4472136
#> 14 -0.4472136 -1  1.3416408 -1.3416408  1 -0.4472136
#> 15 -1.3416408  1 -0.4472136  0.4472136 -1 -1.3416408
#> 16  0.4472136 -1 -1.3416408 -0.4472136 -1  1.3416408