Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

contr.orthonorm

Orthonormal Contrast Matrices for Bayesian Estimation


Description

Returns a design or model matrix of orthonormal contrasts such that the marginal prior on all effects is identical. Implementation from Singmann & Gronau's bfrms, following the description in Rouder, Morey, Speckman, & Province (2012, p. 363).

Though using this factor coding scheme might obscure the interpretation of parameters, it is essential for correct estimation of Bayes factors for contrasts and order restrictions of multi-level factors (where 'k>2'). See info on specifying correct priors for factors with more than 2 levels in the Bayes factors vignette.

Usage

contr.orthonorm(n, contrasts = TRUE, sparse = FALSE)

Arguments

n

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

contrasts

a logical indicating whether contrasts should be computed.

sparse

logical indicating if the result should be sparse (of class dgCMatrix), using package Matrix.

Details

When 'contrasts = FALSE', the returned contrasts are equivalent to 'contr.treatment(, contrasts = FALSE)', as suggested by McElreath (also known as one-hot encoding).

Value

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

References

- McElreath, R. (2020). Statistical rethinking: A Bayesian course with examples in R and Stan. CRC press.

- Rouder, J. N., Morey, R. D., Speckman, P. L., & Province, J. M. (2012). Default Bayes factors for ANOVA designs. *Journal of Mathematical Psychology*, 56(5), 356-374. https://doi.org/10.1016/j.jmp.2012.08.001

Examples

contr.orthonorm(2) # Q_2 in Rouder et al. (2012, p. 363)

contr.orthonorm(5) # equivalent to Q_5 in Rouder et al. (2012, p. 363)

## check decomposition
Q3 <- contr.orthonorm(3)
Q3 %*% t(Q3) ## 2/3 on diagonal and -1/3 on off-diagonal elements

bayestestR

Understand and Describe Bayesian Models and Posterior Distributions

v0.10.0
GPL-3
Authors
Dominique Makowski [aut, cre] (<https://orcid.org/0000-0001-5375-9967>, @Dom_Makowski), Daniel Lüdecke [aut] (<https://orcid.org/0000-0002-8895-3206>, @strengejacke), Mattan S. Ben-Shachar [aut] (<https://orcid.org/0000-0002-4287-4801>, @mattansb), Indrajeet Patil [aut] (<https://orcid.org/0000-0003-1995-6531>, @patilindrajeets), Michael D. Wilson [aut] (<https://orcid.org/0000-0003-4143-7308>), Paul-Christian Bürkner [rev], Tristan Mahr [rev] (<https://orcid.org/0000-0002-8890-5116>), Henrik Singmann [ctb] (<https://orcid.org/0000-0002-4842-3657>), Quentin F. Gronau [ctb] (<https://orcid.org/0000-0001-5510-6943>), Sam Crawley [ctb] (<https://orcid.org/0000-0002-7847-0411>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.