orth_polynomial_code function

Orthogonal Polynomial code

Orthogonal Polynomial code

Wrapper around stats::contr.poly(). You can also use polynomial_code()

as an alias.

orth_polynomial_code(n) polynomial_code(n)

Arguments

  • n: Integer umber of factor levels to compute contrasts for.

Returns

A contrast matrix with dimensions n rows and (n-1) columns.

Details

For n levels of factors where k in 1:n, generate a matrix with n-1 comparisons where each comparison looks for a polynomial trend of degree k where each polynomial is independent of the others.

Examples

mydf <- data.frame( grp = rep(c("a", "b", "c", "d"), each = 2000), val = c( rnorm(200, 2, 1), rnorm(200, 5, 1), rnorm(200, 7.5, 1), rnorm(200, 15, 1) ) ) |> set_contrasts(grp ~ polynomial_code) stats::lm(val ~ grp, data = mydf)
  • Maintainer: Thomas Sostarics
  • License: MIT + file LICENSE
  • Last published: 2024-10-01