Return a matrix of orthornomal contrasts. Code is based on stanova::contr.bayes and corresponding to description by Rouder et al. (2012)

contr.orthonormal(n, contrasts = TRUE)

Arguments

n

a vector of levels for a factor, or the number of levels

contrasts

logical indicating whether contrasts should be computed

Value

A matrix with n rows and k columns, with k = n - 1 if contrasts = TRUE and k = n if contrasts = FALSE.

References

Rouder JN, Morey RD, Speckman PL, Province JM (2012). “Default Bayes factors for ANOVA designs.” Journal of Mathematical Psychology, 56(5), 356--374. doi:10.1016/j.jmp.2012.08.001 .

Examples

contr.orthonormal(c(1, 2))
#>            [,1]
#> [1,] -0.7071068
#> [2,]  0.7071068
contr.orthonormal(c(1, 2, 3))
#>            [,1]       [,2]
#> [1,]  0.0000000  0.8164966
#> [2,] -0.7071068 -0.4082483
#> [3,]  0.7071068 -0.4082483