Hi there,
I have 3 questions about testing specific contrasts with sum-zero coding style and suppressing the intercept and I appreciate your comments. I am planning to do a pairwise comparison between levels of a factor with 4 levels. Here I load and prepare the data and then set the contrast to sum-zero:
# load libraries
library(brms)
library(tidyverse)
# load data
library(afex)
data(sk2011.1)
data <- sk2011.1 %>%
select(id, instruction, inference, response) %>%
as_tibble()
# set the contrast to sum-zero
options(contrasts = c('contr.sum', 'contr.poly'))
contrasts(data$inference) # 4 levels
contrasts(data$instruction) # 2 levels
- With a regular formula, I am not able to sample from intercept and I cannot use Intercept (which is the grand mean) in the
brms::hypothesis()
to recover the fourth level of my predictor. Thus, I suppress the intercept. Is the intercept still my grand mean considering my deviation coding? For example, is this equation still true?inference4 = inference1 + inference2 + inference3
get_prior(bf(response ~ 1 + inference),
data= data)
# prior class coef group resp dpar nlpar bound source
# (flat) b default
# (flat) b inference1 (vectorized)
# (flat) b inference2 (vectorized)
# (flat) b inference3 (vectorized)
# student_t Intercept default
get_prior(bf(response ~ 0 + Intercept + inference),
data= data)
# prior class coef group resp dpar nlpar bound source
# (flat) b default
# (flat) b inference1 (vectorized)
# (flat) b inference2 (vectorized)
# (flat) b inference3 (vectorized)
# (flat) b Intercept (vectorized)
- Is
0 + Intercept + inference
different from0 + inference
? With the second formula, I have direct estimates for all 4 levels of the predictor.
get_prior(bf(response ~ 0 + inference),
data= data)
# prior class coef group resp dpar nlpar bound source
# (flat) b default
# (flat) b inferenceAC (vectorized)
# (flat) b inferenceDA (vectorized)
# (flat) b inferenceMP (vectorized)
# (flat) b inferenceMT (vectorized)
- Since
0 + inference
is easier to deal with, if I decide to use this formula, what happens when I add another predictor? Here I added a 2-level predictor but I only have the estimate for one of its levels. How can I recover its second level considering that there is no intercept here?
get_prior(bf(response ~ 0 + inference + instruction),
data= data)
# prior class coef group resp dpar nlpar bound source
# (flat) b default
# (flat) b inferenceAC (vectorized)
# (flat) b inferenceDA (vectorized)
# (flat) b inferenceMP (vectorized)
# (flat) b inferenceMT (vectorized)
# (flat) b instruction1 (vectorized)
I am aware that it is easy to recover the draws for all levels using tidybayes, emmeans, and other tools. I am interested to calculate BF for different contrasts using the hypothesis()
function.
Thank you.