Closed tsostarics closed 3 months ago
This is implemented and accounts for a few more things:
Consider this as setup, where some matrices dont match, some labels dont match, and some variables aren't factors in the data frame
my_data <- mtcars
clist <- list(cyl ~ helmert_code,
carb ~ helmert_code,
gear ~ sum_code,
am ~ treatment_code + 0 | c("diffA"))
my_data$cyl <- factor(my_data$cyl)
my_data$carb <- factor(my_data$carb)
my_data$am <- factor(my_data$am)
contrasts(my_data$carb) <- helmert_code(6)
Output for passing a list of formulas as clist
glimpse_contrasts(my_data, clist)
Warning message:
These vars in `my_data` are not factors:
- gear
Contrasts for factors in `my_data` don't match matrices in formulas:
- cyl
Comparison labels for contrasts in `my_data` don't match:
- carb (expected `<2, <3, <4, <6, <8` but found ``)
- am (expected `diffA` but found `1`)
To fix, be sure to run:
my_data <- set_contrasts(my_data, clist)
Also note the "to fix..." line at the bottom even if all the formulas are typed out manually:
glimpse_contrasts(my_data,
cyl ~ helmert_code,
carb ~ helmert_code,
gear ~ sum_code,
am ~ treatment_code + 0 | c("diffA"))
Warning message:
These vars in `my_data` are not factors:
- gear
Contrasts for factors in `my_data` don't match matrices in formulas:
- cyl
Comparison labels for contrasts in `my_data` don't match:
- carb (expected `<2, <3, <4, <6, <8` but found ``)
- am (expected `diffA` but found `1`)
To fix, be sure to run:
my_data <- set_contrasts(my_data,
cyl ~ helmert_code,
carb ~ helmert_code,
gear ~ sum_code,
am ~ treatment_code + 0 | c("diffA"))
consider the following
(1) will report that the contrasts for
cyl
usescontr.treatment
(default unordered contrasts), as expected (2) will report that the contrasts forcyl
useshelmert_code
, which adheres to the formula passed to...
but does not correspond to the actual contrasts on the dataframe (3) will report that the contrasts forcyl
usescontr.treatment
(expected) but will warn that the contrasts forcarb
are not equal tocontr.treatment
(because it's a helmert_code matrix)The case for (2) should warn that the contrasts in the formula are not equal the contrasts on the dataframe, and that set_contrasts should be used.