Comparing two different response variables in a multivariate model using the hypothesis function

Hi!

I’m having some trouble using the hypothesis function with a multivariate model. In brief, I have recorded activity rates of animals from multiple populations across 2 contexts. A simplified version of my dataset is as follows:

ID     Population      Activity_context1      Activity_context2      Trial
1          A                  25                     32                1
1          A                  16                     22                2
2          B                  11                     07                1
2          B                  27                     23                2
3          C                  41                     29                1
3          C                  17                     45                2

I’m interested in looking at among-individual correlations across the contexts and therefore want to run a multivariate model. A simplified version of my model is as below:

act1<- bf(Activity_context1 ~ Population + Trial + (1|id), family= gaussian)
act2<- bf(Activity_context2 ~ Population + Trial + (1|id), family= gaussian)

act.model<- brm(act1+ act2+ set_rescor(FALSE),
                          data = mydata,
                          cores = 4,
                          chains = 4,
                          warmup = 500,
                          iter = 3000,
                          seed = 12345)

If possible, I would like to use the hypothesis function to look at 1) whether populations differ in their activity in context 1, and 2) whether populations change their behaviour across the contexts. I have seen a similar post on using the hypothesis with multivariate models (Comparing posteriors of predictors in brms using hypothesis - #2 by martinmodrak), however, I still had a few questions.

In regards to questions 1, I have used the following hypotheses:

# Comparing Population A and B
hyp1 = c(hyp1 = "Activity_context1_Intercept + Activity_context1_PopulationB = Activity_context1_Intercept ")
hyp1 <- hypothesis(act.model, hyp1, alpha = 0.05)

This gives me essentially the same output as the summmary() function and I think this seems to be coded correctly.

However, I am having difficulty in answering question 2. I have coded the contrasts across the two response variables within each population as follows:

# Comparing Population A (context 1) and A (context 2)
hyp2 = c(hyp1 = "Activity_context1_Intercept  = Activity_context2_Intercept  ")
hyp2 <- hypothesis(act.model, hyp2, alpha = 0.05)

The output does not seem correct when looking at the figures, so I am wondering if this is the best way to code this contrast?

Alternatively, I could convert my data into long format and run a separate model with context as a predictor, however, I would prefer to do it with my multivariate model if possible.

Any help would be greatly appreciated!

Thanks in advance!

1 Like

Hi, sorry for not getting to you earlier. Did you manage to resolve the issue in the meantime?

For me, the question as written is a bit too vague to answer, especially this:

Why do you think it is not correct? What do the plots look like? Generally, point hypotheses are a weird bunch, see e.g. Hypothesis testing, model selection, model comparison - some thoughts. In the light of the Schad et al. Bayes factor workflow paper I would also not be surprised if the default method for computing BF in brms which AFAIK is Savage-Dickey just failed for this specific hypothesis, as it AFAIK is intended only for hypotheses of the type something = 0.

Best of luck with your model

Hi Martin,

No worries! Thanks for the reply. Yes I did manage to figure it out in the end.

I think the contrasts were coded correctly. However, when trying to answer my second question (i.e. whether populations change their behaviour across the contexts), I somehow did not consider that I had independently transformed and mean-centred (i.e. Mean = 0, SD = 1) each response variable! This appears to be why plots of the raw data showed a substantial difference in activity between the contexts, whereas the contrasts using the
hypothesis() function showed no change. For question 2, I ran a separate model where I converted the data into long format and included context as a fixed-effect. This allowed me to see how behaviour had changed across the two contexts. Thanks again!

1 Like