Hi @bobby, I'm not entirely sure what you're after, but the below might be helpful.
There are many contrast functions, depending on what you are looking for. hopefully the below provides a few examples of what you are looking for:
library(tidyverse)
my_factors <- tibble(
my_factor_chr = sample(c("yes", "no"), 10, replace = T)
) %>%
mutate(
my_factor_fct = as_factor(my_factor_chr),
my_factor_int = as.integer(my_factor_fct)
)
my_factors
#> # A tibble: 10 x 3
#> my_factor_chr my_factor_fct my_factor_int
#> <chr> <fct> <int>
#> 1 yes yes 1
#> 2 yes yes 1
#> 3 no no 2
#> 4 no no 2
#> 5 no no 2
#> 6 yes yes 1
#> 7 no no 2
#> 8 yes yes 1
#> 9 yes yes 1
#> 10 yes yes 1
contrasts(my_factors$my_factor_fct)
#> no
#> yes 0
#> no 1
contr.treatment(my_factors$my_factor_fct)
#> yes no no no yes no yes yes yes
#> yes 0 0 0 0 0 0 0 0 0
#> yes 1 0 0 0 0 0 0 0 0
#> no 0 1 0 0 0 0 0 0 0
#> no 0 0 1 0 0 0 0 0 0
#> no 0 0 0 1 0 0 0 0 0
#> yes 0 0 0 0 1 0 0 0 0
#> no 0 0 0 0 0 1 0 0 0
#> yes 0 0 0 0 0 0 1 0 0
#> yes 0 0 0 0 0 0 0 1 0
#> yes 0 0 0 0 0 0 0 0 1
contr.sum(my_factors$my_factor_fct)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
#> yes 1 0 0 0 0 0 0 0 0
#> yes 0 1 0 0 0 0 0 0 0
#> no 0 0 1 0 0 0 0 0 0
#> no 0 0 0 1 0 0 0 0 0
#> no 0 0 0 0 1 0 0 0 0
#> yes 0 0 0 0 0 1 0 0 0
#> no 0 0 0 0 0 0 1 0 0
#> yes 0 0 0 0 0 0 0 1 0
#> yes 0 0 0 0 0 0 0 0 1
#> yes -1 -1 -1 -1 -1 -1 -1 -1 -1
stat_funs <- lsf.str("package:stats")
stat_funs[str_detect(stat_funs,"contr")]
#> [1] "contr.helmert" "contr.poly" "contr.SAS" "contr.sum"
#> [5] "contr.treatment" "contrasts" "contrasts<-" "glm.control"
#> [9] "loess.control" "nls.control" "se.contrast"
Created on 2020-07-21 by the reprex package (v0.3.0)