Simple slope analysis in Bayesian analysis with priors (brms)

Hi,

I would like to know how I can conduct a simple slope analysis in Bayesian analysis with priors.

I managed to do it by shifting data (please see below).

df2$pol.c <- df2$pol - mean(df2$pol)
df2$past.p <- df2$past-1

brm(endorse~pol.c*past.p, data = df2, prior = priors_simple_past_eds1,seed = 2020, iter = 100000) %>% summary()

However, the coefficient I obtained through the above approach was not identical with the coefficient I calculated from the output below (not shifting data).

brm(endorse ~ pol * past, data = df2, prior = priors_full_eds1,save_all_pars = TRUE, seed=2020, iter=100000) 

I need to have information about estimate error and credible intervals.
Could you let me know how I can conduct a simple slope analysis in Bayesian analysis without shifting data?

Is there a function to do it?
or how can I calculate it?

Thank you so much in advance.

Kind regards,
IK Kim

  • Operating System: Window, R
  • brms Version: 2.12

The models are expected to give at least slightly different results as the transformation you’ve made changes the intercept which may then interact with the prior on intercept. To be more specific, we would need to see the priors you use, the actual model outputs and preferably at least part of the contents of df2.

(note that you can use ``` to mark blocks of code/output in the post)

Best of luck with your model!

Thanks martinmodrak for your reply.

the priors, code, and output are as follows

priors_full_eds1 <- c(

  set_prior('normal(1.4234734,0.0717751)', class = 'sigma'),
  
  set_prior('normal(6.1064984,0.2737157)', class = 'Intercept'),
  
  set_prior('normal(-0.2368219,0.0792713)', class = 'b', coef = 'pol'),
  
  set_prior('normal(-2.0189179,0.4051452)', class = 'b', coef = 'past'),
  
  set_prior('normal(0.4216265,0.1149064)', class = 'b', coef = 'pol:past')
)
full_brms_eds2 <- brms::brm(endorse ~ pol * past, data = df2_pw,prior = priors_full_eds1,save_all_pars = TRUE, seed=2020, iter=100000)
print(full_brms_eds2, digit = 7)
 Family: gaussian 
  Links: mu = identity; sigma = identity 
Formula: endorse ~ pol * past 
   Data: df2_pw (Number of observations: 537) 
Samples: 4 chains, each with iter = 1e+05; warmup = 50000; thin = 1;
         total post-warmup samples = 2e+05

Population-Level Effects: 
            Estimate Est.Error   l-95% CI   u-95% CI      Rhat Bulk_ESS Tail_ESS
Intercept  6.1181511 0.1472615  5.8305900  6.4076913 1.0000235   128056   150652
pol       -0.2344092 0.0378333 -0.3086516 -0.1600639 1.0000327   121714   136421
past      -1.7367826 0.1956335 -2.1210513 -1.3526806 1.0000384   103865   130381
pol:past   0.3179853 0.0490764  0.2219760  0.4144450 1.0000131    95541   122881

Family Specific Parameters: 
       Estimate Est.Error  l-95% CI  u-95% CI      Rhat Bulk_ESS Tail_ESS
sigma 1.4371619 0.0374294 1.3656650 1.5120744 0.9999990   184923   144728

Samples were drawn using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).

How can I conduct the simple slope analyses (when past = 0 and past =1).
Past is a categorical variable.
Pol is a continuous variable (1 to 7)

Kind regards,
IK Kim

Hi,
the most straightforward approach would be to use the function called hypothesis.
For example, this code will give you values of simple slopes of pol for past = 0 and past = 1:

hypothesis(full_brms_eds2, c(past0 = "pol = 0",
                             past1 = "pol + pol:past = 0"))

If you would like an easier approach, then brms models work perfectly fine with emmeans. See this tutorial to see how to compute simple slopes with this package.:
https://stats.idre.ucla.edu/r/seminars/interactions-r/

Thanks Wiktor_Soral for your kind help.
I have got the information I needed through your code.

Thanks so much.

Kind regards,
IK Kim